Aggiunto controller x Alias
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
using EgtBEAMWALL.DataLayer.DatabaseModels;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Gestione Alias su DB (es: materiali da BTL e su DB)
|
||||
/// </summary>
|
||||
public class AliasController : IDisposable
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public AliasController()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Delete by key
|
||||
/// </summary>
|
||||
/// <param name="Family"></param>
|
||||
/// <param name="ValueOriginal"></param>
|
||||
/// <returns></returns>
|
||||
public bool DeleteByKey(string Family, string ValueOriginal)
|
||||
{
|
||||
bool done = false;
|
||||
using (DatabaseContext localDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
var items2del = localDbCtx
|
||||
.AliasList
|
||||
.Where(x => x.Family == Family && x.ValueOriginal == ValueOriginal);
|
||||
try
|
||||
{
|
||||
// Add to database
|
||||
localDbCtx.AliasList.RemoveRange(items2del);
|
||||
// Commit changes
|
||||
localDbCtx.SaveChanges();
|
||||
done = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"EXCEPTION on Alias.DeleteByKey: {Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get record by Key
|
||||
/// </summary>
|
||||
/// <param name="MatId"></param>
|
||||
/// <returns></returns>
|
||||
public AliasModel FindByDbId(string Family, string ValueOriginal)
|
||||
{
|
||||
using (DatabaseContext localDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
return localDbCtx
|
||||
.AliasList
|
||||
.Where(x => x.Family == Family && x.ValueOriginal == ValueOriginal)
|
||||
.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Alias x famiglia
|
||||
/// </summary>
|
||||
/// <param name="Family">se "" restituisce tutti</param>
|
||||
/// <returns></returns>
|
||||
public List<AliasModel> GetFilt(string Family)
|
||||
{
|
||||
// retrieve
|
||||
using (DatabaseContext localDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
return localDbCtx
|
||||
.AliasList
|
||||
.Where(x => x.Family == Family)
|
||||
.OrderBy(x => x.ValueOriginal)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update or insert Alias record
|
||||
/// </summary>
|
||||
/// <param name="updItem"></param>
|
||||
/// <returns></returns>
|
||||
public bool Upsert(AliasModel updItem)
|
||||
{
|
||||
bool fatto = false;
|
||||
using (DatabaseContext localDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
try
|
||||
{
|
||||
var item2update = localDbCtx
|
||||
.AliasList
|
||||
.Where(x => x.Family == updItem.Family && x.ValueOriginal == updItem.ValueOriginal)
|
||||
.SingleOrDefault();
|
||||
|
||||
if (item2update != null)
|
||||
{
|
||||
// update, vers 1...
|
||||
localDbCtx.Entry(item2update).CurrentValues.SetValues(updItem);
|
||||
// Commit changes
|
||||
localDbCtx.SaveChanges();
|
||||
fatto = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
localDbCtx.AliasList.Add(updItem);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"EXCEPTION on Alias.Upsert: {Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
/// <summary>
|
||||
/// Istanza logger
|
||||
/// </summary>
|
||||
private NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using EgtBEAMWALL.DataLayer.DatabaseModels;
|
||||
using EgwProxy.MagMan;
|
||||
using EgwProxy.MagMan.DTO;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Gestione Sync MagMan (DB locale/online)
|
||||
/// </summary>
|
||||
public class MagmanController : IDisposable
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
private DataSyncro commLib = null;
|
||||
|
||||
/// <summary>
|
||||
/// Init controller gestione MagmanSync
|
||||
/// </summary>
|
||||
/// <param name="ServerAddress"></param>
|
||||
/// <param name="AuthToken"></param>
|
||||
public MagmanController(string ServerAddress, string AuthToken)
|
||||
{
|
||||
commLib = new DataSyncro(ServerAddress, AuthToken);
|
||||
bool servOk = commLib.CheckRemote();
|
||||
Log.Info($"Avviato MagmanController | server: {ServerAddress} | CheckRemote OK: {servOk}");
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Esegue sync materiali:
|
||||
/// - upload + sync (cloud)
|
||||
/// - download + sync (locale)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool SyncMaterials()
|
||||
{
|
||||
bool answ = false;
|
||||
// to be done
|
||||
return answ;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
commLib = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue sync delle giacenze RawItems:
|
||||
/// </summary>
|
||||
/// <param name="MatCode">Se "" --> tutti, altrimenti limitatamente al MatCode cercato</param>
|
||||
/// <returns></returns>
|
||||
public bool SyncRawItems(string MatCode)
|
||||
{
|
||||
bool answ = false;
|
||||
// to be done
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Invia un set di consumi (stimati) per gli Item gestiti
|
||||
/// </summary>
|
||||
/// <param name="idxProjDbId">DbId del progetto da inviare</param>
|
||||
/// <param name="recType">tipo di registrazione da inviare (stima, consumo, ...)</param>
|
||||
/// <param name="rec2send">record da inviare, se consumo Qty deve essere negativa</param>
|
||||
/// <returns></returns>
|
||||
public bool SendResource(int idxProjDbId, ProjResState recType, List<ResourceDTO> rec2send)
|
||||
{
|
||||
bool answ = false;
|
||||
// to be done
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
/// <summary>
|
||||
/// Istanza logger
|
||||
/// </summary>
|
||||
private NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@
|
||||
<HintPath>..\ExtLibs\EgtWPFLib5.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EgwProxy.MagMan, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EgwProxy.MagMan.0.9.2401.2909\lib\EgwProxy.MagMan.dll</HintPath>
|
||||
<HintPath>..\packages\EgwProxy.MagMan.1.0.2401.2912\lib\EgwProxy.MagMan.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
|
||||
@@ -146,6 +146,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminContext.cs" />
|
||||
<Compile Include="Controllers\MagmanController.cs" />
|
||||
<Compile Include="Controllers\AliasController.cs" />
|
||||
<Compile Include="Controllers\RawItemsController.cs" />
|
||||
<Compile Include="Controllers\MaterialsController.cs" />
|
||||
<Compile Include="DatabaseModels\AliasModel.cs" />
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<packages>
|
||||
<package id="BouncyCastle" version="1.8.5" targetFramework="net472" />
|
||||
<package id="DotNetZip" version="1.16.0" targetFramework="net472" />
|
||||
<package id="EgwProxy.MagMan" version="0.9.2401.2909" targetFramework="net472" />
|
||||
<package id="EgwProxy.MagMan" version="1.0.2401.2912" targetFramework="net472" />
|
||||
<package id="EntityFramework" version="6.4.4" targetFramework="net452" />
|
||||
<package id="Google.Protobuf" version="3.21.9" targetFramework="net472" />
|
||||
<package id="K4os.Compression.LZ4" version="1.3.5" targetFramework="net472" />
|
||||
|
||||
Reference in New Issue
Block a user