diff --git a/StockMan.CORE/Components/NewNavMenu.razor.cs b/StockMan.CORE/Components/NewNavMenu.razor.cs index 47d3f6f..be87c69 100644 --- a/StockMan.CORE/Components/NewNavMenu.razor.cs +++ b/StockMan.CORE/Components/NewNavMenu.razor.cs @@ -1,5 +1,4 @@ using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Authorization; using Microsoft.JSInterop; using StockMan.Data.DbModels; @@ -34,7 +33,6 @@ namespace StockMan.CORE.Components #region Protected Properties - protected int currChildOpen { get; set; } = 0; [Inject] @@ -119,7 +117,6 @@ namespace StockMan.CORE.Components return answ; } - #endregion Protected Methods } } \ No newline at end of file diff --git a/StockMan.CORE/Data/LinkMan.cs b/StockMan.CORE/Data/LinkMan.cs index 91552c8..4702610 100644 --- a/StockMan.CORE/Data/LinkMan.cs +++ b/StockMan.CORE/Data/LinkMan.cs @@ -2,10 +2,14 @@ { public class LinkMan { - public string Title { get; set; } = "Link"; + #region Public Properties + public string Css { get; set; } = ""; - public string Icon { get; set; } = ""; public bool hasChildren { get; set; } = false; + public string Icon { get; set; } = ""; public List linkChildren { get; set; } = new List(); + public string Title { get; set; } = "Link"; + + #endregion Public Properties } -} +} \ No newline at end of file diff --git a/StockMan.CORE/Data/StockDataService.cs b/StockMan.CORE/Data/StockDataService.cs index 49c507f..8c98842 100644 --- a/StockMan.CORE/Data/StockDataService.cs +++ b/StockMan.CORE/Data/StockDataService.cs @@ -2,7 +2,6 @@ using Newtonsoft.Json; using NLog; using StackExchange.Redis; -using StockMan.CORE.Pages; using StockMan.Data.Controllers; using StockMan.Data.DbModels; using System.Diagnostics; @@ -48,6 +47,34 @@ namespace StockMan.CORE.Data #region Public Methods + public async Task ConfermaMov(int itemID) + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + bool result = false; + string source = "DB"; + result = await dbController.ConfermaMov(itemID); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ConfermaMov Read from {source}: {ts.TotalMilliseconds}ms"); + return result; + } + + /// + /// eliminazione record flux + /// + /// + /// + public async Task DeleteFlux(ItemFluxModel currRec) + { + var dbResult = await dbController.DeleteFlux(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyItemFlux}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + public void Dispose() { // Clear database controller @@ -56,6 +83,19 @@ namespace StockMan.CORE.Data GC.SuppressFinalize(this); } + public async Task EliminaDup(int itemID) + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + bool result = false; + string source = "DB"; + result = await dbController.EliminaDup(itemID); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"EliminaDup Read from {source}: {ts.TotalMilliseconds}ms"); + return result; + } + /// /// Svuotamento comleto cache REDIS /// @@ -68,6 +108,81 @@ namespace StockMan.CORE.Data return answ; } + /// + /// inserimento nuovo record item flux + /// + /// + /// + public async Task FluxAdd(ItemFluxModel newRec) + { + var dbResult = await dbController.FluxAdd(newRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyItemFlux}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + + /// + /// Aggiornamento record selezionato flusso + /// + /// + /// + public async Task FluxMod(ItemFluxModel currRec) + { + var dbResult = await dbController.FluxMod(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyItemFlux}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + + /// + /// inserimento nuovo record item + /// + /// + /// + public async Task ItemAdd(ItemModel newRec) + { + var dbResult = await dbController.ItemAdd(newRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyItems}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + + /// + /// inserimento nuovo record famiglia item + /// + /// + /// + public async Task ItemFamilyAdd(ItemFamilyModel newRec) + { + var dbResult = await dbController.ItemFamilyAdd(newRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyItemFamily}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + + /// + /// eliminazione record item family + /// + /// + /// + public async Task ItemFamilyDeleteByID(ItemFamilyModel currRec) + { + var dbResult = await dbController.ItemFamilyDeleteByID(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyItemFamily}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + /// /// Lista Famiglie Articoli /// @@ -109,219 +224,6 @@ namespace StockMan.CORE.Data return dbResult; } - /// - /// Aggiornamento record selezionato famiglia item - /// - /// - /// - public async Task ItemFamilyMod(ItemFamilyModel currRec) - { - var dbResult = await dbController.ItemFamilyMod(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyItemFamily}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - /// - /// Aggiornamento record selezionato operatore - /// - /// - /// - public async Task OperatorMod(OperatorModel currRec) - { - var dbResult = await dbController.OperatorMod(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyOperator}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - /// - /// Aggiornamento record selezionato locazione - /// - /// - /// - public async Task LocationMod(LocationModel currRec) - { - var dbResult = await dbController.LocationMod(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyLocation}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - /// - /// Aggiunta operatore - /// - /// - /// - public async Task OperatorAddNew(OperatorModel currRec) - { - var dbResult = await dbController.OperatorAddNew(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyOperator}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - /// - /// Aggiunta locazione - /// - /// - /// - public async Task LocationAddNew(LocationModel currRec) - { - var dbResult = await dbController.LocationAddNew(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyLocation}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - /// - /// Aggiornamento record selezionato item - /// - /// - /// - public async Task ItemMod(ItemModel currRec) - { - var dbResult = await dbController.ItemMod(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyItems}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - /// - /// Aggiornamento record selezionato flusso - /// - /// - /// - public async Task FluxMod(ItemFluxModel currRec) - { - var dbResult = await dbController.FluxMod(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyItemFlux}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - - - /// - /// inserimento nuovo record famiglia item - /// - /// - /// - public async Task ItemFamilyAdd(ItemFamilyModel newRec) - { - var dbResult = await dbController.ItemFamilyAdd(newRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyItemFamily}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - - /// - /// inserimento nuovo record item - /// - /// - /// - public async Task ItemAdd(ItemModel newRec) - { - var dbResult = await dbController.ItemAdd(newRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyItems}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - /// - /// inserimento nuovo record item flux - /// - /// - /// - public async Task FluxAdd(ItemFluxModel newRec) - { - var dbResult = await dbController.FluxAdd(newRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyItemFlux}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - /// - /// eliminazione record item family - /// - /// - /// - public async Task ItemFamilyDeleteByID(ItemFamilyModel currRec) - { - var dbResult = await dbController.ItemFamilyDeleteByID(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyItemFamily}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - /// - /// eliminazione record flux - /// - /// - /// - public async Task DeleteFlux(ItemFluxModel currRec) - { - var dbResult = await dbController.DeleteFlux(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyItemFlux}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - - /// - /// Lista Permessi - /// - /// - public async Task> PermessiGetAll() - { - string source = "DB"; - List? dbResult = new List(); - string currKey = $"{rKeyPermessi}:All"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string? rawData = await redisDb.StringGetAsync(currKey); - if (!string.IsNullOrEmpty(rawData)) - { - source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); - if (tempResult == null) - { - dbResult = new List(); - } - else - { - dbResult = tempResult; - } - } - else - { - dbResult = dbController.PermessiGetAll(); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, LongCache); - } - if (dbResult == null) - { - dbResult = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"PermessiGetAll | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - /// /// Lista Famiglie Articoli da ricerca /// @@ -362,6 +264,22 @@ namespace StockMan.CORE.Data Log.Debug($"ItemFamilyGetSearch | {source} in: {ts.TotalMilliseconds} ms"); return dbResult; } + + /// + /// Aggiornamento record selezionato famiglia item + /// + /// + /// + public async Task ItemFamilyMod(ItemFamilyModel currRec) + { + var dbResult = await dbController.ItemFamilyMod(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyItemFamily}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + /// /// Lista flussi x item da cercare /// @@ -402,94 +320,20 @@ namespace StockMan.CORE.Data Log.Debug($"ItemFluxGetById | {source} in: {ts.TotalMilliseconds} ms"); return dbResult; } - /// - /// Lista flussi x item da cercare - /// - /// - public async Task OperatorsGetByCodExt(string id) - { - string source = "DB"; - OperatorModel? dbResult = new OperatorModel(); - string currKey = $"{rKeyOperator}:Id:{id}"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string? rawData = await redisDb.StringGetAsync(currKey); - if (!string.IsNullOrEmpty(rawData)) - { - source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject(rawData); - if (tempResult == null) - { - dbResult = new OperatorModel(); - } - else - { - dbResult = tempResult; - } - } - else - { - dbResult = dbController.OperatorsGetByCodExt(id); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, LongCache); - } - if (dbResult == null) - { - dbResult = new OperatorModel(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"OperatorsGetByCodExt | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - public async Task ConfermaMov(int itemID) + /// + /// Aggiornamento record selezionato item + /// + /// + /// + public async Task ItemMod(ItemModel currRec) { - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - bool result = false; - string source = "DB"; - result = await dbController.ConfermaMov(itemID); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ConfermaMov Read from {source}: {ts.TotalMilliseconds}ms"); - return result; - } - public async Task EliminaDup(int itemID) - { - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - bool result = false; - string source = "DB"; - result = await dbController.EliminaDup(itemID); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"EliminaDup Read from {source}: {ts.TotalMilliseconds}ms"); - return result; - } - public async Task MoveItems(int stockId, string locationIdFrom, string locationIdTo, string oprId) - { - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - bool result = false; - string source = "DB"; - result = await dbController.MoveItems(stockId, locationIdFrom, locationIdTo, oprId); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"MoveItems Read from {source}: {ts.TotalMilliseconds}ms"); - return result; - } - public async Task MoveItems_New(int stockId, string locationIdFrom, string locationIdTo, string oprId, int qtyMov) - { - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - bool result = false; - string source = "DB"; - result = await dbController.MoveItems_New(stockId, locationIdFrom, locationIdTo, oprId, qtyMov); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"MoveItems_New Read from {source}: {ts.TotalMilliseconds}ms"); - return result; + var dbResult = await dbController.ItemMod(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyItems}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; } /// @@ -532,164 +376,56 @@ namespace StockMan.CORE.Data Log.Debug($"ItemsGetAll | {source} in: {ts.TotalMilliseconds} ms"); return dbResult; } + /// - /// Lista Location + /// Lista Articoli da ricerca per id /// /// - public async Task> LocationGetAll() + public async Task> ItemsGetByID(int id) { string source = "DB"; - List? dbResult = new List(); - string currKey = $"{rKeyLocation}:*"; + List? dbResult = new List(); + string currKey = ""; + currKey = $"{rKeyItems}:Id:{id}"; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string? rawData = await redisDb.StringGetAsync(currKey); - if (!string.IsNullOrEmpty(rawData)) - { - source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); - if (tempResult == null) - { - dbResult = new List(); - } - else - { - dbResult = tempResult; - } - } - else - { - dbResult = dbController.LocationGetAll(); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, LongCache); - } + dbResult = dbController.ItemsGetByID(id); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); if (dbResult == null) { - dbResult = new List(); + dbResult = new List(); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"LocationGetAll | {source} in: {ts.TotalMilliseconds} ms"); + Log.Debug($"ItemsGetByID | {source} in: {ts.TotalMilliseconds} ms"); return dbResult; } + /// - /// Lista Location + /// Lista Articoli da ricerca per location /// /// - public async Task> OperatorsGetAll() + public async Task> ItemsGetByLocation(string location) { string source = "DB"; - List? dbResult = new List(); - string currKey = $"{rKeyOperator}:*"; + List? dbResult = new List(); + string currKey = ""; + currKey = $"{rKeyItems}:Location:{location}"; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string? rawData = await redisDb.StringGetAsync(currKey); - if (!string.IsNullOrEmpty(rawData)) - { - source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); - if (tempResult == null) - { - dbResult = new List(); - } - else - { - dbResult = tempResult; - } - } - else - { - dbResult = dbController.OperatorsGetAll(); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, LongCache); - } + dbResult = dbController.ItemsGetByLocation(location); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); if (dbResult == null) { - dbResult = new List(); + dbResult = new List(); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"OperatorsGetAll | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - /// - /// Lista Location - /// - /// - public async Task> LocationGetLocType() - { - string source = "DB"; - List? dbResult = new List(); - string currKey = $"{rKeyLocType}: *"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string? rawData = await redisDb.StringGetAsync(currKey); - if (!string.IsNullOrEmpty(rawData)) - { - source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); - if (tempResult == null) - { - dbResult = new List(); - } - else - { - dbResult = tempResult; - } - } - else - { - dbResult = dbController.LocationGetLocType(); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, LongCache); - } - if (dbResult == null) - { - dbResult = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"LocationGetLocType | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - /// - /// Lista Location - /// - /// - public async Task> StockStatus() - { - string source = "DB"; - List? dbResult = new List(); - string currKey = $"{rKeyLocationVal}:*"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string? rawData = await redisDb.StringGetAsync(currKey); - if (!string.IsNullOrEmpty(rawData)) - { - source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); - if (tempResult == null) - { - dbResult = new List(); - } - else - { - dbResult = tempResult; - } - } - else - { - dbResult = dbController.StockStatus(); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, LongCache); - } - if (dbResult == null) - { - dbResult = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"StockStatus | {source} in: {ts.TotalMilliseconds} ms"); + Log.Debug($"ItemsGetByLocation | {source} in: {ts.TotalMilliseconds} ms"); return dbResult; } @@ -769,56 +505,7 @@ namespace StockMan.CORE.Data Log.Debug($"ItemsGetSearch | {source} in: {ts.TotalMilliseconds} ms"); return dbResult; } - /// - /// Lista Articoli da ricerca per id - /// - /// - public async Task> ItemsGetByID(int id) - { - string source = "DB"; - List? dbResult = new List(); - string currKey = ""; - currKey = $"{rKeyItems}:Id:{id}"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string? rawData = await redisDb.StringGetAsync(currKey); - dbResult = dbController.ItemsGetByID(id); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, LongCache); - if (dbResult == null) - { - dbResult = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ItemsGetByID | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - /// - /// Lista Articoli da ricerca per location - /// - /// - public async Task> ItemsGetByLocation(string location) - { - string source = "DB"; - List? dbResult = new List(); - string currKey = ""; - currKey = $"{rKeyItems}:Location:{location}"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string? rawData = await redisDb.StringGetAsync(currKey); - dbResult = dbController.ItemsGetByLocation(location); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, LongCache); - if (dbResult == null) - { - dbResult = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ItemsGetByLocation | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } + /// /// Lista Stock da cercare /// @@ -845,6 +532,338 @@ namespace StockMan.CORE.Data return dbResult; } + /// + /// Aggiunta locazione + /// + /// + /// + public async Task LocationAddNew(LocationModel currRec) + { + var dbResult = await dbController.LocationAddNew(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyLocation}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + + /// + /// Lista Location + /// + /// + public async Task> LocationGetAll() + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyLocation}:*"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.LocationGetAll(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"LocationGetAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Lista Location + /// + /// + public async Task> LocationGetLocType() + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyLocType}: *"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.LocationGetLocType(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"LocationGetLocType | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Aggiornamento record selezionato locazione + /// + /// + /// + public async Task LocationMod(LocationModel currRec) + { + var dbResult = await dbController.LocationMod(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyLocation}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + + public async Task MoveItems(int stockId, string locationIdFrom, string locationIdTo, string oprId) + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + bool result = false; + string source = "DB"; + result = await dbController.MoveItems(stockId, locationIdFrom, locationIdTo, oprId); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"MoveItems Read from {source}: {ts.TotalMilliseconds}ms"); + return result; + } + + public async Task MoveItems_New(int stockId, string locationIdFrom, string locationIdTo, string oprId, int qtyMov) + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + bool result = false; + string source = "DB"; + result = await dbController.MoveItems_New(stockId, locationIdFrom, locationIdTo, oprId, qtyMov); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"MoveItems_New Read from {source}: {ts.TotalMilliseconds}ms"); + return result; + } + + /// + /// Aggiunta operatore + /// + /// + /// + public async Task OperatorAddNew(OperatorModel currRec) + { + var dbResult = await dbController.OperatorAddNew(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyOperator}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + + /// + /// Aggiornamento record selezionato operatore + /// + /// + /// + public async Task OperatorMod(OperatorModel currRec) + { + var dbResult = await dbController.OperatorMod(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyOperator}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + + /// + /// Lista Location + /// + /// + public async Task> OperatorsGetAll() + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyOperator}:*"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.OperatorsGetAll(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"OperatorsGetAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Lista flussi x item da cercare + /// + /// + public async Task OperatorsGetByCodExt(string id) + { + string source = "DB"; + OperatorModel? dbResult = new OperatorModel(); + string currKey = $"{rKeyOperator}:Id:{id}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject(rawData); + if (tempResult == null) + { + dbResult = new OperatorModel(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.OperatorsGetByCodExt(id); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new OperatorModel(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"OperatorsGetByCodExt | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Lista Permessi + /// + /// + public async Task> PermessiGetAll() + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyPermessi}:All"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.PermessiGetAll(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"PermessiGetAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Lista Location + /// + /// + public async Task> StockStatus() + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyLocationVal}:*"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.StockStatus(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"StockStatus | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + #endregion Public Methods #region Protected Fields diff --git a/StockMan.CORE/Program.cs b/StockMan.CORE/Program.cs index d0c2a74..830e136 100644 --- a/StockMan.CORE/Program.cs +++ b/StockMan.CORE/Program.cs @@ -1,14 +1,12 @@ -using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Web; +using Blazored.LocalStorage; +using Blazored.SessionStorage; +using Microsoft.AspNetCore.Authentication.Negotiate; using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.AspNetCore.Localization; using StackExchange.Redis; using StockMan.CORE.Data; using StockMan.Data; using System.Globalization; -using Blazored.LocalStorage; -using Blazored.SessionStorage; -using Microsoft.AspNetCore.Authentication.Negotiate; var builder = WebApplication.CreateBuilder(args); diff --git a/StockMan.CORE/Properties/launchSettings.json b/StockMan.CORE/Properties/launchSettings.json index 21d09be..09c7d22 100644 --- a/StockMan.CORE/Properties/launchSettings.json +++ b/StockMan.CORE/Properties/launchSettings.json @@ -25,4 +25,4 @@ } } } -} +} \ No newline at end of file diff --git a/StockMan.Data/Controllers/StoManController.cs b/StockMan.Data/Controllers/StoManController.cs index db1bef5..ad3427c 100644 --- a/StockMan.Data/Controllers/StoManController.cs +++ b/StockMan.Data/Controllers/StoManController.cs @@ -21,20 +21,24 @@ namespace StockMan.Data.Controllers #region Public Methods /// - /// Lista Permessi + /// Conferma movimenti /// + /// /// - public List PermessiGetAll() + public async Task ConfermaMov(int itemID) { - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) + bool answ = false; + using (var dbCtx = new StockManContext(_configuration)) { - dbResult = localDbCtx - .DbSetPermessi - .OrderBy(x => x.GRUPPO) - .ToList(); + var ItemID = new SqlParameter("@ItemID", itemID); + + var callResult = await dbCtx + .Database + .ExecuteSqlRawAsync("exec dbo.stp_ItemConsolidate @ItemID", ItemID); + + answ = true; } - return dbResult; + return answ; } /// @@ -54,116 +58,79 @@ namespace StockMan.Data.Controllers return dbResult; } + /// + /// Flux Delete + /// + /// + public async Task DeleteFlux(ItemFluxModel currRec) + { + bool fatto = false; + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + try + { + var dbResult = localDbCtx + .DbSetItemFlux + .Where(x => x.Id == currRec.Id) + .FirstOrDefault(); + if (dbResult != null) + { + localDbCtx + .DbSetItemFlux + .Remove(dbResult); + await localDbCtx.SaveChangesAsync(); + fatto = true; + } + } + catch (Exception exc) + { + Log.Error($"Eccezione durante DeleteFlux{Environment.NewLine}{exc}"); + } + } + return fatto; + } + public void Dispose() { GC.Collect(); } /// - /// Lista Famiglie Articoli + /// Elimina movimenti duplicati /// + /// /// - public List ItemFamilyGetAll() + public async Task EliminaDup(int itemID) { - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) + bool answ = false; + using (var dbCtx = new StockManContext(_configuration)) { - dbResult = localDbCtx - .DbSetItemFamily - .OrderBy(x => x.Descr) - .ToList(); + var ItemID = new SqlParameter("@ItemID", itemID); + + var callResult = await dbCtx + .Database + .ExecuteSqlRawAsync("exec dbo.stp_ItemShrinkHist @ItemID", ItemID); + + answ = true; } - return dbResult; + return answ; } /// - /// Lista Famiglie Articoli da ricerca + /// aggiunta item /// /// - public List ItemFamilyGetSearch(string searchVal) - { - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - dbResult = localDbCtx - .DbSetItemFamily - .Where(x => x.Descr.Contains(searchVal)) - .OrderBy(x => x.Descr) - .ToList(); - } - return dbResult; - } - - ///// - ///// Modifica Famiglie Articoli - ///// - ///// - //public List ItemFamilyMod() - //{ - // List dbResult = new List(); - // using (StockManContext localDbCtx = new StockManContext(_configuration)) - // { - // dbResult = localDbCtx - // .DbSetItemFamily - // .OrderBy(x => x.Descr) - // .ToList(); - // } - // return dbResult; - - //} - - /// - /// Modifica famiglia articoli - /// - /// - public async Task ItemFamilyMod(ItemFamilyModel editRec) + public async Task FluxAdd(ItemFluxModel newRec) { bool fatto = false; - List dbResult = new List(); + List dbResult = new List(); using (StockManContext localDbCtx = new StockManContext(_configuration)) { try { var currRec = localDbCtx - .DbSetItemFamily - .Where(x => x.Id == editRec.Id) - .FirstOrDefault(); - if (currRec != null) - { - currRec.Descr = editRec.Descr; - } - else - { - localDbCtx - .DbSetItemFamily - .Add(editRec); - } - await localDbCtx.SaveChangesAsync(); - fatto = true; - } - catch (Exception exc) - { - Log.Error($"Eccezione durante ItemFamilyMod{Environment.NewLine}{exc}"); - } - } - return fatto; - - } - /// - /// Aggiungi Operatore - /// - /// - public async Task OperatorAddNew(OperatorModel editRec) - { - bool fatto = false; - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - try - { - var currRec = localDbCtx - .DbSetOperator - .Where(x => x.CodExt == editRec.CodExt) + .DbSetItemFlux + .Where(x => x.Id == newRec.Id) .FirstOrDefault(); if (currRec != null) { @@ -172,183 +139,20 @@ namespace StockMan.Data.Controllers else { localDbCtx - .DbSetOperator - .Add(editRec); + .DbSetItemFlux + .Add(newRec); } await localDbCtx.SaveChangesAsync(); fatto = true; } catch (Exception exc) { - Log.Error($"Eccezione durante OperatorMod{Environment.NewLine}{exc}"); + Log.Error($"Eccezione durante FluxAdd{Environment.NewLine}{exc}"); } } return fatto; - } - - /// - /// Aggiungi Locazione - /// - /// - public async Task LocationAddNew(LocationModel editRec) - { - bool fatto = false; - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - try - { - var currRec = localDbCtx - .DbSetLocation - .Where(x => x.Id == editRec.Id) - .FirstOrDefault(); - if (currRec != null) - { - fatto = false; - } - else - { - localDbCtx - .DbSetLocation - .Add(editRec); - } - await localDbCtx.SaveChangesAsync(); - fatto = true; - } - catch (Exception exc) - { - Log.Error($"Eccezione durante LocationAddNew{Environment.NewLine}{exc}"); - } - } - return fatto; - } - /// - /// Modifica Operatore - /// - /// - public async Task OperatorMod(OperatorModel editRec) - { - bool fatto = false; - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - try - { - var currRec = localDbCtx - .DbSetOperator - .Where(x => x.Id == editRec.Id) - .FirstOrDefault(); - if (currRec != null) - { - currRec.CodExt = editRec.CodExt; - currRec.LastName = editRec.LastName; - currRec.FirstName = editRec.FirstName; - } - else - { - localDbCtx - .DbSetOperator - .Add(editRec); - } - await localDbCtx.SaveChangesAsync(); - fatto = true; - } - catch (Exception exc) - { - Log.Error($"Eccezione durante OperatorMod{Environment.NewLine}{exc}"); - } - } - return fatto; - - } - /// - /// Modifica Locazione - /// - /// - public async Task LocationMod(LocationModel editRec) - { - bool fatto = false; - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - try - { - var currRec = localDbCtx - .DbSetLocation - .Where(x => x.Id == editRec.Id) - .FirstOrDefault(); - if (currRec != null) - { - currRec.Descr = editRec.Descr; - currRec.LocTypeId = editRec.LocTypeId; - } - else - { - localDbCtx - .DbSetLocation - .Add(editRec); - } - await localDbCtx.SaveChangesAsync(); - fatto = true; - } - catch (Exception exc) - { - Log.Error($"Eccezione durante LocationMod{Environment.NewLine}{exc}"); - } - } - return fatto; - - } - /// - /// Modifica item, - /// - /// - public async Task ItemMod(ItemModel editRec) - { - bool fatto = false; - //List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - try - { - var currRec = localDbCtx - .DbSetItem - .Where(x => x.Id == editRec.Id) - .FirstOrDefault(); - if (currRec != null) - { - currRec.Descr = editRec.Descr; - currRec.CodInt = editRec.CodInt; - currRec.ItemFamilyId = editRec.ItemFamilyId; - currRec.CodExt = editRec.CodExt; - currRec.DescrExt = editRec.DescrExt; - currRec.QtaMin = editRec.QtaMin; - currRec.QtaBatch = editRec.QtaBatch; - currRec.CurrValue = editRec.CurrValue; - currRec.QtaCurr = editRec.QtaCurr; - currRec.QtaPend = editRec.QtaPend; - currRec.Um = editRec.Um; - localDbCtx.Entry(currRec).State = EntityState.Modified; - } - else - { - localDbCtx - .DbSetItem - .Add(editRec); - } - await localDbCtx.SaveChangesAsync(); - fatto = true; - } - catch (Exception exc) - { - Log.Error($"Eccezione durante ItemMod{Environment.NewLine}{exc}"); - } - } - return fatto; - - } /// /// Modifica flux /// @@ -395,7 +199,43 @@ namespace StockMan.Data.Controllers } } return fatto; + } + /// + /// aggiunta item + /// + /// + public async Task ItemAdd(ItemModel newRec) + { + bool fatto = false; + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + try + { + var currRec = localDbCtx + .DbSetItem + .Where(x => x.Id == newRec.Id) + .FirstOrDefault(); + if (currRec != null) + { + fatto = false; + } + else + { + localDbCtx + .DbSetItem + .Add(newRec); + } + await localDbCtx.SaveChangesAsync(); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante ItemAdd{Environment.NewLine}{exc}"); + } + } + return fatto; } /// @@ -433,99 +273,8 @@ namespace StockMan.Data.Controllers } } return fatto; - - } - /// - /// aggiunta item - /// - /// - public async Task ItemAdd(ItemModel newRec) - { - bool fatto = false; - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - try - { - var currRec = localDbCtx - .DbSetItem - .Where(x => x.Id == newRec.Id) - .FirstOrDefault(); - if (currRec != null) - { - fatto = false; - } - else - { - localDbCtx - .DbSetItem - .Add(newRec); - } - await localDbCtx.SaveChangesAsync(); - fatto = true; - } - catch (Exception exc) - { - Log.Error($"Eccezione durante ItemAdd{Environment.NewLine}{exc}"); - } - } - return fatto; - - } - /// - /// aggiunta item - /// - /// - public async Task FluxAdd(ItemFluxModel newRec) - { - bool fatto = false; - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - try - { - var currRec = localDbCtx - .DbSetItemFlux - .Where(x => x.Id == newRec.Id) - .FirstOrDefault(); - if (currRec != null) - { - fatto = false; - } - else - { - localDbCtx - .DbSetItemFlux - .Add(newRec); - } - await localDbCtx.SaveChangesAsync(); - fatto = true; - } - catch (Exception exc) - { - Log.Error($"Eccezione durante FluxAdd{Environment.NewLine}{exc}"); - } - } - return fatto; - } - /// - /// Lista Items - /// - /// - public List ItemsGetAll() - { - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - dbResult = localDbCtx - .DbSetItem - .OrderBy(x => x.Descr) - .ToList(); - } - return dbResult; - } /// /// Lista Items /// @@ -537,7 +286,6 @@ namespace StockMan.Data.Controllers { try { - var dbResult = localDbCtx .DbSetItemFamily .Where(x => x.Id == currRec.Id) @@ -558,39 +306,204 @@ namespace StockMan.Data.Controllers } return fatto; } + /// - /// Flux Delete + /// Lista Famiglie Articoli /// /// - public async Task DeleteFlux(ItemFluxModel currRec) + public List ItemFamilyGetAll() + { + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + dbResult = localDbCtx + .DbSetItemFamily + .OrderBy(x => x.Descr) + .ToList(); + } + return dbResult; + } + + /// + /// Lista Famiglie Articoli da ricerca + /// + /// + public List ItemFamilyGetSearch(string searchVal) + { + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + dbResult = localDbCtx + .DbSetItemFamily + .Where(x => x.Descr.Contains(searchVal)) + .OrderBy(x => x.Descr) + .ToList(); + } + return dbResult; + } + + /// + /// Modifica famiglia articoli + /// + /// + public async Task ItemFamilyMod(ItemFamilyModel editRec) { bool fatto = false; + List dbResult = new List(); using (StockManContext localDbCtx = new StockManContext(_configuration)) { try { - - var dbResult = localDbCtx - .DbSetItemFlux - .Where(x => x.Id == currRec.Id) - .FirstOrDefault(); - if (dbResult != null) + var currRec = localDbCtx + .DbSetItemFamily + .Where(x => x.Id == editRec.Id) + .FirstOrDefault(); + if (currRec != null) + { + currRec.Descr = editRec.Descr; + } + else { localDbCtx - .DbSetItemFlux - .Remove(dbResult); - await localDbCtx.SaveChangesAsync(); - fatto = true; + .DbSetItemFamily + .Add(editRec); } + await localDbCtx.SaveChangesAsync(); + fatto = true; } catch (Exception exc) { - Log.Error($"Eccezione durante DeleteFlux{Environment.NewLine}{exc}"); + Log.Error($"Eccezione durante ItemFamilyMod{Environment.NewLine}{exc}"); } } return fatto; } + /// + /// Lista Flux x item + /// + /// + public List ItemFluxGetById(int id) + { + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + dbResult = localDbCtx + .DbSetItemFlux + .Include(l => l.Location) + .Include(e => e.ExtLocation) + .Where(x => x.ItemId == id) + .OrderByDescending(x => x.Id) + .ToList(); + } + return dbResult; + } + + /// + /// Modifica item, + /// + /// + public async Task ItemMod(ItemModel editRec) + { + bool fatto = false; + //List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + try + { + var currRec = localDbCtx + .DbSetItem + .Where(x => x.Id == editRec.Id) + .FirstOrDefault(); + if (currRec != null) + { + currRec.Descr = editRec.Descr; + currRec.CodInt = editRec.CodInt; + currRec.ItemFamilyId = editRec.ItemFamilyId; + currRec.CodExt = editRec.CodExt; + currRec.DescrExt = editRec.DescrExt; + currRec.QtaMin = editRec.QtaMin; + currRec.QtaBatch = editRec.QtaBatch; + currRec.CurrValue = editRec.CurrValue; + currRec.QtaCurr = editRec.QtaCurr; + currRec.QtaPend = editRec.QtaPend; + currRec.Um = editRec.Um; + localDbCtx.Entry(currRec).State = EntityState.Modified; + } + else + { + localDbCtx + .DbSetItem + .Add(editRec); + } + await localDbCtx.SaveChangesAsync(); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante ItemMod{Environment.NewLine}{exc}"); + } + } + return fatto; + } + + /// + /// Lista Items + /// + /// + public List ItemsGetAll() + { + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + dbResult = localDbCtx + .DbSetItem + .OrderBy(x => x.Descr) + .ToList(); + } + return dbResult; + } + + /// + /// Lista Items da ricerca + /// + /// + public List ItemsGetByID(int id) + { + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + var risultato = localDbCtx + .DbSetItem + .Where(x => ((x.Id == id))) + .ToList(); + + if (risultato != null) + { + dbResult = risultato; + } + } + return dbResult; + } + + /// + /// Lista Items da ricerca + /// + /// + public List ItemsGetByLocation(string locationSel) + { + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + dbResult = localDbCtx + .DbSetItemStock + .Where(x => x.LocationId == locationSel) + .Include(l => l.ItemNav) + .ToList(); + } + return dbResult; + } + ///// ///// Lista Items da ricerca ///// @@ -664,45 +577,6 @@ namespace StockMan.Data.Controllers return dbResult; } - /// - /// Lista Items da ricerca - /// - /// - public List ItemsGetByID(int id) - { - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - var risultato = localDbCtx - .DbSetItem - .Where(x => ((x.Id == id))) - .ToList(); - - if (risultato != null) - { - dbResult = risultato; - } - } - return dbResult; - } - /// - /// Lista Items da ricerca - /// - /// - public List ItemsGetByLocation(string locationSel) - { - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - dbResult = localDbCtx - .DbSetItemStock - .Where(x => x.LocationId == locationSel) - .Include(l => l.ItemNav) - .ToList(); - } - return dbResult; - } - /// /// Lista Item Stock (ALL!) /// @@ -740,20 +614,40 @@ namespace StockMan.Data.Controllers } /// - /// Lista Item Stock (raggruppati x location) + /// Aggiungi Locazione /// /// - public List StockStatus() + public async Task LocationAddNew(LocationModel editRec) { - List dbResult = new List(); + bool fatto = false; + List dbResult = new List(); using (StockManContext localDbCtx = new StockManContext(_configuration)) { - dbResult = localDbCtx - .DbSetVLocationVal - .Include(l => l.LocationNav) - .ToList(); + try + { + var currRec = localDbCtx + .DbSetLocation + .Where(x => x.Id == editRec.Id) + .FirstOrDefault(); + if (currRec != null) + { + fatto = false; + } + else + { + localDbCtx + .DbSetLocation + .Add(editRec); + } + await localDbCtx.SaveChangesAsync(); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante LocationAddNew{Environment.NewLine}{exc}"); + } } - return dbResult; + return fatto; } /// @@ -772,6 +666,7 @@ namespace StockMan.Data.Controllers } return dbResult; } + /// /// Lista Locazioni join con tabella location type /// @@ -783,14 +678,52 @@ namespace StockMan.Data.Controllers { dbResult = localDbCtx .DbSetLocation - .Include(l=>l.LocTypeNav) - .Where(x=>x.LocTypeNav.IsStock) + .Include(l => l.LocTypeNav) + .Where(x => x.LocTypeNav.IsStock) .OrderBy(x => x.Id) .ToList(); } return dbResult; } + /// + /// Modifica Locazione + /// + /// + public async Task LocationMod(LocationModel editRec) + { + bool fatto = false; + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + try + { + var currRec = localDbCtx + .DbSetLocation + .Where(x => x.Id == editRec.Id) + .FirstOrDefault(); + if (currRec != null) + { + currRec.Descr = editRec.Descr; + currRec.LocTypeId = editRec.LocTypeId; + } + else + { + localDbCtx + .DbSetLocation + .Add(editRec); + } + await localDbCtx.SaveChangesAsync(); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante LocationMod{Environment.NewLine}{exc}"); + } + } + return fatto; + } + /// /// Lista Tipi Locazioni /// @@ -808,126 +741,6 @@ namespace StockMan.Data.Controllers return dbResult; } - /// - /// Lista Tipi Movimenti - /// - /// - public List MovTypeGetAll() - { - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - dbResult = localDbCtx - .DbSetMovType - .OrderBy(x => x.Descr) - .ToList(); - } - return dbResult; - } - - /// - /// Lista Operatori - /// - /// - public List OperatorsGetAll() - { - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - dbResult = localDbCtx - .DbSetOperator - .OrderBy(x => x.LastName) - .ThenBy(x => x.FirstName) - .ToList(); - } - return dbResult; - } - /// - /// Operatore cercato - /// - /// - public OperatorModel OperatorsGetByCodExt(string codExt) - { - OperatorModel dbResult = new OperatorModel(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - var risultato = localDbCtx - .DbSetOperator - .Where(x => x.CodExt == codExt) - .OrderBy(x => x.LastName) - .ThenBy(x => x.FirstName) - .FirstOrDefault(); - - if (risultato != null) - { - dbResult = risultato; - } - } - return dbResult; - } - - - /// - /// Lista Flux x item - /// - /// - public List ItemFluxGetById(int id) - { - List dbResult = new List(); - using (StockManContext localDbCtx = new StockManContext(_configuration)) - { - dbResult = localDbCtx - .DbSetItemFlux - .Include(l=>l.Location) - .Include(e=>e.ExtLocation) - .Where(x => x.ItemId == id) - .OrderByDescending(x => x.Id) - .ToList(); - } - return dbResult; - } - - - /// - /// Conferma movimenti - /// - /// - /// - public async Task ConfermaMov(int itemID) - { - bool answ = false; - using (var dbCtx = new StockManContext(_configuration)) - { - var ItemID = new SqlParameter("@ItemID", itemID); - - var callResult = await dbCtx - .Database - .ExecuteSqlRawAsync("exec dbo.stp_ItemConsolidate @ItemID", ItemID); - - answ = true; - } - return answ; - } - /// - /// Elimina movimenti duplicati - /// - /// - /// - public async Task EliminaDup(int itemID) - { - bool answ = false; - using (var dbCtx = new StockManContext(_configuration)) - { - var ItemID = new SqlParameter("@ItemID", itemID); - - var callResult = await dbCtx - .Database - .ExecuteSqlRawAsync("exec dbo.stp_ItemShrinkHist @ItemID", ItemID); - - answ = true; - } - return answ; - } /// /// Muove gli items nei vari scaffali /// @@ -950,6 +763,7 @@ namespace StockMan.Data.Controllers } return answ; } + /// /// Muove gli items nei vari scaffali /// @@ -974,6 +788,191 @@ namespace StockMan.Data.Controllers return answ; } + /// + /// Lista Tipi Movimenti + /// + /// + public List MovTypeGetAll() + { + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + dbResult = localDbCtx + .DbSetMovType + .OrderBy(x => x.Descr) + .ToList(); + } + return dbResult; + } + + //} + /// + /// Aggiungi Operatore + /// + /// + public async Task OperatorAddNew(OperatorModel editRec) + { + bool fatto = false; + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + try + { + var currRec = localDbCtx + .DbSetOperator + .Where(x => x.CodExt == editRec.CodExt) + .FirstOrDefault(); + if (currRec != null) + { + fatto = false; + } + else + { + localDbCtx + .DbSetOperator + .Add(editRec); + } + await localDbCtx.SaveChangesAsync(); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante OperatorMod{Environment.NewLine}{exc}"); + } + } + return fatto; + } + + ///// + ///// Modifica Famiglie Articoli + ///// + ///// + //public List ItemFamilyMod() + //{ + // List dbResult = new List(); + // using (StockManContext localDbCtx = new StockManContext(_configuration)) + // { + // dbResult = localDbCtx + // .DbSetItemFamily + // .OrderBy(x => x.Descr) + // .ToList(); + // } + // return dbResult; + /// + /// Modifica Operatore + /// + /// + public async Task OperatorMod(OperatorModel editRec) + { + bool fatto = false; + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + try + { + var currRec = localDbCtx + .DbSetOperator + .Where(x => x.Id == editRec.Id) + .FirstOrDefault(); + if (currRec != null) + { + currRec.CodExt = editRec.CodExt; + currRec.LastName = editRec.LastName; + currRec.FirstName = editRec.FirstName; + } + else + { + localDbCtx + .DbSetOperator + .Add(editRec); + } + await localDbCtx.SaveChangesAsync(); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante OperatorMod{Environment.NewLine}{exc}"); + } + } + return fatto; + } + + /// + /// Lista Operatori + /// + /// + public List OperatorsGetAll() + { + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + dbResult = localDbCtx + .DbSetOperator + .OrderBy(x => x.LastName) + .ThenBy(x => x.FirstName) + .ToList(); + } + return dbResult; + } + + /// + /// Operatore cercato + /// + /// + public OperatorModel OperatorsGetByCodExt(string codExt) + { + OperatorModel dbResult = new OperatorModel(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + var risultato = localDbCtx + .DbSetOperator + .Where(x => x.CodExt == codExt) + .OrderBy(x => x.LastName) + .ThenBy(x => x.FirstName) + .FirstOrDefault(); + + if (risultato != null) + { + dbResult = risultato; + } + } + return dbResult; + } + + /// + /// Lista Permessi + /// + /// + public List PermessiGetAll() + { + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + dbResult = localDbCtx + .DbSetPermessi + .OrderBy(x => x.GRUPPO) + .ToList(); + } + return dbResult; + } + + /// + /// Lista Item Stock (raggruppati x location) + /// + /// + public List StockStatus() + { + List dbResult = new List(); + using (StockManContext localDbCtx = new StockManContext(_configuration)) + { + dbResult = localDbCtx + .DbSetVLocationVal + .Include(l => l.LocationNav) + .ToList(); + } + return dbResult; + } + #endregion Public Methods #region Private Fields