Files
bnhtrade/src/bnhtrade.Core/Model/Stock/SkuTransaction.cs

216 lines
6.2 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Model.Stock
{
public class SkuTransaction : IValidatableObject
{
private DateTime? transactionDate = null;
private bool? isProcessed = null;
private short? quantity = null;
private int? stockjournalId = null;
private int? skuTransactionId = null;
private int? foreignKey = null;
private string skuTransactionTypeCode;
private Model.Stock.SkuTransactionType skuTransactionType;
public int SkuTransactionId
{
get { return skuTransactionId.GetValueOrDefault(); }
set { skuTransactionId = value; }
}
public bool IsSetSkuTransactionId
{
get { return skuTransactionId != null; }
}
[Required()]
public DateTime TransactionDate
{
get { return transactionDate.GetValueOrDefault(); }
set { transactionDate = value; }
}
public bool IsSetTransactionDate
{
get { return transactionDate != null; }
}
[Required()]
public string SkuTransactionTypeCode
{
get
{
if (IsSetSkuTransactionType)
{
return SkuTransactionType.TypeCode;
}
else
{
return skuTransactionTypeCode;
}
}
set
{
if (IsSetSkuTransactionType)
{
if (SkuTransactionType.TypeCode != value)
{
SkuTransactionType = null;
skuTransactionTypeCode = value;
}
}
else
{
skuTransactionTypeCode = value;
}
}
}
public bool IsSetSkuTransactionTypeCode
{
get { return SkuTransactionTypeCode != null; }
}
public Model.Stock.SkuTransactionType SkuTransactionType
{
get
{
return skuTransactionType;
}
set
{
if (IsSetSkuTransactionTypeCode)
{
skuTransactionTypeCode = null;
}
skuTransactionType = value;
}
}
public bool IsSetSkuTransactionType
{
get { return SkuTransactionType != null; }
}
public int ForeignKey
{
get { return foreignKey.GetValueOrDefault(); }
set { foreignKey = value; }
}
public bool IsSetForeignKey
{
get { return foreignKey != null; }
}
public string Reference { get; set; }
public bool IsSetReference
{
get { return Reference != null; }
}
public string Detail { get; set; }
public bool IsSetDetail
{
get { return Detail != null; }
}
[Required()]
public string SkuNumber { get; set; }
public bool IsSetSkuNumber
{
get { return SkuNumber != null; }
}
[Required(), Range(0, short.MaxValue)]
public short Quantity
{
get { return quantity.GetValueOrDefault(); }
set { quantity = value; }
}
public bool IsSetQuantity
{
get { return quantity != null; }
}
public bool IsProcessed
{
get { return isProcessed.GetValueOrDefault(); }
set { isProcessed = value; }
}
public bool IsSetIsProcessed
{
get { return isProcessed != null; }
}
public int StockJournalId
{
get { return stockjournalId.GetValueOrDefault(); }
set { stockjournalId = value; }
}
public bool IsSetStockJournalId
{
get { return stockjournalId != null; }
}
public SkuTransaction Clone()
{
var clone = new SkuTransaction();
if (IsSetDetail) { clone.Detail = string.Copy(this.Detail); }
if (IsSetForeignKey) { clone.ForeignKey = this.ForeignKey; }
if (IsSetIsProcessed) { clone.IsProcessed = this.IsProcessed; }
if (IsSetQuantity) { clone.Quantity = this.Quantity; }
if (IsSetReference) { clone.Reference = string.Copy(this.Reference); }
if (IsSetSkuNumber) { clone.SkuNumber = string.Copy(this.SkuNumber); }
if (IsSetStockJournalId) { clone.StockJournalId = this.StockJournalId; }
if (IsSetSkuTransactionId) { clone.SkuTransactionId = this.SkuTransactionId; }
if (IsSetTransactionDate) { clone.TransactionDate = this.TransactionDate; }
if (IsSetSkuTransactionType) { clone.SkuTransactionType = this.SkuTransactionType; }
else if (IsSetSkuTransactionTypeCode) { clone.SkuTransactionTypeCode = string.Copy(this.SkuTransactionTypeCode); }
return clone;
}
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var result = new List<ValidationResult>();
if (!IsSetTransactionDate)
{
result.Add(new ValidationResult("Transaction date is not set"));
}
if (!IsSetIsProcessed)
{
result.Add(new ValidationResult("IsProcessed is not set"));
}
if (!IsSetQuantity)
{
result.Add(new ValidationResult("Quantity is not set"));
}
//if (!IsSetSkuTransactionId)
//{
// result.Add(new ValidationResult("Stock Transaction Id is not set"));
//}
if (IsSetStockJournalId && (!IsSetIsProcessed || IsProcessed == false))
{
result.Add(new ValidationResult("Stock Journal Id is set, IsProcessed must be set to true"));
}
return result;
}
}
}