Merge remote-tracking branch 'gitlab.seriate/DataLayer' into feature/NewWarehouse

This commit is contained in:
Emmanuele Sassi
2024-01-31 19:01:06 +01:00
2 changed files with 23 additions and 23 deletions
@@ -204,13 +204,13 @@ namespace EgtBEAMWALL.DataLayer.Controllers
/// </summary>
/// <param name="updItem"></param>
/// <returns></returns>
public bool Upsert(Core.MaterialM coreItem)
public int Upsert(Core.MaterialM coreItem)
{
bool fatto = false;
int newIdx = 0;
// converto
MaterialModel updItem = ConvToModel(coreItem);
fatto = Upsert(updItem);
return fatto;
newIdx = Upsert(updItem);
return newIdx;
}
/// <summary>
@@ -218,17 +218,17 @@ namespace EgtBEAMWALL.DataLayer.Controllers
/// </summary>
/// <param name="updItem"></param>
/// <returns></returns>
public bool Upsert(MaterialModel updItem)
public int Upsert(MaterialModel updItem)
{
bool fatto = false;
int newIdx = 0;
using (DatabaseContext localDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
{
try
{
var item2update = localDbCtx
.MaterialsList
.Where(x => x.MatId == updItem.MatId
|| x.MatCloudId == updItem.MatCloudId
.Where(x => (updItem.MatId > 0 && x.MatId == updItem.MatId)
|| (updItem.MatCloudId > 0 && x.MatCloudId == updItem.MatCloudId)
|| (x.MatCode == updItem.MatCode && x.WMm == updItem.WMm && x.HMm == updItem.HMm && x.LMm == updItem.LMm))
.SingleOrDefault();
@@ -236,21 +236,21 @@ namespace EgtBEAMWALL.DataLayer.Controllers
{
// update, vers 1...
localDbCtx.Entry(item2update).CurrentValues.SetValues(updItem);
// Commit changes
localDbCtx.SaveChanges();
fatto = true;
}
else
{
localDbCtx.MaterialsList.Add(updItem);
}
// Commit changes
localDbCtx.SaveChanges();
newIdx = item2update.MatId;
}
catch (Exception exc)
{
Log.Error($"EXCEPTION on Materials.Upsert: {Environment.NewLine}{exc}");
}
}
return fatto;
return newIdx;
}
#endregion Public Methods
@@ -258,16 +258,16 @@ namespace EgtBEAMWALL.DataLayer.Controllers
/// </summary>
/// <param name="updItem"></param>
/// <returns></returns>
public bool Upsert(RawItemModel updItem)
public int Upsert(RawItemModel updItem)
{
bool fatto = false;
int newIdx = 0;
using (DatabaseContext localDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
{
try
{
var item2update = localDbCtx
.RawItemList
.Where(x => x.RawItemId == updItem.RawItemId
.Where(x => (updItem.RawItemId>0 && x.RawItemId == updItem.RawItemId)
|| (x.MatId == updItem.MatId && x.WMm == updItem.WMm && x.HMm == updItem.HMm && x.LMm == updItem.LMm))
.SingleOrDefault();
@@ -275,21 +275,21 @@ namespace EgtBEAMWALL.DataLayer.Controllers
{
// update, vers 1...
localDbCtx.Entry(item2update).CurrentValues.SetValues(updItem);
// Commit changes
localDbCtx.SaveChanges();
fatto = true;
}
else
{
localDbCtx.RawItemList.Add(updItem);
}
// Commit changes
localDbCtx.SaveChanges();
newIdx = item2update.RawItemId;
}
catch (Exception exc)
{
Log.Error($"EXCEPTION on RawItems.Upsert: {Environment.NewLine}{exc}");
}
}
return fatto;
return newIdx;
}
/// <summary>
@@ -297,13 +297,13 @@ namespace EgtBEAMWALL.DataLayer.Controllers
/// </summary>
/// <param name="coreItem"></param>
/// <returns></returns>
public bool Upsert(Core.RawPartM coreItem)
public int Upsert(Core.RawPartM coreItem)
{
bool fatto = false;
int newIdx = 0;
// converto
RawItemModel updItem = ConvToModel(coreItem);
fatto = Upsert(updItem);
return fatto;
newIdx = Upsert(updItem);
return newIdx;
}
#endregion Public Methods