76 lines
2.1 KiB
C#
76 lines
2.1 KiB
C#
using AyCode.Core.Extensions;
|
|
using AyCode.Core.Helpers;
|
|
using LinqToDB.Mapping;
|
|
using Mango.Nop.Core.Entities;
|
|
using Mango.Nop.Core.Interfaces;
|
|
using Nop.Core;
|
|
using Nop.Core.Domain.Orders;
|
|
|
|
namespace Mango.Nop.Core.Dtos;
|
|
|
|
public abstract class MgOrderItemDto<TProductDto> : MgEntityBase, IModelDtoBase<OrderItem>, IMgOrderItemDto<TProductDto> where TProductDto : IMgProductDto
|
|
{
|
|
public Guid OrderItemGuid { get; set; }
|
|
public int OrderId { get; set; }
|
|
public int ProductId { get; set; }
|
|
public int Quantity { get; set; }
|
|
|
|
public decimal UnitPriceInclTax { get; set; }
|
|
public decimal UnitPriceExclTax { get; set; }
|
|
|
|
public decimal PriceInclTax { get; set; }
|
|
public decimal PriceExclTax { get; set; }
|
|
|
|
public string AttributesXml { get; set; }
|
|
public decimal? ItemWeight { get; set; }
|
|
|
|
public string ProductName => ProductDto?.Name ?? "ProductDto is null!!!";
|
|
|
|
[Association(ThisKey = nameof(ProductId), OtherKey = nameof(BaseEntity.Id), CanBeNull = true)]
|
|
public TProductDto? ProductDto { get; set; }
|
|
|
|
protected MgOrderItemDto() :base()
|
|
{ }
|
|
|
|
protected MgOrderItemDto(int orderItemId)
|
|
{
|
|
Id = orderItemId;
|
|
}
|
|
|
|
protected MgOrderItemDto(OrderItem orderItem)
|
|
{
|
|
CopyEntityValuesToDto(orderItem);
|
|
}
|
|
|
|
public virtual void CopyDtoValuesToEntity(OrderItem entity)
|
|
{
|
|
PropertyHelper.CopyPublicValueTypeProperties(this, entity);
|
|
}
|
|
|
|
public virtual void CopyEntityValuesToDto(OrderItem entity)
|
|
{
|
|
PropertyHelper.CopyPublicValueTypeProperties(entity, this);
|
|
}
|
|
|
|
public virtual void CopyEntityValuesToDto(OrderItem entity, TProductDto productDto)
|
|
{
|
|
CopyEntityValuesToDto(entity);
|
|
|
|
InitializeProductDto(productDto);
|
|
}
|
|
|
|
public virtual void InitializeProductDto(TProductDto productDto)
|
|
{
|
|
ProductDto = productDto;
|
|
}
|
|
|
|
public virtual OrderItem CreateMainEntity()
|
|
{
|
|
//base.CreateMainEntity();
|
|
|
|
var orderItem = new OrderItem();
|
|
CopyDtoValuesToEntity(orderItem);
|
|
|
|
return orderItem;
|
|
}
|
|
} |