This commit is contained in:
Loretta 2025-10-12 18:07:48 +02:00
parent 9d6cc0abed
commit 294b1e0970
3 changed files with 50 additions and 3 deletions

View File

@ -1,14 +1,29 @@
using AyCode.Core.Extensions;
using FruitBank.Common.Interfaces;
using LinqToDB.Mapping;
using Mango.Nop.Core.Dtos;
using Mango.Nop.Core.Interfaces;
using Nop.Core;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Common;
using Nop.Core.Domain.Orders;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq.Expressions;
using Newtonsoft.Json;
namespace FruitBank.Common.Dtos;
public class OrderDto : MgOrderDto<OrderItemDto, ProductDto>, IOrderDto
{
[NotColumn]
private static Expression<Func<OrderDto, GenericAttribute, bool>> RelationWithGenericAttribute => (orderDto, genericAttribute) =>
orderDto.Id == genericAttribute.EntityId && genericAttribute.KeyGroup == nameof(Order);
[Association(ThisKey = nameof(Id), OtherKey = nameof(GenericAttribute.EntityId), ExpressionPredicate = nameof(RelationWithGenericAttribute), CanBeNull = true)]
public List<GenericAttribute> GenericAttributes { get; set; }
public OrderDto() :base()
{ }
public OrderDto(int orderId) : base(orderId)

View File

@ -1,14 +1,43 @@
using FruitBank.Common.Entities;
using System.Globalization;
using System.Linq.Expressions;
using FruitBank.Common.Entities;
using FruitBank.Common.Interfaces;
using LinqToDB.Mapping;
using Mango.Nop.Core.Dtos;
using Newtonsoft.Json;
using Nop.Core;
using Nop.Core.Domain.Common;
using Nop.Core.Domain.Orders;
namespace FruitBank.Common.Dtos;
public class OrderItemDto : MgOrderItemDto<ProductDto>, IOrderItemDto
public class OrderItemDto : MgOrderItemDto<ProductDto>, IOrderItemDto, IMeasuringNetWeight
{
[NotColumn]
private static Expression<Func<OrderItemDto, GenericAttribute, bool>> RelationWithGenericAttribute => (orderItemDto, genericAttribute) =>
orderItemDto.Id == genericAttribute.EntityId && genericAttribute.KeyGroup == nameof(OrderItem);
[Association(ThisKey = nameof(Id), OtherKey = nameof(GenericAttribute.EntityId), ExpressionPredicate = nameof(RelationWithGenericAttribute), CanBeNull = true)]
public List<GenericAttribute> GenericAttributes { get; set; }
[Association(ThisKey = nameof(Id), OtherKey = nameof(OrderItemPallet.OrderItemId), CanBeNull = true)]
public List<OrderItemPallet> OrderItemPallets { get; set; }
[NotColumn]
[JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public double NetWeight
{
get => CommonHelper.To<double>(GenericAttributes?.FirstOrDefault(x => x.Key == nameof(IMeasuringNetWeight.NetWeight))?.Value ?? "0");
set
{
//Direkt legyen exception! - J.
var ga = GenericAttributes?.FirstOrDefault(x => x.Key == nameof(IMeasuringNetWeight.NetWeight))!;
ga.Value = value.ToString(CultureInfo.InvariantCulture);
}
}
public OrderItemDto() : base()
{
}

View File

@ -31,6 +31,8 @@ public sealed class OrderClientTests
Assert.IsNotNull(orderDtos);
Assert.IsTrue(orderDtos.Count != 0);
Assert.IsTrue(orderDtos.All(o => o.OrderItemDtos.All(oi => oi.ProductDto != null && oi.ProductDto.Id == oi.ProductId)));
}
[TestMethod]
@ -53,7 +55,8 @@ public sealed class OrderClientTests
var orderDto = await _signalRClient.GetOrderDtoById(orderId);
Assert.IsNotNull(orderDto);
Assert.IsTrue(orderDto.OrderStatusId >= 10);
//Assert.IsTrue(orderDto.CustomOrderNumber == orderId.ToString());
Assert.IsTrue(orderDto.CustomOrderNumber == orderId.ToString());
}
}