diff --git a/Mango.Nop.Core/Dtos/MgOrderDto.cs b/Mango.Nop.Core/Dtos/MgOrderDto.cs index 7bb1d93..8e586fa 100644 --- a/Mango.Nop.Core/Dtos/MgOrderDto.cs +++ b/Mango.Nop.Core/Dtos/MgOrderDto.cs @@ -1,24 +1,38 @@ -using Mango.Nop.Core.Interfaces; +using AyCode.Core.Extensions; +using Mango.Nop.Core.Interfaces; using Nop.Core.Domain.Catalog; using Nop.Core.Domain.Orders; +using Nop.Core.Domain.Shipping; namespace Mango.Nop.Core.Dtos; -public abstract class MgOrderDto : ModelDtoBase, IMgOrderDto +public abstract class MgOrderDto : ModelDtoBase, IMgOrderDto where TOrderItemDto : IMgOrderItemDto where TProductDto : IMgProductDto { - public Guid OrderGuid { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public int StoreId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public int CustomerId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public int OrderStatusId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public int ShippingStatusId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public decimal OrderDiscount { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public decimal OrderTotal { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public DateTime CreatedOnUtc { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public DateTime? PaidDateUtc { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public string ShippingMethod { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public string CustomOrderNumber { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public string CustomValuesXml { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public bool Deleted { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public Guid OrderGuid { get; set; } + public int StoreId { get; set; } + public int CustomerId { get; set; } + public int OrderStatusId { get; set; } + public int ShippingStatusId { get; set; } + public decimal OrderDiscount { get; set; } + public decimal OrderTotal { get; set; } + public DateTime CreatedOnUtc { get; set; } + public DateTime? PaidDateUtc { get; set; } + public string ShippingMethod { get; set; } + public string CustomOrderNumber { get; set; } + public string CustomValuesXml { get; set; } + public bool Deleted { get; set; } + public List OrderItemDtos { get; private set; } + + public OrderStatus OrderStatus + { + get => (OrderStatus)OrderStatusId; + set => OrderStatusId = (int)value; + } + public ShippingStatus ShippingStatus + { + get => (ShippingStatus)ShippingStatusId; + set => ShippingStatusId = (int)value; + } protected MgOrderDto() :base() { } @@ -26,4 +40,40 @@ public abstract class MgOrderDto : ModelDtoBase, IMgOrderDto { } protected MgOrderDto(Order order) : base(order) { } + + public override void CopyDtoValuesToEntity(Order entity) + { + base.CopyDtoValuesToEntity(entity); + + PropertyHelper.CopyPublicValueTypeProperties(this, entity); + } + + public override void CopyEntityValuesToDto(Order entity) + { + base.CopyEntityValuesToDto(entity); + + PropertyHelper.CopyPublicValueTypeProperties(entity, this); + } + + public void CopyEntityValuesToDto(Order entity, List orderItemDtos) + { + CopyEntityValuesToDto(entity); + + InitializeOrderItemDtos(orderItemDtos); + } + + public void InitializeOrderItemDtos(List orderItemDtos) + { + OrderItemDtos = orderItemDtos; + } + + public override Order CreateMainEntity() + { + //base.CreateMainEntity(); + + var order = new Order(); + CopyDtoValuesToEntity(order); + + return order; + } } \ No newline at end of file diff --git a/Mango.Nop.Core/Dtos/MgOrderItemDto.cs b/Mango.Nop.Core/Dtos/MgOrderItemDto.cs new file mode 100644 index 0000000..a4e8716 --- /dev/null +++ b/Mango.Nop.Core/Dtos/MgOrderItemDto.cs @@ -0,0 +1,59 @@ +using AyCode.Core.Extensions; +using Mango.Nop.Core.Interfaces; +using Nop.Core.Domain.Orders; + +namespace Mango.Nop.Core.Dtos; + +public abstract class MgOrderItemDto : ModelDtoBase, IMgOrderItemDto where TProductDto : IMgProductDto +{ + public Guid OrderItemGuid { get; set; } + public int OrderId { get; set; } + public int ProductId { get; set; } + public int Quantity { get; set; } + public string AttributesXml { get; set; } + public decimal? ItemWeight { get; set; } + public TProductDto ProductDto { get; set; } + + protected MgOrderItemDto() :base() + { } + protected MgOrderItemDto(int orderItemId) : base(orderItemId) + { } + protected MgOrderItemDto(OrderItem orderItem) : base(orderItem) + { } + + public override void CopyDtoValuesToEntity(OrderItem entity) + { + base.CopyDtoValuesToEntity(entity); + + PropertyHelper.CopyPublicValueTypeProperties(this, entity); + } + + public override void CopyEntityValuesToDto(OrderItem entity) + { + base.CopyEntityValuesToDto(entity); + + PropertyHelper.CopyPublicValueTypeProperties(entity, this); + } + + public void CopyEntityValuesToDto(OrderItem entity, TProductDto productDto) + { + CopyEntityValuesToDto(entity); + + InitializeProductDto(productDto); + } + + public void InitializeProductDto(TProductDto productDto) + { + ProductDto = productDto; + } + + public override OrderItem CreateMainEntity() + { + //base.CreateMainEntity(); + + var orderItem = new OrderItem(); + CopyDtoValuesToEntity(orderItem); + + return orderItem; + } +} \ No newline at end of file diff --git a/Mango.Nop.Core/Interfaces/IMgOrderDto.cs b/Mango.Nop.Core/Interfaces/IMgOrderDto.cs index 7c6a76e..8796398 100644 --- a/Mango.Nop.Core/Interfaces/IMgOrderDto.cs +++ b/Mango.Nop.Core/Interfaces/IMgOrderDto.cs @@ -1,9 +1,12 @@ using AyCode.Interfaces.Entities; +using Mango.Nop.Core.Dtos; using Nop.Core.Domain.Common; +using Nop.Core.Domain.Orders; +using Nop.Core.Domain.Shipping; namespace Mango.Nop.Core.Interfaces; -public interface IMgOrderDto : IEntityInt, ISoftDeletedEntity +public interface IMgOrderDto : IEntityInt, ISoftDeletedEntity where TOrderItemDto : IMgOrderItemDto where TProductDto : IMgProductDto { public Guid OrderGuid { get; set; } public int StoreId { get; set; } @@ -11,18 +14,10 @@ public interface IMgOrderDto : IEntityInt, ISoftDeletedEntity public int CustomerId { get; set; } public int OrderStatusId { get; set; } - //public OrderStatus OrderStatus - //{ - // get => (OrderStatus)OrderStatusId; - // set => OrderStatusId = (int)value; - //} + public OrderStatus OrderStatus { get; set; } public int ShippingStatusId { get; set; } - //public ShippingStatus ShippingStatus - //{ - // get => (ShippingStatus)ShippingStatusId; - // set => ShippingStatusId = (int)value; - //} + public ShippingStatus ShippingStatus { get; set; } public decimal OrderDiscount { get; set; } @@ -32,9 +27,12 @@ public interface IMgOrderDto : IEntityInt, ISoftDeletedEntity public DateTime? PaidDateUtc { get; set; } public string ShippingMethod { get; set; } - + public string CustomOrderNumber { get; set; } public string CustomValuesXml { get; set; } - public bool Deleted { get; set; } + public List OrderItemDtos { get; } + + void InitializeOrderItemDtos(List orderItemDtos); + void CopyEntityValuesToDto(Order entity, List orderItemDtos); } \ No newline at end of file diff --git a/Mango.Nop.Core/Interfaces/IMgOrderItemDto.cs b/Mango.Nop.Core/Interfaces/IMgOrderItemDto.cs new file mode 100644 index 0000000..a1f08f9 --- /dev/null +++ b/Mango.Nop.Core/Interfaces/IMgOrderItemDto.cs @@ -0,0 +1,23 @@ +using AyCode.Interfaces.Entities; +using Nop.Core.Domain.Orders; + +namespace Mango.Nop.Core.Interfaces; + +public interface IMgOrderItemDto : IEntityInt where TProductDto : IMgProductDto +{ + public Guid OrderItemGuid { get; set; } + + public int OrderId { get; set; } + + public int ProductId { get; set; } + + public int Quantity { get; set; } + + public string AttributesXml { get; set; } + public decimal? ItemWeight { get; set; } + + public TProductDto ProductDto { get; set; } + + void InitializeProductDto(TProductDto productDto); + void CopyEntityValuesToDto(OrderItem entity, TProductDto productDto); +} \ No newline at end of file