86 lines
3.1 KiB
C#
86 lines
3.1 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using FruitBank.Common.Interfaces;
|
|
using LinqToDB.Mapping;
|
|
using Mango.Nop.Core.Entities;
|
|
using DataType = LinqToDB.DataType;
|
|
|
|
namespace FruitBank.Common.Entities;
|
|
|
|
[Table(Name = FruitBankConstClient.ShippingItemPalletDbTableName)]
|
|
[System.ComponentModel.DataAnnotations.Schema.Table(FruitBankConstClient.ShippingItemPalletDbTableName)]
|
|
public class ShippingItemPallet : MgEntityBase, IShippingItemPallet
|
|
{
|
|
private double _palletWeight;
|
|
private double _grossWeight;
|
|
|
|
public int ShippingItemId { get; set; }
|
|
|
|
[Column(DataType = DataType.DecFloat)]
|
|
public double PalletWeight
|
|
{
|
|
get => _palletWeight;
|
|
set => _palletWeight = double.Round(value, 1);
|
|
}
|
|
|
|
//[Nullable]
|
|
//[Column(CanBeNull = true)]
|
|
[Range(1, 100000, ErrorMessage = "The Quantity value should be a number between 1 and 100,000.")]
|
|
public int Quantity { get; set; }
|
|
|
|
[NotColumn]
|
|
//[Column(DataType = DataType.DecFloat, CanBeNull = false)]
|
|
//[Range(1, 100000, ErrorMessage = "The NetWeight value should be a number between 1 and 100,000.")]
|
|
public double NetWeight => double.Round(GrossWeight - PalletWeight, 1);
|
|
|
|
//[Nullable]
|
|
[Column(DataType = DataType.DecFloat, CanBeNull = false)]
|
|
[Range(1, 100000, ErrorMessage = "The GrossWeight value should be a number between 1 and 100,000.")]
|
|
public double GrossWeight
|
|
{
|
|
get => _grossWeight;
|
|
set => _grossWeight = double.Round(value, 1);
|
|
}
|
|
|
|
public bool IsMeasured { get; set; }
|
|
|
|
[LinqToDB.Mapping.Association(ThisKey = nameof(ShippingItemId), OtherKey = nameof(ShippingItem.Id), CanBeNull = true)]
|
|
public ShippingItem? ShippingItem { get; set; }
|
|
|
|
[SkipValuesOnUpdate]
|
|
public int? CreatorId { get; set; }
|
|
public int? ModifierId { get; set; }
|
|
|
|
[SkipValuesOnUpdate]
|
|
public DateTime Created { get; set; }
|
|
public DateTime Modified { get; set; }
|
|
|
|
/// <summary>
|
|
/// Nem lehet nullánál kisebb "Weight" érték és a ShippingId, Quantity nagyobb mint nulla! Megengedőbb mint az IsValidMeasuringValues(bool isMeasurable)...
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool IsValidSafeMeasuringValues()
|
|
{
|
|
return ShippingItemId > 0 && Quantity > 0 && PalletWeight >= 0 && NetWeight >= 0 && GrossWeight >= 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// "Szigorúbb" mint az IsValidSafeMeasuringValues()
|
|
/// </summary>
|
|
/// <param name="isMeasurable"></param>
|
|
/// <returns></returns>
|
|
public bool IsValidMeasuringValues(bool isMeasurable)
|
|
{
|
|
return ShippingItemId > 0 && Quantity > 0 &&
|
|
((!isMeasurable && NetWeight == 0 && GrossWeight == 0 && PalletWeight == 0) || (isMeasurable && NetWeight > 0 && GrossWeight > 0 && PalletWeight >= 0));
|
|
}
|
|
|
|
public bool IsMeasuredAndValid(bool isMeasurable)
|
|
{
|
|
return Id > 0 && IsMeasured && IsValidMeasuringValues(isMeasurable);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{base.ToString()} [ShippingItemId: {ShippingItemId}; IsMeasured: {IsMeasured}; PalletWeight: {PalletWeight}; Quantity: {Quantity}; NetWeight: {NetWeight}; GrossWeight: {GrossWeight}]";
|
|
}
|
|
} |