aggiunta gestione compagnie
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -22,6 +23,8 @@ namespace WebDoorCreator.Data.Controllers
|
||||
// Clear database context
|
||||
//Log.Info("Dispose di GWMSController");
|
||||
}
|
||||
|
||||
#region Company methods
|
||||
/// <summary>
|
||||
/// Recupera l'elenco Company (ALL)
|
||||
/// </summary>
|
||||
@@ -50,5 +53,53 @@ namespace WebDoorCreator.Data.Controllers
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adding a new company
|
||||
/// </summary>
|
||||
/// <param name="addEditRec">Record to edit or add</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> CompanyAddMod(CompanyModel addEditRec)
|
||||
{
|
||||
bool fatto = false;
|
||||
//List<ItemModel> dbResult = new List<ItemModel>();
|
||||
using (WDCDataContext localDbCtx = new WDCDataContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
var currRec = localDbCtx
|
||||
.DbSetCompany
|
||||
.Where(x => x.CompanyId == addEditRec.CompanyId)
|
||||
.FirstOrDefault();
|
||||
if (currRec != null) //if is not null edit the record found
|
||||
{
|
||||
currRec.CompanyName = addEditRec.CompanyName;
|
||||
currRec.CompanyExtCode = addEditRec.CompanyExtCode;
|
||||
currRec.Address = addEditRec.Address;
|
||||
currRec.City = addEditRec.City;
|
||||
currRec.State = addEditRec.State;
|
||||
currRec.ZipCode = addEditRec.ZipCode;
|
||||
currRec.VAT = addEditRec.VAT;
|
||||
currRec.PrivateNote = addEditRec.PrivateNote;
|
||||
currRec.CompanyToken = addEditRec.CompanyToken;
|
||||
localDbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
}
|
||||
else //if is null add the record as new in the table
|
||||
{
|
||||
localDbCtx
|
||||
.DbSetCompany
|
||||
.Add(addEditRec);
|
||||
}
|
||||
await localDbCtx.SaveChangesAsync();
|
||||
fatto = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante CompanyAddMod;{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
#endregion company methods
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user