diff --git a/EgtBEAMWALL.DataLayer/Controllers/BTLPartController.cs b/EgtBEAMWALL.DataLayer/Controllers/BTLPartController.cs
index 1be44c10..fb216211 100644
--- a/EgtBEAMWALL.DataLayer/Controllers/BTLPartController.cs
+++ b/EgtBEAMWALL.DataLayer/Controllers/BTLPartController.cs
@@ -6,255 +6,255 @@ using EgtBEAMWALL.DataLayer.DatabaseModels;
namespace EgtBEAMWALL.DataLayer.Controllers
{
- public class BTLPartController : IDisposable
- {
- private DatabaseContext dbCtx;
+ public class BTLPartController : IDisposable
+ {
+ private DatabaseContext dbCtx;
- public BTLPartController()
- {
- // Initialize database context
- dbCtx = new DatabaseContext();
- }
+ public BTLPartController()
+ {
+ // Initialize database context
+ dbCtx = new DatabaseContext();
+ }
- public void Dispose()
- {
- // Clear database context
- dbCtx.Dispose();
- }
- ///
- /// Get record by DBId
- ///
- ///
- ///
- public BTLPartModel FindByDbId(int PartDbId)
- {
- return dbCtx
- .BTLPartList
- .Where(x => x.PartDbId == PartDbId)
- .SingleOrDefault();
- }
- ///
- /// Get record by ExtId
- ///
- ///
- ///
- public BTLPartModel FindByPartId(int PartId)
- {
- return dbCtx
- .BTLPartList
- .Where(x => x.PartId == PartId)
- .SingleOrDefault();
- }
- ///
- /// Get paginated data from DB (ASC ordered)
- ///
- ///
- ///
- ///
- public List GetPaginatedAsc(int PartDbIdStart, int numRecord)
- {
- int numEnd = PartDbIdStart - numRecord;
- // check numEnd
- if (numEnd < 0)
- numEnd = 0;
- // retrieve
- return dbCtx
- .BTLPartList
- .Where(x => x.PartDbId <= PartDbIdStart)
- .OrderBy(x => x.PartDbId)
- .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
- .BTLPartList
- .Where(x => x.PartDbId <= PartDbIdStart)
- .OrderByDescending(x => x.PartDbId)
- .Take(numRecord)
- .ToList();
- }
- ///
- /// Get filtered data by ProjectId (ASC ordered)
- ///
- ///
- ///
- public List GetByProjectAsc(int ProjDbId)
- {
- // retrieve
- return dbCtx
- .BTLPartList
- .Where(x => x.ProjDbId == ProjDbId)
- .OrderBy(x => x.PartDbId)
- .ToList();
- }
- ///
- /// Get filtered data by ProjectId (DESC ordered)
- ///
- ///
- ///
- public List GetByProjectDesc(int ProjDbId)
- {
- // retrieve
- return dbCtx
- .BTLPartList
- .Where(x => x.ProjDbId == ProjDbId)
- .OrderByDescending(x => x.PartDbId)
- .ToList();
- }
+ public void Dispose()
+ {
+ // Clear database context
+ dbCtx.Dispose();
+ }
+ ///
+ /// Get record by DBId
+ ///
+ ///
+ ///
+ public BTLPartModel FindByDbId(int PartDbId)
+ {
+ return dbCtx
+ .BTLPartList
+ .Where(x => x.PartDbId == PartDbId)
+ .SingleOrDefault();
+ }
+ ///
+ /// Get record by ExtId
+ ///
+ ///
+ ///
+ public BTLPartModel FindByPartId(int PartId)
+ {
+ return dbCtx
+ .BTLPartList
+ .Where(x => x.PartId == PartId)
+ .SingleOrDefault();
+ }
+ ///
+ /// Get paginated data from DB (ASC ordered)
+ ///
+ ///
+ ///
+ ///
+ public List GetPaginatedAsc(int PartDbIdStart, int numRecord)
+ {
+ int numEnd = PartDbIdStart - numRecord;
+ // check numEnd
+ if (numEnd < 0)
+ numEnd = 0;
+ // retrieve
+ return dbCtx
+ .BTLPartList
+ .Where(x => x.PartDbId <= PartDbIdStart)
+ .OrderBy(x => x.PartDbId)
+ .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
+ .BTLPartList
+ .Where(x => x.PartDbId <= PartDbIdStart)
+ .OrderByDescending(x => x.PartDbId)
+ .Take(numRecord)
+ .ToList();
+ }
+ ///
+ /// Get filtered data by ProjectId (ASC ordered)
+ ///
+ ///
+ ///
+ public List GetByProjectAsc(int ProjDbId)
+ {
+ // retrieve
+ return dbCtx
+ .BTLPartList
+ .Where(x => x.ProjDbId == ProjDbId)
+ .OrderBy(x => x.PartDbId)
+ .ToList();
+ }
+ ///
+ /// Get filtered data by ProjectId (DESC ordered)
+ ///
+ ///
+ ///
+ public List GetByProjectDesc(int ProjDbId)
+ {
+ // retrieve
+ return dbCtx
+ .BTLPartList
+ .Where(x => x.ProjDbId == ProjDbId)
+ .OrderByDescending(x => x.PartDbId)
+ .ToList();
+ }
- ///
- /// Create multiple (empty) BTLPart record associated to Project
- ///
- ///
- ///
- ///
- public List CreateBaseObj(int ProjDbId, List rawListData)
- {
- List partData = new List();
+ ///
+ /// Create multiple (empty) BTLPart record associated to Project
+ ///
+ ///
+ ///
+ ///
+ public List CreateBaseObj(int ProjDbId, List rawListData)
+ {
+ List partData = new List();
- foreach (var item in rawListData)
- {
- BTLPartModel newItem = new BTLPartModel() { ProjDbId = ProjDbId, PartId = item };
- partData.Add(newItem);
- }
+ foreach (var item in rawListData)
+ {
+ BTLPartModel newItem = new BTLPartModel() { ProjDbId = ProjDbId, PartId = item };
+ partData.Add(newItem);
+ }
- try
- {
- // Add to database
- dbCtx.BTLPartList.AddRange(partData);
- // Commit changes
- dbCtx.SaveChanges();
- }
- catch
- { }
-
- return partData;
- }
-
-
- ///
- /// Create multiple BTLPart record associated to Project
- ///
- ///
- ///
- ///
- public List Create(int ProjID, List partData)
- {
- // se è adv mode --> uso TUTTI i dati
- if (DbManager.AdvDataModel)
- {
try
{
- // Add to database
- dbCtx.BTLPartList.AddRange(partData);
- // Commit changes
- dbCtx.SaveChanges();
+ // Add to database
+ dbCtx.BTLPartList.AddRange(partData);
+ // Commit changes
+ dbCtx.SaveChanges();
}
catch
{ }
+
return partData;
- }
- // se non adv --> faccio solo copia degli id...
- else
- {
- List partIdList = new List();
- foreach (var item in partData)
+ }
+
+
+ ///
+ /// Create multiple BTLPart record associated to Project
+ ///
+ ///
+ ///
+ ///
+ public List Create(int ProjID, List partData)
+ {
+ // se è adv mode --> uso TUTTI i dati
+ if (DbManager.AdvDataModel)
{
- partIdList.Add(item.PartId);
+ try
+ {
+ // Add to database
+ dbCtx.BTLPartList.AddRange(partData);
+ // Commit changes
+ dbCtx.SaveChanges();
+ }
+ catch
+ { }
+ return partData;
}
- return CreateBaseObj(ProjID, partIdList);
- }
- }
+ // se non adv --> faccio solo copia degli id...
+ else
+ {
+ List partIdList = new List();
+ foreach (var item in partData)
+ {
+ partIdList.Add(item.PartId);
+ }
+ return CreateBaseObj(ProjID, partIdList);
+ }
+ }
- ///
- /// Update single BTLPart
- ///
- ///
- ///
- public bool Update(BTLPartModel updItem)
- {
- bool done = false;
- var item2update = dbCtx
- .BTLPartList
- .Where(x => x.PartDbId == updItem.PartDbId)
- .SingleOrDefault();
- try
- {
- // update, vers 1...
- dbCtx.Entry(item2update).CurrentValues.SetValues(updItem);
+ ///
+ /// Update single BTLPart
+ ///
+ ///
+ ///
+ public bool Update(BTLPartModel updItem)
+ {
+ bool done = false;
+ var item2update = dbCtx
+ .BTLPartList
+ .Where(x => x.PartDbId == updItem.PartDbId)
+ .SingleOrDefault();
+ try
+ {
+ // update, vers 1...
+ dbCtx.Entry(item2update).CurrentValues.SetValues(updItem);
- //// update, vers 2
- //dbCtx.BTLPartList.Remove(item2del);
- //dbCtx.BTLPartList.Add(updItem);
+ //// update, vers 2
+ //dbCtx.BTLPartList.Remove(item2del);
+ //dbCtx.BTLPartList.Add(updItem);
- // Commit changes
- dbCtx.SaveChanges();
- done = true;
- }
- catch
- { }
- return done;
- }
+ // Commit changes
+ dbCtx.SaveChanges();
+ done = true;
+ }
+ catch
+ { }
+ return done;
+ }
- ///
- /// Delete single BTLPart
- ///
- ///
- ///
- public bool Delete(int PartDbId)
- {
- bool done = false;
- var item2del = dbCtx
- .BTLPartList
- .Where(x => x.PartDbId == PartDbId)
- .SingleOrDefault();
- try
- {
- // Add to database
- dbCtx.BTLPartList.Remove(item2del);
- // Commit changes
- dbCtx.SaveChanges();
- done = true;
- }
- catch
- { }
- return done;
- }
- ///
- /// Delete BTLPart by project
- ///
- ///
- ///
- public bool DeleteByProject(int ProjDbId)
- {
- bool done = false;
- var items2del = dbCtx
- .BTLPartList
- .Where(x => x.ProjDbId == ProjDbId);
- try
- {
- // Add to database
- dbCtx.BTLPartList.RemoveRange(items2del);
- // Commit changes
- dbCtx.SaveChanges();
- done = true;
- }
- catch
- { }
- return done;
- }
+ ///
+ /// Delete single BTLPart
+ ///
+ ///
+ ///
+ public bool Delete(int PartDbId)
+ {
+ bool done = false;
+ var item2del = dbCtx
+ .BTLPartList
+ .Where(x => x.PartDbId == PartDbId)
+ .SingleOrDefault();
+ try
+ {
+ // Add to database
+ dbCtx.BTLPartList.Remove(item2del);
+ // Commit changes
+ dbCtx.SaveChanges();
+ done = true;
+ }
+ catch
+ { }
+ return done;
+ }
+ ///
+ /// Delete BTLPart by project
+ ///
+ ///
+ ///
+ public bool DeleteByProject(int ProjDbId)
+ {
+ bool done = false;
+ var items2del = dbCtx
+ .BTLPartList
+ .Where(x => x.ProjDbId == ProjDbId);
+ try
+ {
+ // Add to database
+ dbCtx.BTLPartList.RemoveRange(items2del);
+ // Commit changes
+ dbCtx.SaveChanges();
+ done = true;
+ }
+ catch
+ { }
+ return done;
+ }
///
/// Conversion of base class to DB model class
///
@@ -291,32 +291,33 @@ namespace EgtBEAMWALL.DataLayer.Controllers
///
///
///
- public static BTLPartModel ConvertFromCore(Core.BTLPart corePart)
- {
- BTLPartModel answ = new BTLPartModel();
- if (corePart != null)
- {
- answ = new BTLPartModel()
+ public static BTLPartModel ConvertFromCore(Core.BTLPart corePart, int currProjDbId)
+ {
+ BTLPartModel answ = new BTLPartModel();
+ if (corePart != null)
{
- PartId = corePart.nPartId,
- PDN = corePart.nPDN,
- DO = corePart.bDO,
- NAM = corePart.sNAM,
- W = corePart.dW,
- L = corePart.dL,
- H = corePart.dH,
- MAT = corePart.sMATERIAL,
- CNT = corePart.nCNT,
- TBP = corePart.nTBP,
- DON = corePart.nDON,
- ROT = corePart.nROT,
- GRP = corePart.sGRP,
- UNT = corePart.nUNT,
- CALC_State = (int)corePart.nState
- };
- }
- return answ;
- }
+ answ = new BTLPartModel()
+ {
+ PartId = corePart.nPartId,
+ PDN = corePart.nPDN,
+ DO = corePart.bDO,
+ NAM = corePart.sNAM,
+ W = corePart.dW,
+ L = corePart.dL,
+ H = corePart.dH,
+ MAT = corePart.sMATERIAL,
+ CNT = corePart.nCNT,
+ TBP = corePart.nTBP,
+ DON = corePart.nDON,
+ ROT = corePart.nROT,
+ GRP = corePart.sGRP,
+ UNT = corePart.nUNT,
+ CALC_State = (int)corePart.nState,
+ ProjDbId = currProjDbId
+ };
+ }
+ return answ;
+ }
- }
+ }
}