77 lines
3.3 KiB
C#
77 lines
3.3 KiB
C#
using FruitBank.Common.Interfaces;
|
|
using LinqToDB.Mapping;
|
|
using Mango.Nop.Core.Dtos;
|
|
using Mango.Nop.Core.Extensions;
|
|
using Newtonsoft.Json;
|
|
//using Nop.Core.Domain.Catalog;
|
|
using Nop.Core.Domain.Common;
|
|
using System.Linq.Expressions;
|
|
|
|
namespace FruitBank.Common.Dtos;
|
|
|
|
public class ProductDto : MgProductDto, IProductDto
|
|
{
|
|
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
private static Expression<Func<ProductDto, GenericAttribute, bool>> RelationWithGenericAttribute => (orderItemDto, genericAttribute) =>
|
|
orderItemDto.Id == genericAttribute.EntityId && genericAttribute.KeyGroup == "Product";// nameof(Product);
|
|
|
|
|
|
[Association(ThisKey = nameof(Id), OtherKey = nameof(GenericAttribute.EntityId), ExpressionPredicate = nameof(RelationWithGenericAttribute), CanBeNull = false)]
|
|
public List<GenericAttribute> GenericAttributes { get; set; }
|
|
|
|
public ProductDto() :base()
|
|
{ }
|
|
public ProductDto(int productId) : base(productId)
|
|
{ }
|
|
//public ProductDto(Product product) : base(product)
|
|
//{ }
|
|
|
|
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
public bool IsMeasurable
|
|
{
|
|
get => GenericAttributes.GetValueOrDefault<bool>(nameof(IMeasurable.IsMeasurable));
|
|
set
|
|
{
|
|
throw new Exception($"ProductDto.IsMeasurable not set");
|
|
|
|
//Direkt legyen exception! - J.
|
|
var ga = GenericAttributes.SingleOrDefault(x => x.Key == nameof(IMeasurable.IsMeasurable))!;
|
|
ga.Value = value.ToString();
|
|
}
|
|
}
|
|
|
|
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
public double Tare
|
|
{
|
|
get => GenericAttributes.GetValueOrDefault<double>(nameof(ITare.Tare));
|
|
//get => CommonHelper.To<double>(GenericAttributes.SingleOrDefault(x => x.Key == nameof(ITare.Tare))?.Value ?? "0");
|
|
set => throw new Exception($"ProductDto.Tare not set");
|
|
}
|
|
|
|
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
public double NetWeight
|
|
{
|
|
get => GenericAttributes.GetValueOrDefault<double>(nameof(IMeasuringNetWeight.NetWeight));
|
|
//get => CommonHelper.To<double>(GenericAttributes.SingleOrDefault(x => x.Key == nameof(IMeasuringNetWeight.NetWeight))?.Value ?? "0");
|
|
set => throw new Exception($"ProductDto.NetWeight not set");
|
|
}
|
|
|
|
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
public int IncomingQuantity
|
|
{
|
|
get => GenericAttributes.GetValueOrDefault<int>(nameof(IIncomingQuantity.IncomingQuantity));
|
|
//get => CommonHelper.To<int>(GenericAttributes.SingleOrDefault(x => x.Key == nameof(IIncomingQuantity.IncomingQuantity))?.Value ?? "0");
|
|
set => throw new Exception($"ProductDto.IncomingQuantity not set");
|
|
}
|
|
|
|
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
public int AvailableQuantity => StockQuantity + IncomingQuantity;
|
|
|
|
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
public double AverageWeight => GenericAttributes.GetValueOrDefault<double>(nameof(IProductDto.AverageWeight));
|
|
|
|
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
|
|
public double AverageWeightTreshold => GenericAttributes.GetValueOrDefault<double>(nameof(IProductDto.AverageWeightTreshold));
|
|
|
|
public bool HasMeasuringValues() => Id > 0 && NetWeight != 0 && IsMeasurable;
|
|
} |