Ok salvataggio su template

This commit is contained in:
Samuele Locatelli
2023-06-01 12:16:00 +02:00
parent 39d8bf85b9
commit 40cf14c77b
10 changed files with 280 additions and 179 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>WebDoorCreator - Egalware</i>
<h4>Version: 0.9.2306.0111</h4>
<h4>Version: 0.9.2306.0112</h4>
<br /> Release note:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
0.9.2306.0111
0.9.2306.0112
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>0.9.2306.0111</version>
<version>0.9.2306.0112</version>
<url>http://nexus.steamware.net/repository/SWS/WDC/stable/WDC.UI.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/WDC/stable/ChangeLog.html</changelog>
<mandatory>false</mandatory>
@@ -195,6 +195,36 @@ namespace WebDoorCreator.Data.Controllers
return fatto;
}
/// <summary>
/// Getting door data by key
/// </summary>
/// <returns></returns>
public DoorModel? DoorGetByKey(int doorId)
{
DoorModel? dbResult = new DoorModel();
// retrieving data from db
using (WDCDataContext localDbCtx = new WDCDataContext(_configuration))
{
try
{
// extracting entire set
dbResult = localDbCtx
.DbSetDoor
.Where(x => x.DoorId == doorId)
.Include(o => o.OrderNav)
.Include(t => t.TypeNav)
.OrderBy(x => x.DoorId)
.AsNoTracking()
.FirstOrDefault();
}
catch (Exception exc)
{
Log.Error($"Error in DoorGetByKey:{Environment.NewLine}{exc}");
}
}
return dbResult;
}
/// <summary>
/// Adding a new door
/// </summary>
@@ -823,6 +853,31 @@ namespace WebDoorCreator.Data.Controllers
return fatto;
}
public List<OrderModel> OrderGetByCompStatus(int CompanyId, int StatusId)
{
List<OrderModel> dbResult = new List<OrderModel>();
using (var dbCtx = new WDCDataContext(_configuration))
{
try
{
var rawData = dbCtx
.DbSetOrders
.Where(x => x.CompanyId == CompanyId && x.Status == StatusId)
.AsNoTracking()
.ToList();
if (rawData != null)
{
dbResult = rawData;
}
}
catch (Exception exc)
{
Log.Error($"Error in OrderGetByCompStatus:{Environment.NewLine}{exc}");
}
}
return dbResult;
}
public OrderModel OrderGetByKey(int orderId)
{
OrderModel dbResult = new OrderModel();
@@ -848,31 +903,6 @@ namespace WebDoorCreator.Data.Controllers
return dbResult;
}
public List<OrderModel> OrderGetByCompStatus(int CompanyId, int StatusId)
{
List<OrderModel> dbResult = new List<OrderModel>();
using (var dbCtx = new WDCDataContext(_configuration))
{
try
{
var rawData = dbCtx
.DbSetOrders
.Where(x => x.CompanyId == CompanyId && x.Status==StatusId)
.AsNoTracking()
.ToList();
if (rawData != null)
{
dbResult = rawData;
}
}
catch (Exception exc)
{
Log.Error($"Error in OrderGetByCompStatus:{Environment.NewLine}{exc}");
}
}
return dbResult;
}
/// <summary>
/// Remove order
/// </summary>
+7 -6
View File
@@ -156,9 +156,10 @@ namespace WebDoorCreator.Data.DbModels
/// <summary>
/// Clone oggetto
/// </summary>
/// <param name="userId"></param>
/// <param name="userName"></param>
/// <param name="doorId"></param>
/// <returns></returns>
public DoorOpModel ObjClone(string userId, int doorId)
public DoorOpModel ObjClone(string userName, int doorId)
{
DoorOpModel answ = new DoorOpModel();
DateTime adesso = DateTime.Now;
@@ -168,8 +169,8 @@ namespace WebDoorCreator.Data.DbModels
{
DateIns = adesso,
DateMod = adesso,
UserIdIns = userId,
UserIdMod = userId,
UserIdIns = userName,
UserIdMod = userName,
ObjectId = ObjectId,
DoorId = DoorId,
JsoncConfigVal = JsoncConfigVal,
@@ -184,8 +185,8 @@ namespace WebDoorCreator.Data.DbModels
{
DateIns = adesso,
DateMod = adesso,
UserIdIns = userId,
UserIdMod = userId,
UserIdIns = userName,
UserIdMod = userName,
ObjectId = ObjectId,
DoorId = doorId,
JsoncConfigVal = JsoncConfigVal,
@@ -963,6 +963,54 @@ namespace WebDoorCreator.Data.Services
return SteamCrypto.DecryptString(encData, Constants.passPhrase);
}
/// <summary>
/// Clone a copy of the door in the specified order
/// </summary>
/// <param name="doorId">Record id to edit or add</param>
/// <param name="orderId">Destination order where door must be placed</param>
/// <param name="userName">userName for cloning</param>
/// <returns></returns>
public async Task<bool> DoorCloneToOrder(int doorId, int orderId, string userName)
{
var dbResult = false;
int newDoorId = 0;
var doorOps2Add = new List<DoorOpModel>();
var CurrDoor = await DoorGetByKey(doorId);
var DoorOpsList = await DoorOpGetByDoorId(doorId);
if (DoorOpsList != null)
{
var doorOps2Clone = DoorOpsList?.Where(x => x.DoorId == doorId).ToList();
var door2Clone = CurrDoor;
if (door2Clone != null)
{
var doorToAdd = door2Clone.ObjClone(userName);
// imposto ordine per la porta...
doorToAdd.OrderId = orderId;
// salvo!
newDoorId = await DoorInsert(doorToAdd);
if (newDoorId != 0 && doorOps2Clone != null)
{
foreach (var item in doorOps2Clone)
{
var doorOp2Add = item.ObjClone(userName, newDoorId);
doorOps2Add.Add(doorOp2Add);
}
// salvo!
dbResult = await DoorOpInsert(newDoorId, doorOps2Add);
}
}
}
// await dbController.DoorModQty(NewQty, doorId, isAdd); svuoto cache
await DoorFlushCache(doorId);
await DoorOpFlushCache(doorId);
await OrderDetailFlushCache(orderId);
await OrdersFlushCache();
return dbResult;
}
/// <summary>
/// CElimina record posta
/// </summary>
@@ -998,6 +1046,47 @@ namespace WebDoorCreator.Data.Services
return answ;
}
/// <summary>
/// Doors key (DoorId)
/// </summary>
public async Task<DoorModel?> DoorGetByKey(int doorId)
{
string source = "DB";
DoorModel? dbResult = new DoorModel();
// cerco da cache
string currKey = $"{Constants.rKeyDoor}:Single:{doorId}";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<DoorModel>(rawData);
if (tempResult == null)
{
dbResult = new DoorModel();
}
else
{
dbResult = tempResult;
}
}
else
{
dbResult = dbController.DoorGetByKey(doorId);
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
if (dbResult == null)
{
dbResult = new DoorModel();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"DoorGetByKey | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
/// <summary>
/// Doors list by numRec
/// </summary>
@@ -1094,24 +1183,6 @@ namespace WebDoorCreator.Data.Services
return dbResult;
}
/// <summary>
/// Clone a copy of the door in the specified order
/// </summary>
/// <param name="DoorId">Record id to edit or add</param>
/// <param name="OrderId">Destination order where door must be placed</param>
/// <returns></returns>
public async Task<bool> DoorCloneToOrder(int DoorId, int OrderId)
{
var dbResult = false;// await dbController.DoorModQty(NewQty, DoorId, isAdd);
// svuoto cache
await DoorFlushCache(DoorId);
await DoorOpFlushCache(DoorId);
await OrderDetailFlushCache(OrderId);
await OrdersFlushCache();
return dbResult;
}
/// <summary>
/// Adding or removing a single door
/// </summary>
@@ -1243,7 +1314,7 @@ namespace WebDoorCreator.Data.Services
}
/// <summary>
/// Create DDF from DoorId
/// Create DDF from doorId
/// </summary>
public async Task<string> DoorOpGetDDF(int DoorId)
{
@@ -1804,6 +1875,22 @@ namespace WebDoorCreator.Data.Services
return dbResult;
}
/// <summary>
/// Clean REDIS order detail data in cache
/// </summary>
/// <param name="OrderId">0 = all</param>
/// <returns></returns>
public async Task<bool> OrderDetailFlushCache(int OrderId)
{
RedisValue pattern = new RedisValue($"{Constants.rKeyDoorsByOrder}:*");
if (OrderId > 0)
{
pattern = new RedisValue($"{Constants.rKeyDoorsByOrder}:{OrderId}");
}
bool answ = await ExecFlushRedisPattern(pattern);
return answ;
}
/// <summary>
/// Order (content) cloning
/// </summary>
@@ -1820,20 +1907,43 @@ namespace WebDoorCreator.Data.Services
return dbResult;
}
/// <summary>
/// Clean REDIS order detail data in cache
/// </summary>
/// <param name="OrderId">0 = all</param>
/// <returns></returns>
public async Task<bool> OrderDetailFlushCache(int OrderId)
public async Task<List<OrderModel>?> OrderGetByCompStatus(int CompanyId, int StatusId)
{
RedisValue pattern = new RedisValue($"{Constants.rKeyDoorsByOrder}:*");
if (OrderId > 0)
string source = "DB";
List<OrderModel>? dbResult = new List<OrderModel>();
// cerco da cache
string currKey = $"{Constants.rKeyOrderByComp}:{CompanyId}:{StatusId}"; ;
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
pattern = new RedisValue($"{Constants.rKeyDoorsByOrder}:{OrderId}");
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<List<OrderModel>>(rawData);
if (tempResult == null)
{
dbResult = new List<OrderModel>();
}
else
{
dbResult = tempResult;
}
}
bool answ = await ExecFlushRedisPattern(pattern);
return answ;
else
{
dbResult = dbController.OrderGetByCompStatus(CompanyId, StatusId);
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
if (dbResult == null)
{
dbResult = new List<OrderModel>();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"OrderGetByCompStatus | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
public async Task<OrderModel?> OrderGetByKey(int orderId)
@@ -1875,46 +1985,6 @@ namespace WebDoorCreator.Data.Services
return dbResult;
}
public async Task<List<OrderModel>?> OrderGetByCompStatus(int CompanyId, int StatusId)
{
string source = "DB";
List<OrderModel>? dbResult = new List<OrderModel>();
// cerco da cache
string currKey = $"{Constants.rKeyOrderByComp}:{CompanyId}:{StatusId}"; ;
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<List<OrderModel>>(rawData);
if (tempResult == null)
{
dbResult = new List<OrderModel>();
}
else
{
dbResult = tempResult;
}
}
else
{
dbResult = dbController.OrderGetByCompStatus(CompanyId, StatusId);
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
if (dbResult == null)
{
dbResult = new List<OrderModel>();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"OrderGetByCompStatus | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
/// <summary>
/// Remove order
/// </summary>
@@ -1994,7 +2064,7 @@ namespace WebDoorCreator.Data.Services
{
var dbResult = await dbController.OrderUpdate(orderId, newStatus);
// elimino cache redis...
//bool answ = await DoorFlushCache(currRec.DoorId);
//bool answ = await DoorFlushCache(currRec.doorId);
// elimino cache redis dati ordine...
bool answ = await FlushRedisCache();
return dbResult;
@@ -2307,18 +2377,20 @@ namespace WebDoorCreator.Data.Services
Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
public async Task<Dictionary<string, Dictionary<string, string>>?> VocLemmaTEMPGetAll()
public async Task<bool> VocLemmaInsert()
{
string source = "DB";
Dictionary<string, Dictionary<string, string>>? dbResult = new Dictionary<string, Dictionary<string, string>>();
// cerco da cache
bool fatto = false;
List<VocabularyTempModel> VocLemmas = new List<VocabularyTempModel>();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = dbController.VocLemmaTEMPGetAll();
fatto = await dbController.VocLemmaInsert();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
Log.Debug($"VocLemmaInsert in: {ts.TotalMilliseconds} ms");
return fatto;
}
public async Task<List<VocabularyTempModel>> VocLemmaInsertPrepare(string rootPath)
@@ -2367,21 +2439,18 @@ namespace WebDoorCreator.Data.Services
return VocLemmas;
}
public async Task<bool> VocLemmaInsert()
public async Task<Dictionary<string, Dictionary<string, string>>?> VocLemmaTEMPGetAll()
{
bool fatto = false;
List<VocabularyTempModel> VocLemmas = new List<VocabularyTempModel>();
string source = "DB";
Dictionary<string, Dictionary<string, string>>? dbResult = new Dictionary<string, Dictionary<string, string>>();
// cerco da cache
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
fatto = await dbController.VocLemmaInsert();
dbResult = dbController.VocLemmaTEMPGetAll();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"VocLemmaInsert in: {ts.TotalMilliseconds} ms");
return fatto;
Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
#endregion Public Methods
@@ -9,17 +9,15 @@ namespace WebDoorCreator.UI.Components.DoorMan
{
public partial class DoorModal
{
protected List<DoorOpModel> doorOps2Add = new List<DoorOpModel>();
#region Public Properties
public DoorModel CurrDoor { get; set; } = new DoorModel();
public DoorModel CurrDoorClone { get; set; } = new DoorModel();
[Parameter]
public int CurrDoorId { get; set; } = 0;
public List<DoorModel> DoorsList { get; set; } = new List<DoorModel>();
public List<OrderModel> OrdersCompList { get; set; } = new List<OrderModel>();
[Parameter]
public EventCallback<DoorModel> E_DoorClose { get; set; }
@@ -30,8 +28,22 @@ namespace WebDoorCreator.UI.Components.DoorMan
[Parameter]
public int OrderId { get; set; } = 0;
public List<OrderModel> OrdersCompList { get; set; } = new List<OrderModel>();
[Parameter]
public string userId { get; set; } = "";
public string UserName { get; set; } = "";
#endregion Public Properties
#region Protected Fields
protected List<DoorOpModel> doorOps2Add = new List<DoorOpModel>();
protected bool SaveOnTemplate = false;
#endregion Protected Fields
#region Protected Properties
[Inject]
protected IConfiguration config { get; set; } = null!;
@@ -54,14 +66,12 @@ namespace WebDoorCreator.UI.Components.DoorMan
protected int newDoorId { get; set; } = 0;
protected int OrderIdTplSel { get; set; } = 0;
protected List<string> ordListVal { get; set; } = new List<string>();
[Inject]
protected QueueDataService QDataServ { get; set; } = null!;
[Inject]
protected WebDoorCreatorService WDService { get; set; } = null!;
protected int userCurrCompany
{
get => WDCUService.userCurrComp;
@@ -75,6 +85,13 @@ namespace WebDoorCreator.UI.Components.DoorMan
[Inject]
protected WDCUserService WDCUService { get; set; } = null!;
[Inject]
protected WebDoorCreatorService WDService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected async Task addOrRemoveOneDoorNumber(bool isAdd)
{
//var door = new DoorModel();
@@ -128,6 +145,14 @@ namespace WebDoorCreator.UI.Components.DoorMan
/// <returns></returns>
protected async Task doClone()
{
var cloned = await WDService.DoorCloneToOrder(CurrDoor.DoorId, CurrDoor.OrderId, UserName);
if (cloned)
{
await doSave();
await closeModal();
}
#if false
var DoorOpsList = await WDService.DoorOpGetByDoorId(CurrDoorId);
if (DoorOpsList != null)
{
@@ -158,51 +183,9 @@ namespace WebDoorCreator.UI.Components.DoorMan
}
}
}
#endif
}
/// <summary>
/// Clona la porta selezionata con annesse door operations nel template selezionato...
/// </summary>
/// <returns></returns>
protected async Task doSaveTemplate()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Are you sure? this operation will copy current door to selected template order?"))
return;
var DoorOpsList = await WDService.DoorOpGetByDoorId(CurrDoorId);
if (DoorOpsList != null)
{
var doorOps2Clone = DoorOpsList?.Where(x => x.DoorId == CurrDoorId).ToList();
var door2Clone = CurrDoor;
if (door2Clone != null)
{
var doorToAdd = door2Clone.ObjClone(userId);
// salvo!
newDoorId = await WDService.DoorInsert(doorToAdd);
if (newDoorId != 0 && doorOps2Clone != null)
{
foreach (var item in doorOps2Clone)
{
var doorOp2Add = item.ObjClone(userId, newDoorId);
doorOps2Add.Add(doorOp2Add);
}
// salvo!
var done = await WDService.DoorOpInsert(newDoorId, doorOps2Add);
if (done)
{
await doSave();
await closeModal();
}
}
}
}
}
protected bool SaveOnTemplate = false;
/// <summary>
/// Effettua salvataggio record e generazione DDF
/// </summary>
@@ -229,8 +212,8 @@ namespace WebDoorCreator.UI.Components.DoorMan
listOp = listOp.OrderBy(d => ordListVal.IndexOf(d.ObjectId)).ToList();
string currDdf = currDdfConv.GetSerialized(listOp);
// FIXME TODO: si potrebbe eliminare in futuro che va su REDIS
// versione corrente del DDF generato
// FIXME TODO: si potrebbe eliminare in futuro che va su REDIS versione corrente
// del DDF generato
int currVers = await QDataServ.SendCalcReq(newDoorId, currDdf);
if (currVers > 0)
@@ -241,6 +224,24 @@ namespace WebDoorCreator.UI.Components.DoorMan
}
}
/// <summary>
/// Clona la porta selezionata con annesse door operations nel template selezionato...
/// </summary>
/// <returns></returns>
protected async Task doSaveTemplate()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Are you sure? this operation will copy current door to selected template order?"))
return;
// prendo ord templ dest...
var cloned = await WDService.DoorCloneToOrder(CurrDoor.DoorId, OrderIdTplSel, UserName);
if (cloned)
{
await doSave();
await closeModal();
}
}
protected override async Task OnInitializedAsync()
{
await Task.Delay(1);
@@ -250,6 +251,7 @@ namespace WebDoorCreator.UI.Components.DoorMan
var footRows = config.GetSection("ConfDDF:Footer").Get<List<string>>();
currDdfConv = new WebDoorCreator.Data.DDF.Converter(vers, remDoorOp, headRows, footRows);
}
protected override async Task OnParametersSetAsync()
{
await Task.Delay(1);
@@ -308,7 +310,6 @@ namespace WebDoorCreator.UI.Components.DoorMan
}
}
protected int OrderIdTplSel { get; set; } = 0;
#endregion Protected Methods
}
}
+1 -1
View File
@@ -157,7 +157,7 @@
@if (currDoorModal != null && currDoorModal.DoorId != 0)
{
<DoorModal userId="@userId" E_DoorClose="@SetCurrDoorModal" OrderId="@currDoorModal.OrderId" CurrDoorId="@currDoorModal.DoorId"></DoorModal>
<DoorModal UserName="@userId" E_DoorClose="@SetCurrDoorModal" OrderId="@currDoorModal.OrderId" CurrDoorId="@currDoorModal.DoorId"></DoorModal>
}
@if (newOrdReq)
{
+1 -1
View File
@@ -200,7 +200,7 @@ namespace WebDoorCreator.UI.Pages
// var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
// code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
// var callbackUrl = $"/Account/ConfirmEmail?userId{user.Id}&code{code}&returnUrl=~/";
// var callbackUrl = $"/Account/ConfirmEmail?UserName{user.Id}&code{code}&returnUrl=~/";
// await _emailSender.SendEmailAsync(email, "Web Door Creator: Please confirm your email account",
// $"<a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>Click here</a> to confirm the account linked with this email.");
+1 -1
View File
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>0.9.2306.0111</Version>
<Version>0.9.2306.0112</Version>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-WebDoorCreator.UI-dfe95fed-1398-4144-bd43-8b3a765d6608</UserSecretsId>
</PropertyGroup>