Mango.Nop.Libraries/Mango.Nop.Core/Dtos/MgOrderDto.cs

111 lines
3.4 KiB
C#

using AyCode.Core.Extensions;
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;
public abstract class MgOrderDto<TOrderItemDto, TProductDto> : MgEntityBase, IModelDtoBase<Order>, IMgOrderDto<TOrderItemDto, TProductDto> where TOrderItemDto : IMgOrderItemDto<TProductDto> 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<TOrderItemDto> OrderItemDtos { get; set; }
[Association(ThisKey = nameof(Id), OtherKey = nameof(OrderNote.OrderId), CanBeNull = true)]
public List<OrderNote> OrderNotes { get; set; }
public OrderStatus OrderStatus
{
get => (OrderStatus)OrderStatusId;
set => OrderStatusId = (int)value;
}
public ShippingStatus ShippingStatus
{
get => (ShippingStatus)ShippingStatusId;
set => ShippingStatusId = (int)value;
}
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<MgOrderDto<Order, Order>();
// //cfg.CreateMap<Person, Person>()
// // .ForMember(dest => dest.Address, opt => opt.MapFrom(src => _mapper.Map<Address>(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<TOrderItemDto> orderItemDtos)
{
CopyEntityValuesToDto(entity);
InitializeOrderItemDtos(orderItemDtos);
}
public virtual void InitializeOrderItemDtos(List<TOrderItemDto> orderItemDtos)
{
OrderItemDtos = orderItemDtos;
}
public virtual Order CreateMainEntity()
{
//base.CreateMainEntity();
var order = new Order();
CopyDtoValuesToEntity(order);
return order;
}
}