FruitBankHybridApp/FruitBank.Common/Entities/StockTakingItemPallet.cs

46 lines
1.8 KiB
C#

using FruitBank.Common.Dtos;
using FruitBank.Common.Interfaces;
using LinqToDB.Mapping;
using Mango.Nop.Core.Entities;
using System.ComponentModel.DataAnnotations.Schema;
namespace FruitBank.Common.Entities;
public interface IStockTakingItemPallet : IMeasuringItemPalletBase
{
int StockTakingItemId { get; set; }
public StockTakingItem? StockTakingItem{ get; set; }
}
[LinqToDB.Mapping.Table(Name = FruitBankConstClient.StockTakingItemPalletDbTableName)]
[System.ComponentModel.DataAnnotations.Schema.Table(FruitBankConstClient.StockTakingItemPalletDbTableName)]
public class StockTakingItemPallet : MeasuringItemPalletBase, IStockTakingItemPallet
{
public int StockTakingItemId
{
get => ForeignItemId;
set => ForeignItemId = value;
}
//[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
[Association(ThisKey = nameof(StockTakingItemId), OtherKey = nameof(StockTakingItem.Id), CanBeNull = true)]
public StockTakingItem? StockTakingItem { get; set; }
public override double CalculateNetWeight() => base.CalculateNetWeight();
public override bool IsValidSafeMeasuringValues()
{
return StockTakingItemId > 0 && TrayQuantity >= 0 && TareWeight >= 0 && PalletWeight >= 0 && NetWeight >= 0 && GrossWeight >= 0;
}
public override bool IsValidMeasuringValues(bool isMeasurable)
{
return StockTakingItemId > 0 && TrayQuantity >= 0 && ((!isMeasurable && NetWeight == 0 && GrossWeight == 0 && PalletWeight == 0 && TareWeight == 0)
|| (isMeasurable && NetWeight >= 0 && GrossWeight >= 0 && PalletWeight >= 0 && TareWeight >= 0));
}
public override void SetParentPropToNull()
{
StockTakingItem = null;
}
}