This commit is contained in:
Adam 2025-09-23 12:21:01 +02:00
commit 7559c715c2
18 changed files with 152 additions and 107 deletions

View File

@ -1,4 +1,5 @@
using FruitBank.Common.Loggers;
using Mango.Nop.Core.Loggers;
namespace FruitBank.Common.Server.Services.Loggers;

View File

@ -4,6 +4,7 @@ using AyCode.Services.SignalRs;
using FruitBank.Common.Interfaces;
using FruitBank.Common.Loggers;
using FruitBank.Common.SignalRs;
using Mango.Nop.Core.Loggers;
using Microsoft.Extensions.Configuration;
namespace FruitBank.Common.Server.Services.SignalRs;

View File

@ -16,7 +16,7 @@ public class Partner : MgEntityBase, IPartner
public string City { get; set; }
public string Street { get; set; }
[Association(ThisKey = nameof(Id), OtherKey = nameof(ShippingDocument.ShippingId))]
[Association(ThisKey = nameof(Id), OtherKey = nameof(ShippingDocument.ShippingId), CanBeNull = true)]
public List<ShippingDocument>? ShippingDocuments { get; set; }

View File

@ -13,7 +13,7 @@ public class Shipping : MgEntityBase, IShipping
public string LicencePlate { get; set; }
public bool IsAllMeasured { get; set; }
[Association(ThisKey = nameof(Id), OtherKey = nameof(ShippingDocument.ShippingId))]
[Association(ThisKey = nameof(Id), OtherKey = nameof(ShippingDocument.ShippingId), CanBeNull = true)]
public List<ShippingDocument>? ShippingDocuments { get; set; }

View File

@ -14,13 +14,13 @@ public class ShippingDocument : MgEntityBase, IShippingDocument
public string Country { get; set; }
public bool IsAllMeasured { get; set; }
[Association(ThisKey = nameof(ShippingId), OtherKey = nameof(Shipping.Id))]
[Association(ThisKey = nameof(ShippingId), OtherKey = nameof(Shipping.Id), CanBeNull = true)]
public Shipping? Shipping{ get; set; }
[Association(ThisKey = nameof(PartnerId), OtherKey = nameof(Partner.Id))]
[Association(ThisKey = nameof(PartnerId), OtherKey = nameof(Partner.Id), CanBeNull = true)]
public Partner? Partner { get; set; }
[Association(ThisKey = nameof(Id), OtherKey = nameof(ShippingItem.ShippingDocumentId))]
[Association(ThisKey = nameof(Id), OtherKey = nameof(ShippingItem.ShippingDocumentId), CanBeNull = true)]
public List<ShippingItem>? ShippingItems { get; set; }

View File

@ -6,6 +6,7 @@ using Mango.Nop.Core.Entities;
using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Orders;
using System.ComponentModel.DataAnnotations;
using Nop.Core.Domain.Catalog;
using DataType = LinqToDB.DataType;
namespace FruitBank.Common.Entities;
@ -20,28 +21,42 @@ public class ShippingItem : MgEntityBase, IShippingItem
public int ShippingDocumentId { get; set; }
public string Name { get; set; }
[Column(DataType = DataType.DecFloat)]
public double NetWeight { get; set; }
[Column(DataType = DataType.DecFloat)]
public double GrossWeight { get; set; }
public int Quantity { get; set; }
[Column(DataType = DataType.DecFloat)] public double NetWeight { get; set; }
[Column(DataType = DataType.DecFloat)] public double GrossWeight { get; set; }
[Nullable]
[Column(CanBeNull = true)]
[Range(1, 100000, ErrorMessage = "The MeasuredQuantity value should be a number between 1 and 100,000.")]
public int? MeasuredQuantity { get; set; }
[Nullable]
[Column(DataType = DataType.DecFloat, CanBeNull = true)]
[Required]
[Range(1, 100000, ErrorMessage = "The MeasuredNetWeight value should be a number between 1 and 100,000.")]
public double? MeasuredNetWeight { get; set; }
[Nullable]
[Column(DataType = DataType.DecFloat, CanBeNull = true)]
[Required]
[Range(1, 100000, ErrorMessage = "The MeasuredGrossWeight value should be a number between 1 and 100,000.")]
public double? MeasuredGrossWeight { get; set; }
public bool IsMeasurable { get; set; }
public bool IsMeasured { get; set; }
[LinqToDB.Mapping.Association(ThisKey = nameof(ShippingDocumentId), OtherKey = nameof(ShippingDocument.Id))]
[LinqToDB.Mapping.Association(ThisKey = nameof(ProductId), OtherKey = nameof(Product.Id), CanBeNull = true)]
public Product? Product { get; set; }
[LinqToDB.Mapping.Association(ThisKey = nameof(ShippingDocumentId), OtherKey = nameof(ShippingDocument.Id), CanBeNull = true)]
public ShippingDocument? ShippingDocument { get; set; }
[SkipValuesOnUpdate]
public DateTime Created { get; set; }
[SkipValuesOnUpdate] public DateTime Created { get; set; }
public DateTime Modified { get; set; }
public bool IsValidMeasuringValues()
{
return /*ProductId > 0 && */MeasuredQuantity > 0 && (!IsMeasurable || (MeasuredNetWeight > 0 && MeasuredGrossWeight > 0));
}
}

View File

@ -27,6 +27,7 @@ public interface IFruitBankDataControllerCommon
public Task<List<ShippingItem>?> GetShippingItems();
public Task<ShippingItem?> GetShippingItemById(int id);
public Task<ShippingItem?> UpdateShippingItem(ShippingItem shippingItem);
public Task<ShippingItem?> UpdateMeasuredShippingItem(ShippingItem shippingItem);
#endregion ShippingItem
#region ShippingDocument

View File

@ -13,5 +13,6 @@ public interface IShippingDocument: IEntityInt, ITimeStampInfo
public bool IsAllMeasured { get; set; }
public Partner? Partner { get; set; }
public Shipping? Shipping{ get; set; }
public List<ShippingItem>? ShippingItems { get; set; }
}

View File

@ -1,5 +1,7 @@
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.TimeStampInfo;
using FruitBank.Common.Entities;
using Nop.Core.Domain.Catalog;
namespace FruitBank.Common.Interfaces;
@ -9,10 +11,19 @@ public interface IShippingItem : IEntityInt, ITimeStampInfo
int? ProductId { get; set; }
string Name { get; set; }
int Quantity { get; set; }
double NetWeight { get; set; }
double GrossWeight { get; set; }
int? MeasuredQuantity { get; set; }
double? MeasuredNetWeight { get; set; }
double? MeasuredGrossWeight { get; set; }
bool IsMeasurable { get; set; }
bool IsMeasured { get; set; }
public Product? Product { get; set; }
public ShippingDocument? ShippingDocument { get; set; }
public bool IsValidMeasuringValues();
}

View File

@ -1,12 +0,0 @@
using AyCode.Core.Loggers;
namespace FruitBank.Common.Loggers;
public interface ILogger<TCategory> : ILogger
{
}
public interface ILogger : IAcLoggerBase
{
}

View File

@ -1,32 +0,0 @@
using AyCode.Core.Enums;
using AyCode.Core.Loggers;
namespace FruitBank.Common.Loggers;
public class Logger<TCategory> : Logger, ILogger<TCategory>
{
public Logger() : base(typeof(TCategory).Name)
{ }
public Logger(params IAcLogWriterBase[] logWriters) : base(typeof(TCategory).Name, logWriters)
{ }
public Logger(AppType appType, LogLevel logLevel, params IAcLogWriterBase[] logWriters) : base(appType, logLevel, typeof(TCategory).Name, logWriters)
{ }
}
public class Logger : AcLoggerBase, ILogger
{
public Logger() : this(null)
{
}
public Logger(string? categoryName) : base(categoryName)
{ }
public Logger(string? categoryName, params IAcLogWriterBase[] logWriters) : base(categoryName, logWriters)
{ }
public Logger(AppType appType, LogLevel logLevel, string? categoryName, params IAcLogWriterBase[] logWriters) : base(appType, logLevel, categoryName, logWriters)
{ }
}

View File

@ -24,6 +24,7 @@ public class SignalRTags : AcSignalRTags
public const int GetShippingItemById = 51;
public const int AddShippingItem = 55;
public const int UpdateShippingItem = 56;
public const int UpdateMeasuredShippingItem = 57;
public const int GetShippingDocuments = 60;
public const int GetShippingDocumentById = 61;

View File

@ -2,8 +2,10 @@
using AyCode.Core.Loggers;
using AyCode.Utils.Extensions;
using FruitBank.Common.Entities;
using FruitBank.Common.Interfaces;
using FruitBank.Common.Loggers;
using FruitBankHybrid.Shared.Services.SignalRs;
using System.Diagnostics.CodeAnalysis;
namespace FruitBankHybrid.Shared.Tests
{
@ -133,16 +135,22 @@ namespace FruitBankHybrid.Shared.Tests
Assert.IsNotNull(shippingItems);
Assert.IsTrue(shippingItems.Count != 0);
Assert.IsTrue(shippingItems.All(si=>si.Product?.Id == si.ProductId), "shippingItem.Product == null");
}
//[TestMethod]
//[DataRow(1)]
public async Task<ShippingItem> GetShippingItemByIdTest(int shippingItemeId)
[return: NotNull]
public async Task<ShippingItem> GetShippingItemByIdTest(int shippingItemId)
{
var shippingItem = await _signalRClient.GetShippingItemById(shippingItemeId);
var shippingItem = await _signalRClient.GetShippingItemById(shippingItemId);
Assert.IsNotNull(shippingItem);
Assert.IsTrue(shippingItem.Id == shippingItemeId);
Assert.IsNotNull(shippingItem.Product, $"shippingItem.Product == null; shippingItem.Id: {shippingItem.ProductId}");
Assert.IsTrue(shippingItem.Id == shippingItemId);
Assert.IsTrue(shippingItem.Quantity > 0, "Quantity == 0");
Assert.IsTrue(shippingItem.NetWeight > 0, "NetWeight == 0");
Assert.IsTrue(shippingItem.GrossWeight > 0, "GrossWeight == 0");
@ -151,21 +159,38 @@ namespace FruitBankHybrid.Shared.Tests
[DataTestMethod]
[DataRow(1)]
//[DataRow(2)]
public async Task UpdateShippingItemTest(int shippingItemId)
{
var shippingItem = await GetShippingItemByIdTest(shippingItemId);
var newName = GetFixtureName(shippingItem.Name);
var originalShippingItem = await GetShippingItemByIdTest(shippingItemId);
var newName = GetFixtureName(originalShippingItem.Name);
var shippingItem = await GetShippingItemByIdTest(shippingItemId);
shippingItem.Name = newName;
//shippingItem.MeasuredGrossWeight = 5;
await _signalRClient.UpdateShippingItem(shippingItem);
shippingItem = await _signalRClient.UpdateShippingItem(shippingItem);
Assert.IsNotNull(shippingItem);
Assert.IsNotNull(shippingItem.Product);
Assert.IsTrue(shippingItem.Name == newName);
Assert.IsTrue(shippingItem.Product.StockQuantity == originalShippingItem.Product!.StockQuantity);
shippingItem = await GetShippingItemByIdTest(shippingItemId);
Assert.IsTrue(shippingItem.Name == newName);
Assert.IsTrue(shippingItem.Product!.StockQuantity == originalShippingItem.Product.StockQuantity);
//Assert.IsTrue(shippingItem.MeasuredGrossWeight is 5);
shippingItem.Name = GetOriginalName(shippingItem.Name);
await _signalRClient.UpdateShippingItem(shippingItem);
shippingItem = await _signalRClient.UpdateShippingItem(shippingItem);
Assert.IsNotNull(shippingItem);
Assert.IsNotNull(shippingItem.Product);
shippingItem = await GetShippingItemByIdTest(shippingItemId);
Assert.IsTrue(shippingItem.Name == originalShippingItem.Name);
Assert.IsTrue(shippingItem.Product!.StockQuantity == originalShippingItem.Product.StockQuantity);
}
#endregion ShippingItem

View File

@ -6,6 +6,7 @@ using FruitBank.Common.Loggers;
using FruitBankHybrid.Shared.Services.Loggers;
using FruitBankHybrid.Shared.Services.SignalRs;
using Mango.Nop.Core.Dtos;
using Mango.Nop.Core.Loggers;
using Mango.Nop.Core.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;

View File

@ -100,19 +100,36 @@
<EditForm Model="@SelectedShippingItem" Context="FrmContext"
OnValidSubmit="@HandleValidSubmit"
OnInvalidSubmit="@HandleInvalidSubmit">
<DataAnnotationsValidator />
@* <DataAnnotationsValidator /> *@
<DxFormLayout Data="@SelectedShippingItem" CaptionPosition="CaptionPosition.Vertical" CssClass="w-100" ItemUpdating="@((pair) => OnItemUpdating(pair.Key, pair.Value))">
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")" Field="@nameof(ShippingItem.Name)" Caption="Item Name:" Enabled="false" ColSpanMd="6" />
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")" Field="@nameof(ShippingItem.GrossWeight)" Caption="GrossWeight:" Enabled="false" ColSpanMd="3" />
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")" Field="@nameof(ShippingItem.NetWeight)" Caption="NetWeight:" Enabled="false" ColSpanMd="3" />
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")" Field="@nameof(ShippingItem.MeasuredGrossWeight)" Caption="MeasuredGrossWeight:" ColSpanMd="3" BeginRow="true">
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")"
Field="@nameof(ShippingItem.MeasuredQuantity)"
Caption="MeasuredQuantity:"
ColSpanMd="2"
BeginRow="true">
</DxFormLayoutItem>
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")" Field="@nameof(ShippingItem.MeasuredNetWeight)" Caption="MeasuredNetWeight:" ColSpanMd="3">
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")"
Field="@nameof(ShippingItem.MeasuredGrossWeight)"
Enabled="@(SelectedShippingItem.IsMeasurable)"
Caption="MeasuredGrossWeight:"
ColSpanMd="2">
</DxFormLayoutItem>
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")" Field="@nameof(ShippingItem.IsMeasured)" Enabled="false" Caption="Sikeres mérés:" ColSpanMd="6">
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")"
Field="@nameof(ShippingItem.MeasuredNetWeight)"
Enabled="@(SelectedShippingItem.IsMeasurable)"
Caption="MeasuredNetWeight:"
ColSpanMd="2">
</DxFormLayoutItem>
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")"
Field="@nameof(ShippingItem.IsMeasured)"
Enabled="false" Caption="Sikeres mérés:" ColSpanMd="6">
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="12" BeginRow="true">

View File

@ -1,37 +1,23 @@
using AyCode.Core.Helpers;
using AyCode.Core.Loggers;
using AyCode.Models.Users;
using AyCode.Core.Loggers;
using DevExpress.Blazor;
using FruitBank.Common.Entities;
using FruitBank.Common.Loggers;
using FruitBank.Common.Models;
using FruitBankHybrid.Shared.Services.Loggers;
using FruitBankHybrid.Shared.Services.SignalRs;
using Mango.Nop.Core.Dtos;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Logging;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using DevExpress.Data.Mask.Internal;
using Microsoft.AspNetCore.Components.Forms;
using static System.Net.Mime.MediaTypeNames;
using static System.Runtime.InteropServices.JavaScript.JSType;
using ILogger = FruitBank.Common.Loggers.ILogger;
using ILogger = Mango.Nop.Core.Loggers.ILogger;
namespace FruitBankHybrid.Shared.Pages
{
public class ShippingDateModel
{
public int ShippingId { get; set; }
public DateTime DateTime { get; set; }
public bool IsMeasured { get; set; }
public ShippingDateModel(DateTime dateTime, bool isMeasured)
public ShippingDateModel(int shippingId, DateTime dateTime, bool isMeasured)
{
ShippingId = shippingId;
DateTime = dateTime;
IsMeasured = isMeasured;
}
@ -70,8 +56,8 @@ namespace FruitBankHybrid.Shared.Pages
{
var shippings = await FruitBankSignalRClient.GetShippings() ?? [];
_shippingDates = shippings.Select(x => new ShippingDateModel(x.ShippingDate.Date, x.IsAllMeasured)).ToList();
NotMeasuredShippings = shippings.Where(x => DaysEqual(x.ShippingDate.Date, dateTime)).ToList();
_shippingDates = shippings.Select(shipping => new ShippingDateModel(shipping.Id, shipping.ShippingDate.Date, shipping.IsAllMeasured)).ToList();
NotMeasuredShippings = shippings.Where(shipping => DaysEqual(shipping.ShippingDate.Date, dateTime)).ToList();
//if (getAllShipping) NotMeasuredShippings = await FruitBankSignalRClient.GetShippings() ?? [];
//else NotMeasuredShippings = await FruitBankSignalRClient.GetNotMeasuredShippings() ?? [];
@ -135,10 +121,23 @@ namespace FruitBankHybrid.Shared.Pages
{
if (SelectedShippingItem == null || shippingItemFromDb == null) return;
SelectedShippingItem.MeasuredQuantity = shippingItemFromDb.MeasuredQuantity;
SelectedShippingItem.MeasuredNetWeight = shippingItemFromDb.MeasuredNetWeight;
SelectedShippingItem.MeasuredGrossWeight = shippingItemFromDb.MeasuredGrossWeight;
SelectedShippingItem.IsMeasured = shippingItemFromDb.IsMeasured;
if (SelectedShippingDocument != null)
SelectedShippingDocument.IsAllMeasured = SelectedShippingDocument.ShippingItems?.All(si => si.IsMeasured) ?? false;
if (SelectedShipping != null)
{
SelectedShipping.IsAllMeasured = SelectedShipping.ShippingDocuments?.All(sd => sd.IsAllMeasured) ?? false;
var shippingDate = _shippingDates.FirstOrDefault(shipping => shipping.ShippingId == SelectedShipping.Id);
if (shippingDate != null) shippingDate.IsMeasured = SelectedShipping.IsAllMeasured;
}
//if (SelectedShippingItem is { IsMeasured: true })
//{
// SelectedShippingDocument?.ShippingItems?.Remove(SelectedShippingItem);
@ -150,12 +149,20 @@ namespace FruitBankHybrid.Shared.Pages
private async Task UpdateShippingItem(ShippingItem? shippingItem)
{
if (shippingItem is { MeasuredGrossWeight: > 0, MeasuredNetWeight: > 0 })
if (shippingItem != null && shippingItem.IsValidMeasuringValues())
{
BtnSaveEnabled = false;
shippingItem.IsMeasured = shippingItem is { MeasuredGrossWeight: > 0, MeasuredNetWeight: > 0 };
RefreshSelectedShippingItemMeasuredValuesFromDb(await FruitBankSignalRClient.UpdateShippingItem(shippingItem));
var updatedShippingItem = await FruitBankSignalRClient.UpdateMeasuredShippingItem(shippingItem);
if (updatedShippingItem == null)
{
_logger.Error($"Sikertelen volt a shippingItem mentése! Id: {shippingItem.Id}");
//TODO: - J.
return;
}
RefreshSelectedShippingItemMeasuredValuesFromDb(updatedShippingItem);
}
}
@ -176,24 +183,27 @@ namespace FruitBankHybrid.Shared.Pages
switch (fieldName)
{
case nameof(ShippingItem.Name):
SelectedShippingItem.Name = newValue.ToString() ?? string.Empty;
break;
case nameof(ShippingItem.GrossWeight):
SelectedShippingItem.GrossWeight = (double)newValue;
break;
case nameof(ShippingItem.NetWeight):
SelectedShippingItem.NetWeight = (double)newValue;
break;
case nameof(ShippingItem.MeasuredGrossWeight):
SelectedShippingItem.MeasuredGrossWeight = (double)newValue;
//case nameof(ShippingItem.Name):
// SelectedShippingItem.Name = newValue.ToString() ?? string.Empty;
// break;
//case nameof(ShippingItem.GrossWeight):
// SelectedShippingItem.GrossWeight = (double)newValue;
// break;
//case nameof(ShippingItem.NetWeight):
// SelectedShippingItem.NetWeight = (double)newValue;
// break;
case nameof(ShippingItem.MeasuredQuantity):
SelectedShippingItem.MeasuredQuantity = (int)newValue <= 0 ? null : (int)newValue;
break;
case nameof(ShippingItem.MeasuredNetWeight):
SelectedShippingItem.MeasuredNetWeight = (double)newValue;
SelectedShippingItem.MeasuredNetWeight = !SelectedShippingItem.IsMeasurable || (double)newValue <= 0 ? null : (double)newValue;
break;
case nameof(ShippingItem.MeasuredGrossWeight):
SelectedShippingItem.MeasuredGrossWeight = !SelectedShippingItem.IsMeasurable || (double)newValue <= 0 ? null : (double)newValue;
break;
}
//if (SelectedShippingItem.MeasuredGrossWeight > 0 && SelectedShippingItem.MeasuredNetWeight > 0)
if (SelectedShippingItem.IsValidMeasuringValues())
BtnSaveEnabled = true;
}

View File

@ -2,6 +2,7 @@
using AyCode.Core.Loggers;
using FruitBank.Common;
using FruitBank.Common.Loggers;
using Mango.Nop.Core.Loggers;
namespace FruitBankHybrid.Shared.Services.Loggers;

View File

@ -72,6 +72,10 @@ namespace FruitBankHybrid.Shared.Services.SignalRs
public Task<ShippingItem?> UpdateShippingItem(ShippingItem shippingItem)
=> PostDataAsync(SignalRTags.UpdateShippingItem, shippingItem);
public Task<ShippingItem?> UpdateMeasuredShippingItem(ShippingItem shippingItem)
=> PostDataAsync(SignalRTags.UpdateMeasuredShippingItem, shippingItem);
#endregion ShippingItem
#region ShippingDocument