From 67dc2c5acd39f04ea38dabd2df24114b8797f3a8 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 30 Mar 2023 11:33:13 +0200 Subject: [PATCH] ORDERS - metodo remove --- .../Controllers/WebDoorCreatorController.cs | 31 +++++++++++++++++++ .../Components/Order/OrderList.razor | 17 +++++++--- .../Components/Order/OrderList.razor.cs | 14 +++++++++ .../Data/WebDoorCreatorService.cs | 14 ++++++++- 4 files changed, 70 insertions(+), 6 deletions(-) diff --git a/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs b/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs index 71a2ffe..38beef7 100644 --- a/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs +++ b/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs @@ -334,6 +334,37 @@ namespace WebDoorCreator.Data.Controllers return fatto; } + /// + /// Remove order + /// + /// Record to add + /// + public async Task OrderRem(int OrdId) + { + bool fatto = false; + using (WDCDataContext localDbCtx = new WDCDataContext(_configuration)) + { + try + { + var selRec = localDbCtx + .DbSetOrders + .Where(x => x.OrderId == OrdId) + .FirstOrDefault(); + if (selRec != null) + { + localDbCtx.DbSetOrders.Remove(selRec); + await localDbCtx.SaveChangesAsync(); + fatto = true; + } + } + catch (Exception exc) + { + Log.Error($"Eccezione durante OrderRem: {Environment.NewLine}{exc}"); + } + } + return fatto; + } + #endregion Order methods #region Door methods diff --git a/WebDoorCreator.UI/Components/Order/OrderList.razor b/WebDoorCreator.UI/Components/Order/OrderList.razor index a91963d..8a3df44 100644 --- a/WebDoorCreator.UI/Components/Order/OrderList.razor +++ b/WebDoorCreator.UI/Components/Order/OrderList.razor @@ -14,7 +14,8 @@ else Doors Number Model Number TOTAL COST - @* PROGRESS*@ + @*PROGRESS*@ + @@ -29,10 +30,16 @@ else @item.NumType @($"{item.TotCost:C2}") @* -
-
-
- *@ +
+
+
+ *@ + + @if (item.OrderStatus < (int)Core.Enum.OrderStatus.Sent) + { + + } + } diff --git a/WebDoorCreator.UI/Components/Order/OrderList.razor.cs b/WebDoorCreator.UI/Components/Order/OrderList.razor.cs index 987afec..b96c87a 100644 --- a/WebDoorCreator.UI/Components/Order/OrderList.razor.cs +++ b/WebDoorCreator.UI/Components/Order/OrderList.razor.cs @@ -1,7 +1,9 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Identity; using Microsoft.JSInterop; +using NLog.LayoutRenderers; using WebDoorCreator.Data.DbModels; using WebDoorCreator.UI.Data; @@ -117,6 +119,18 @@ namespace WebDoorCreator.UI.Components.Order await E_currOrderStatus.InvokeAsync(currOrd); } + protected async Task deleteRecord(OrderStatusViewModel currRec) + { + + if (!await JSRuntime.InvokeAsync("confirm", $"Order Deletion requested: are you sure to remove {currRec.OrderExtCode}?")) + return; + + await Task.Delay(1); + var done = await WDService.OrderRem(currRec.OrderId); + await WDService.OrdersFlushCache(); + await ReloadData(); + } + #endregion Private Methods } } \ No newline at end of file diff --git a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs index e08462b..6287655 100644 --- a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs +++ b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs @@ -497,7 +497,19 @@ namespace WebDoorCreator.UI.Data // elimino cache redis... RedisValue pattern = new RedisValue($"{rKeyOrderStatus}:*"); bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); + return dbResult; + } + /// + /// Remove order + /// + /// + /// + public async Task OrderRem(int OrdId) + { + var dbResult = await dbController.OrderRem(OrdId); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyOrderStatus}:*"); + bool answ = await ExecFlushRedisPattern(pattern); return dbResult; }