using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EgtBEAMWALL.DbDataLayer.DatabaseModels;
namespace EgtBEAMWALL.DbDataLayer.Controllers
{
public class ProjController : IDisposable
{
private DatabaseContext dbCtx;
public ProjController()
{
// Initialize database context
dbCtx = new DatabaseContext();
}
public void Dispose()
{
// Clear database context
dbCtx.Dispose();
}
///
/// Get record by ProjDbId
///
///
///
public ProjModel FindByProjDbId(int ProjDbId)
{
return dbCtx
.ProjList
.Where(x => x.ProjDbId == ProjDbId)
.SingleOrDefault();
}
///
/// Get record by ProjId
///
///
///
public ProjModel FindByProjId(int ProjId)
{
return dbCtx
.ProjList
.Where(x => x.ProjId == ProjId)
.SingleOrDefault();
}
///
/// Get paginated data from DB (ASC ordered)
///
///
///
///
public List GetPaginatedAsc(int ProjDbIdStart, int numRecord)
{
int numEnd = ProjDbIdStart - numRecord;
// check numEnd
if (numEnd < 0)
numEnd = 0;
// retrieve
return dbCtx
.ProjList
.Where(x => x.ProjDbId <= ProjDbIdStart)
.OrderBy(x => x.ProjDbId)
.Take(numRecord)
.ToList();
}
///
/// Get paginated data from DB (DESC ordered)
///
///
///
///
public List GetPaginatedDesc(int PartDbIdStart, int numRecord)
{
int numEnd = PartDbIdStart - numRecord;
// check numEnd
if (numEnd < 0)
numEnd = 0;
// retrieve
return dbCtx
.ProjList
.Where(x => x.ProjDbId <= PartDbIdStart)
.OrderByDescending(x => x.ProjDbId)
.Take(numRecord)
.ToList();
}
///
/// Get filtered data by ProjectId (ASC ordered)
///
///
///
public List GetByProdAsc(int ProdDbId)
{
// retrieve
return dbCtx
.ProjList
.Where(x => x.ProdDbId == ProdDbId)
.OrderBy(x => x.ProdDbId)
.ToList();
}
///
/// Get filtered data by ProjectId (DESC ordered)
///
///
///
public List GetByProdDesc(int ProdDbId)
{
// retrieve
return dbCtx
.ProjList
.Where(x => x.ProdDbId == ProdDbId)
.OrderByDescending(x => x.ProdDbId)
.ToList();
}
///
/// Create record on DB
///
///
///
///
public ProjModel Create(int newProjId, string newBTLFileName)
{
ProjModel newProj = new ProjModel() { ProjId=newProjId, BTLFileName=newBTLFileName };
try
{
// Add to database
dbCtx.ProjList.Add(newProj);
// Commit changes
dbCtx.SaveChanges();
}
catch
{ }
return newProj;
}
}
}