- metodo remove
This commit is contained in:
Samuele Locatelli
2023-03-30 11:33:13 +02:00
parent b04f09bb1c
commit 67dc2c5acd
4 changed files with 70 additions and 6 deletions
@@ -334,6 +334,37 @@ namespace WebDoorCreator.Data.Controllers
return fatto;
}
/// <summary>
/// Remove order
/// </summary>
/// <param name="OrdId">Record to add</param>
/// <returns></returns>
public async Task<bool> 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
@@ -14,7 +14,8 @@ else
<th class="text-end">Doors Number</th>
<th class="text-end">Model Number</th>
<th class="text-end">TOTAL COST</th>
@* <th>PROGRESS</th>*@
@*<th>PROGRESS</th>*@
<th class="text-end"></th>
</tr>
</thead>
<tbody>
@@ -29,10 +30,16 @@ else
<td class="text-end">@item.NumType</td>
<td class="text-end">@($"{item.TotCost:C2}")</td>
@*<td>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-label="Basic example" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: calc(20%item.OrderStatus); background-color: @setPgColor(item.OrderStatus)"></div>
</div>
</td>*@
<div class="progress">
<div class="progress-bar" role="progressbar" aria-label="Basic example" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: calc(20%item.OrderStatus); background-color: @setPgColor(item.OrderStatus)"></div>
</div>
</td>*@
<td class="text-end">
@if (item.OrderStatus < (int)Core.Enum.OrderStatus.Sent)
{
<button class="btn btn-sm btn-danger" @onclick="() => deleteRecord(item)"><i class="fa-solid fa-trash-can"></i></button>
}
</td>
</tr>
}
</tbody>
@@ -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<bool>("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
}
}
@@ -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;
}
/// <summary>
/// Remove order
/// </summary>
/// <param name="currRec"></param>
/// <returns></returns>
public async Task<bool> OrderRem(int OrdId)
{
var dbResult = await dbController.OrderRem(OrdId);
// elimino cache redis...
RedisValue pattern = new RedisValue($"{rKeyOrderStatus}:*");
bool answ = await ExecFlushRedisPattern(pattern);
return dbResult;
}