using AyCode.Core.Extensions; using AyCode.Core.Serializers.Toons; using AyCode.Core.Helpers; using LinqToDB.Mapping; using Mango.Nop.Core.Entities; using Mango.Nop.Core.Interfaces; using Newtonsoft.Json; using Nop.Core; using Nop.Core.Domain.Common; using Nop.Core.Domain.Customers; using Nop.Core.Domain.Orders; using Nop.Core.Domain.Payments; using Nop.Core.Domain.Shipping; using System.Linq.Expressions; namespace Mango.Nop.Core.Dtos; [ToonDescription("Base DTO for orders with items, customer and status tracking")] public abstract class MgOrderDto : MgEntityBase, IModelDtoBase, IMgOrderDto where TOrderItemDto : IMgOrderItemDto where TProductDto : IMgProductDto { 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 int PaymentStatusId { get; set; } public string ShippingMethod { get; set; } public string CustomOrderNumber { get; set; } public string CustomValuesXml { get; set; } public bool Deleted { get; set; } [Association(ThisKey = nameof(CustomerId), OtherKey = nameof(Customer.Id), CanBeNull = false)] public Customer Customer { get; set; } //TODO: CustomerDto!!! - J. [Association(ThisKey = nameof(Id), OtherKey = nameof(OrderItem.OrderId), CanBeNull = true)] public List OrderItemDtos { get; set; } [Association(ThisKey = nameof(Id), OtherKey = nameof(OrderNote.OrderId), CanBeNull = true)] public List OrderNotes { get; set; } [ToonDescription(Purpose = "Enum wrapper", BusinessRule = "get, set => OrderStatusId")] public OrderStatus OrderStatus { get => (OrderStatus)OrderStatusId; set => OrderStatusId = (int)value; } [ToonDescription(Purpose = "Enum wrapper", BusinessRule = "get, set => ShippingStatusId")] public ShippingStatus ShippingStatus { get => (ShippingStatus)ShippingStatusId; set => ShippingStatusId = (int)value; } [ToonDescription(Purpose = "Enum wrapper", BusinessRule = "get, set => PaymentStatusId")] public PaymentStatus PaymentStatus { get => (PaymentStatus)PaymentStatusId; set => PaymentStatusId = (int)value; } protected MgOrderDto() :base() { } protected MgOrderDto(int orderId) { Id = orderId; } protected MgOrderDto(Order order) { CopyEntityValuesToDto(order); } public virtual void CopyDtoValuesToEntity(Order entity) { //var config = new MapperConfiguration(cfg => //{ // cfg.CreateMap(); // //cfg.CreateMap() // // .ForMember(dest => dest.Address, opt => opt.MapFrom(src => _mapper.Map
(src.Address))); //}); //var _mapper = config.CreateMapper(); //_mapper.Map<> PropertyHelper.CopyPublicValueTypeProperties(this, entity); } public virtual void CopyEntityValuesToDto(Order entity) { PropertyHelper.CopyPublicValueTypeProperties(entity, this); } public virtual void CopyEntityValuesToDto(Order entity, List orderItemDtos) { CopyEntityValuesToDto(entity); InitializeOrderItemDtos(orderItemDtos); } public virtual void InitializeOrderItemDtos(List orderItemDtos) { OrderItemDtos = orderItemDtos; } public virtual Order CreateMainEntity() { //base.CreateMainEntity(); var order = new Order(); CopyDtoValuesToEntity(order); return order; } }