continuo gestione ordini

This commit is contained in:
zaccaria.majid
2023-03-14 15:51:32 +01:00
parent 59059676d5
commit 6cc360619e
9 changed files with 507 additions and 14 deletions
@@ -1,6 +1,8 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using NLog;
using System.Collections.Generic;
using WebDoorCreator.Data.DbModels;
using WebDoorCreator.Data.DTO;
@@ -93,7 +95,7 @@ namespace WebDoorCreator.Data.Controllers
}
catch (Exception exc)
{
Log.Error($"Eccezione durante CompanyAddMod;{Environment.NewLine}{exc}");
Log.Error($"Eccezione durante CompanyAddMod: {Environment.NewLine}{exc}");
}
}
return fatto;
@@ -101,7 +103,7 @@ namespace WebDoorCreator.Data.Controllers
#endregion Company methods
#region user methods
#region User methods
/// <summary>
/// Populating DTO to handle users
@@ -133,6 +135,7 @@ namespace WebDoorCreator.Data.Controllers
}
return dbResult;
}
/// <summary>
/// Retrieving data from user/roles relation
/// </summary>
@@ -157,6 +160,7 @@ namespace WebDoorCreator.Data.Controllers
}
return dbResult;
}
/// <summary>
/// Retrieving data from users table
/// </summary>
@@ -181,6 +185,7 @@ namespace WebDoorCreator.Data.Controllers
}
return dbResult;
}
/// <summary>
/// Retrieving data from users table filtered by id
/// </summary>
@@ -200,7 +205,7 @@ namespace WebDoorCreator.Data.Controllers
.OrderBy(x => x.Id)
.FirstOrDefault();
if(risultato != null)
if (risultato != null)
{
dbResult = risultato;
}
@@ -217,9 +222,9 @@ namespace WebDoorCreator.Data.Controllers
return dbResult;
}
#endregion user methods
#endregion User methods
#region roles methods
#region Roles methods
/// <summary>
/// Retrieving data from roles table
@@ -245,8 +250,77 @@ namespace WebDoorCreator.Data.Controllers
}
return dbResult;
}
#endregion roles methods
#endregion Roles methods
#region Order status methods
/// <summary>
/// Order status
/// </summary>
/// <param name="companyId"></param>
/// <param name="orderStatus"></param>
/// <param name="dataFrom"></param>
/// <param name="dataTo"></param>
/// <returns></returns>
public List<OrderStatusViewModel> GetOrderStatus(int companyId, int orderStatus, DateTime dataFrom, DateTime dataTo)
{
List<OrderStatusViewModel> dbResult = new List<OrderStatusViewModel>();
using (var dbCtx = new WDCDataContext(_configuration))
{
try
{
var CompanyId = new SqlParameter("@CompanyId", companyId);
var OrderStatus = new SqlParameter("@OrderStatus", orderStatus);
var DataFrom = new SqlParameter("@DataFrom", dataFrom.Date);
var DataTo = new SqlParameter("@DataTo", dataTo.Date);
var k = $"exec dbo.stp_OrderList_getFilt {companyId}, {orderStatus}, '{dataFrom.Date.ToString("yyyy/MM/dd")}', '{dataTo.Date.ToString("yyyy/MM/dd")}'";
dbResult = dbCtx
.DbSetOrderStatus
.FromSqlRaw("exec dbo.stp_OrderList_getFilt @CompanyId, @OrderStatus, @DataFrom, @DataTo", CompanyId, OrderStatus, DataFrom, DataTo)
.AsNoTracking()
.ToList();
}
catch (Exception exc)
{
Log.Error($"Error in GetOrderStatus:{Environment.NewLine}{exc}");
}
}
return dbResult;
}
#endregion Order status methods
#region Order methods
/// <summary>
/// Adding a new order
/// </summary>
/// <param name="addRec">Record to add</param>
/// <returns></returns>
public async Task<bool> OrderAdd(OrderModel addRec)
{
bool fatto = false;
using (WDCDataContext localDbCtx = new WDCDataContext(_configuration))
{
try
{
localDbCtx
.DbSetOrders
.Add(addRec);
await localDbCtx.SaveChangesAsync();
fatto = true;
}
catch (Exception exc)
{
Log.Error($"Eccezione durante OrderAd: {Environment.NewLine}{exc}");
}
}
return fatto;
}
#endregion Order methods
}
}
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
namespace WebDoorCreator.Data.DbModels
{
/// <summary>
/// View to retrieve data from multiple tables
/// </summary>
[Table("v_OrderStatus")]
public class OrderStatusViewModel
{
/// <summary>
/// OrderId from Order table
/// </summary>
[Key]
public int OrderId { get; set; } = 0;
/// <summary>
/// CompanyId from Order table
/// </summary>
public int CompanyId { get; set; } = 0;
/// <summary>
/// OrderExtCode from Order table
/// </summary>
public string OrderExtCode { get; set; } = "";
/// <summary>
/// DateIns from Order table
/// </summary>
public DateTime DateIns { get; set; }
/// <summary>
/// UserIdIns from Order table
/// </summary>
public string UserIdIns { get; set; } = "";
/// <summary>
/// UserIdMod from Order table
/// </summary>
public string UserIdMod { get; set; } = "";
/// <summary>
/// OrderStatus from Order table
/// </summary>
public int OrderStatus { get; set; } = 0;
/// <summary>
/// OrderDescript from Order table
/// </summary>
public string OrderDescript { get; set; } = "";
/// <summary>
/// NumType sums all the different types of doors in the order
/// </summary>
public int NumType { get; set; } = 0;
/// <summary>
/// NumDoors sums all the different doors in the order
/// </summary>
public int NumDoors { get; set; } = 0;
/// <summary>
/// TotCost represent the total cost of the order
/// </summary>
public decimal TotCost { get; set; } = 0;
}
}
+1
View File
@@ -57,6 +57,7 @@ namespace WebDoorCreator.Data
public virtual DbSet<DoorModel> DbSetDoor { get; set; }
public virtual DbSet<DoorTypeModel> DbSetDoorType { get; set; }
public virtual DbSet<UsersViewModel> DbSetUsersView { get; set; }
public virtual DbSet<OrderStatusViewModel> DbSetOrderStatus { get; set; }
@@ -11,11 +11,15 @@
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="nav-item px-3 d-flex flex-warp align-items-center">
<NavLink class="nav-link" href="OrdersHomePage">
<span class="oi oi-cart" aria-hidden="true"></span> Orders home page
</NavLink>
</div>
<AuthorizeView Roles="SuperAdmin, CompAdmin, CompUser" Context="MenuHide">
<Authorized>
<div class="nav-item px-3 d-flex flex-warp align-items-center">
<NavLink class="nav-link" href="OrdersHomePage">
<span class="oi oi-cart" aria-hidden="true"></span> Orders home page
</NavLink>
</div>
</Authorized>
</AuthorizeView>
<!--Hiding to non-SuperAdmin users the option to manage the application -->
<AuthorizeView Roles="SuperAdmin" Context="MenuHide">
<Authorized>
@@ -0,0 +1,40 @@
@if (ListOrdersStatus == null)
{
<EgwCoreLib.Razor.LoadingData></EgwCoreLib.Razor.LoadingData>
}
else
{
<table class="table table-sm table-striped table-responsive-md border border-dark">
<thead>
<tr class="bg-dark text-light">
<td></td>
<th>Order Date</th>
<th>Order Number</th>
<th>Order Description</th>
<th>Doors Number</th>
<th>Model Number</th>
<th>TOTAL COST</th>
<th>PROGRESS</th>
</tr>
</thead>
<tbody>
@foreach (var item in ListOrdersStatus)
{
<tr>
<td><button class="btn btn-sm btn-warning"><i class="fa-solid fa-pen-to-square"></i></button></td>
<td>@item.DateIns</td>
<td>@item.OrderId</td>
<td>@item.OrderDescript</td>
<td>@item.NumDoors</td>
<td>@item.NumType</td>
<td>@item.TotCost</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>
</tr>
}
</tbody>
</table>
}
@@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.JSInterop;
using WebDoorCreator.UI;
using WebDoorCreator.UI.Components;
using WebDoorCreator.UI.Shared;
using WebDoorCreator.Data.DbModels;
using WebDoorCreator.UI.Data;
namespace WebDoorCreator.UI.Components
{
public partial class OrderList
{
#region Protected Properties
[Inject]
protected WebDoorCreatorService WDService { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
[Parameter]
public EventCallback<OrderStatusViewModel> E_currOrderStatus { get; set; }
#endregion Protected Properties
#region Protected Methods
protected override async Task OnInitializedAsync()
{
await ReloadData();
}
#endregion Protected Methods
#region Private Fields
private List<OrderStatusViewModel>? ListOrdersStatus = null;
#endregion Private Fields
#region Private Methods
//protected List<UsersViewModel>? UsersList { get; set; } = null;
//protected List<AspNetRoles>? RolesList { get; set; } = null;
protected OrderStatusViewModel? currOrder { get; set; } = null;
protected bool isModRole { get; set; } = false;
private async Task ReloadData()
{
var adesso = DateTime.Now.Date;
ListOrdersStatus = null;
await Task.Delay(1);
ListOrdersStatus = await WDService.GetOrderStatus(0, 0, adesso.AddYears(-2), adesso);
await Task.Delay(1);
await InvokeAsync(StateHasChanged);
}
private async Task setCurrOrder(string userId)
{
await Task.Delay(1);
}
protected string setPgColor(int progress)
{
string answ = "";
if(progress == 1)
{
answ = "#D35400";
}
else if (progress == 2)
{
answ = "#F1C40F";
}
else if (progress == 3)
{
answ = "#2980B9";
}
else if (progress == 4)
{
answ = "#8E44AD";
}
else if (progress == 5)
{
answ = "#27AE60";
}
return answ;
}
//private async Task editRec(CompanyModel currComp)
//{
// await E_currCompany.InvokeAsync(currComp);
//}
#endregion Private Methods
}
}
@@ -7,6 +7,7 @@ using WebDoorCreator.Data.Controllers;
using WebDoorCreator.Data.DbModels;
using EgwCoreLib.Razor.Data;
using WebDoorCreator.Data.DTO;
using WebDoorCreator.Data;
namespace WebDoorCreator.UI.Data
{
@@ -112,7 +113,7 @@ namespace WebDoorCreator.UI.Data
{
var dbResult = await dbController.CompanyAddMod(currRec);
// elimino cache redis...
RedisValue pattern = new RedisValue($"{rKeyCompany}:cache:*");
RedisValue pattern = new RedisValue($"{rKeyCompany}:*");
bool answ = await ExecFlushRedisPattern(pattern);
await Task.Delay(1);
return dbResult;
@@ -299,6 +300,7 @@ namespace WebDoorCreator.UI.Data
}
#endregion User Methods
/*----------------------------------------------------------------------------------------------------------------------*/
#region Roles Methods
@@ -344,7 +346,70 @@ namespace WebDoorCreator.UI.Data
return dbResult;
}
#endregion Roles Methods
/*----------------------------------------------------------------------------------------------------------------------*/
#region Order status Methods
public async Task<List<OrderStatusViewModel>?> GetOrderStatus(int companyId, int orderStatus, DateTime dataFrom, DateTime dataTo)
{
string source = "DB";
List<OrderStatusViewModel>? dbResult = new List<OrderStatusViewModel>();
// cerco da cache
string currKey = rKeyOrderStatus;
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<List<OrderStatusViewModel>>(rawData);
if (tempResult == null)
{
dbResult = new List<OrderStatusViewModel>();
}
else
{
dbResult = tempResult;
}
}
else
{
dbResult = dbController.GetOrderStatus(companyId, orderStatus, dataFrom, dataTo);
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
if (dbResult == null)
{
dbResult = new List<OrderStatusViewModel>();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"GetOrderStatus | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
#endregion Order status Methods
#region Order methods
/// <summary>
/// Add new order
/// </summary>
/// <param name="currRec"></param>
/// <returns></returns>
public async Task<bool> OrderAdd(OrderModel currRec)
{
var dbResult = await dbController.OrderAdd(currRec);
// elimino cache redis...
RedisValue pattern = new RedisValue($"{rKeyOrderStatus}:*");
bool answ = await ExecFlushRedisPattern(pattern);
await Task.Delay(1);
return dbResult;
}
#endregion Order methods
#endregion Public Methods
#region Protected Fields
@@ -384,6 +449,7 @@ namespace WebDoorCreator.UI.Data
//#endregion Public Methods
protected const string rKeyCompany = $"{redisBaseAddr}:Cache:Company";
protected const string rKeyOrderStatus = $"{redisBaseAddr}:Cache:OrderStatus";
protected const string rKeyUsers = $"{redisBaseAddr}:Cache:Users";
protected const string rKeyUsersView = $"{redisBaseAddr}:Cache:UsersView";
protected const string rKeyRoles = $"{redisBaseAddr}:Cache:Roles";
+53 -1
View File
@@ -1,4 +1,56 @@
@page "/OrdersHomePage"
<h3>ORDERS</h3>
<AuthorizeView>
<Authorized>
<div class="card">
<div class="pb-0 d-flex justify-content-start card-header">
<div class="fs-5">
ORDERS
</div>
</div>
<div class="card-body">
<!-- Button trigger modal -->
<div class="d-flex justify-content-between mb-2">
<h5 class="">Orders list</h5>
<button type="button" class="btn btn-sm btn-success" data-bs-toggle="modal" data-bs-target="#newOrderModal">
<i class="fa-solid fa-plus"></i> Add new order
</button>
</div>
<OrderList></OrderList>
</div>
</div>
<!-- Modal Order -->
<div class="modal fade" id="newOrderModal" tabindex="-1" aria-labelledby="newOrderModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="newCompModalLabel">Insert new company</h1>
</div>
<div class="modal-body">
<div class="w-100">
<div class="form-floating">
<input id="orderCodExt" @bind-value="@orderCodExt" class="form-control w-100 w-100w-100 my-1" />
<label for="orderCodExt" class="form-label">Order external code</label>
</div>
<div class="form-floating">
<textarea id="orderDescr" @bind="@orderDescr" class="form-control w-100" rows="3"></textarea>
<label for="orderDescr" class="form-label">Order description</label>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
@if (orderCodExt != "")
{
<button type="button" class="btn btn-primary" @onclick="()=>addNewOrder(context.User.Identity?.Name!)">Save changes</button>
}
</div>
</div>
</div>
</div>
</Authorized>
</AuthorizeView>
@@ -13,10 +13,84 @@ using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.JSInterop;
using WebDoorCreator.UI;
using WebDoorCreator.UI.Shared;
using WebDoorCreator.Data.DbModels;
using WebDoorCreator.UI.Data;
using Microsoft.AspNetCore.Identity;
namespace WebDoorCreator.UI.Pages
{
public partial class OrdersHomePage
{
#region Protected Properties
[Inject]
protected WebDoorCreatorService WDService { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
protected UserManager<IdentityUser> _userManager { get; set; } = null!;
[Inject]
protected NavigationManager NavManager { get; set; } = null!;
[Parameter]
public EventCallback<AspNetUsers> E_currUser { get; set; }
#endregion Protected Properties
#region Private Fields
protected string _orderCodExt = "";
protected string orderCodExt
{
get => _orderCodExt;
set => _orderCodExt = value;
}
protected string _orderDescr = "";
protected string orderDescr
{
get => _orderDescr;
set => _orderDescr = value;
}
private List<CompanyModel>? ListRecords = null;
#endregion Private Fields
#region Private Methods
protected List<UsersViewModel>? UsersList { get; set; } = null;
protected List<AspNetRoles>? RolesList { get; set; } = null;
protected AspNetUsers? currUser { get; set; } = null;
protected bool isModRole { get; set; } = false;
protected async Task addNewOrder(string userName)
{
var user = await _userManager.FindByNameAsync(userName);
OrderModel addRec = new OrderModel()
{
CompanyId = 2,
OrderExtCode = orderCodExt,
DateIns = DateTime.Now,
UserIdIns = user.Id,
DateMod = DateTime.Now,
UserIdMod = user.Id,
Status = Core.Enum.OrderStatus.DoorDef,
OrderDescript = orderDescr
};
var done = await WDService.OrderAdd(addRec);
if(done)
{
NavManager.NavigateTo(NavManager.Uri, true);
}
}
#endregion Private Methods
}
}