diff --git a/EgtBEAMWALL.DataLayer/Controllers/ProjController.cs b/EgtBEAMWALL.DataLayer/Controllers/ProjController.cs
index 2b4a7fa2..ad5ef5b8 100644
--- a/EgtBEAMWALL.DataLayer/Controllers/ProjController.cs
+++ b/EgtBEAMWALL.DataLayer/Controllers/ProjController.cs
@@ -26,6 +26,17 @@ namespace EgtBEAMWALL.DataLayer.Controllers
#region Protected Methods
+ ///
+ /// Helper conversione modelli
+ ///
+ ///
+ ///
+ protected Core.ProjFileM coreConv(ProjModel currProj)
+ {
+ Core.ProjFileM answ = Core.ProjFileM.CreateProjFileM(currProj.ProjId, ProdIdByProdDbId(currProj.ProdDbId), currProj.DtCreated, currProj.DtExported, currProj.ListName, currProj.BTLFileName);
+ return answ;
+ }
+
///
/// Get LAST paginated data from DB (DESC ordered)
///
@@ -112,12 +123,13 @@ namespace EgtBEAMWALL.DataLayer.Controllers
///
///
///
- public ProjModel FindByProjDbId(int ProjDbId)
+ public Core.ProjFileM FindByProjDbId(int ProjDbId)
{
- return dbCtx
+ Core.ProjFileM answ = coreConv(dbCtx
.ProjList
.Where(x => x.ProjDbId == ProjDbId)
- .SingleOrDefault();
+ .SingleOrDefault());
+ return answ;
}
///
@@ -127,57 +139,13 @@ namespace EgtBEAMWALL.DataLayer.Controllers
///
public ProjModel FindByProjId(int ProjId)
{
- return dbCtx
- .ProjList
+ var answ = dbCtx
+ .ProjList
.Where(x => x.ProjId == ProjId)
.SingleOrDefault();
+ return answ;
}
-#if false
- ///
- /// 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();
- }
-
-#endif
-
///
/// Get filtered data by ProdId (ASC ordered)
///
@@ -185,6 +153,7 @@ namespace EgtBEAMWALL.DataLayer.Controllers
///
public List GetByProdAsc(int ProdId)
{
+ List answ = new List();
int ProdDbId = 0;
try
{
@@ -202,11 +171,12 @@ namespace EgtBEAMWALL.DataLayer.Controllers
Console.WriteLine($"EXCEPTION on GetByProdAsc: {exc}");
}
// retrieve
- return dbCtx
+ answ = dbCtx
.ProjList
.Where(x => x.ProdDbId == ProdDbId)
.OrderBy(x => x.ProdDbId)
.ToList();
+ return answ;
}
///
@@ -214,8 +184,9 @@ namespace EgtBEAMWALL.DataLayer.Controllers
///
///
///
- public List GetByProdDesc(int ProdId)
+ public List GetByProdDesc(int ProdId)
{
+ List answ = new List();
int ProdDbId = 0;
try
{
@@ -233,11 +204,14 @@ namespace EgtBEAMWALL.DataLayer.Controllers
Console.WriteLine($"EXCEPTION on GetByProdAsc: {exc}");
}
// retrieve
- return dbCtx
+ var dbRes = dbCtx
.ProjList
.Where(x => x.ProdDbId == ProdDbId)
.OrderByDescending(x => x.ProdDbId)
.ToList();
+ // conversione
+ answ = dbRes.Select(x => coreConv(x)).ToList();
+ return answ;
}
///
@@ -247,14 +221,22 @@ namespace EgtBEAMWALL.DataLayer.Controllers
///
public List GetLastDesc(int numRecord)
{
- List result = new List();
-
- var dbResult = GetLastDbModelDesc(numRecord);
+ List answ = new List();
+ // se numRecord = 0 --> passo tutti
+ if (numRecord == 0)
+ {
+ numRecord = dbCtx.ProjList.Count();
+ }
+ // retrieve
+ var dbRes = dbCtx
+ .ProjList
+ .OrderByDescending(x => x.ProjId)
+ .Take(numRecord)
+ .ToList();
// conversione
- result = dbResult.Select(x => Core.ProjFileM.CreateProjFileM(x.ProjId, ProdIdByProdDbId(x.ProdDbId), x.DtCreated, x.DtExported, x.ListName, x.BTLFileName)).ToList();
-
- return result;
+ answ = dbRes.Select(x => coreConv(x)).ToList();
+ return answ;
}
///
@@ -286,7 +268,7 @@ namespace EgtBEAMWALL.DataLayer.Controllers
// creo nuovo...
var newRec = dbCtx
.ProjList
- .Add(new ProjModel() { ProjId = nextId, BTLFileName = "", Locked = true, DtCreated = DateTime.Now });
+ .Add(new ProjModel() { ProjId = nextId, BTLFileName = "", IsNew = true, Locked = true, DtCreated = DateTime.Now });
// Commit changes
dbCtx.SaveChanges();
@@ -300,7 +282,7 @@ namespace EgtBEAMWALL.DataLayer.Controllers
/// ProjID
/// Stato Lock da impostare
///
- public ProjModel LockByProjId(int ProjId, bool Locked)
+ public Core.ProjFileM LockByProjId(int ProjId, bool Locked)
{
var currProj = dbCtx
.ProjList
@@ -319,7 +301,27 @@ namespace EgtBEAMWALL.DataLayer.Controllers
dbCtx.SaveChanges();
- return currProj;
+ return coreConv(currProj);
+ }
+
+ ///
+ /// Reimposta come NEW
+ ///
+ /// ProjID
+ /// Stato Lock da impostare
+ ///
+ public Core.ProjFileM ResetNew(int ProjId)
+ {
+ var currProj = dbCtx
+ .ProjList
+ .Where(x => x.ProjId == ProjId)
+ .SingleOrDefault();
+
+ // aggiorno stato
+ currProj.IsNew = true;
+ dbCtx.SaveChanges();
+
+ return coreConv(currProj);
}
///
@@ -397,7 +399,7 @@ namespace EgtBEAMWALL.DataLayer.Controllers
///
///
///
- public ProjModel UpdateInfo(int ProjId, string BTLFileName, string ListName, DateTime DtExported)
+ public Core.ProjFileM UpdateInfo(int ProjId, string BTLFileName, string ListName, DateTime DtExported)
{
var currData = FindByProjId(ProjId);
// aggiorno valore BTL
@@ -408,7 +410,7 @@ namespace EgtBEAMWALL.DataLayer.Controllers
// Commit changes
dbCtx.SaveChanges();
- return currData;
+ return coreConv(currData);
}
#endregion Public Methods