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
{
///
/// Model/Data used to create an intial entry in the stock SKU transaction table
///
public class SkuTransactionCreate : IValidatableObject
{
[Required()]
public DateTime TransactionDate { get; private set; }
[Required()]
public string SkuTransactionTypeCode { get; private set; }
public int? ForeignKey { get; private set; }
public string Reference { get; private set; }
public string Detail { get; private set; }
[Required()]
public string SkuNumber { get; private set; }
[Required(), Range(0, short.MaxValue)]
public int Quantity { get; private set; } // cannot be negative
public SkuTransactionCreate(DateTime transactionDate, string transactionTypeCode, int? foreignKey, string reference, string detail
, string skuNumber, int quantity)
{
this.TransactionDate = transactionDate;
this.SkuTransactionTypeCode = transactionTypeCode;
this.ForeignKey = foreignKey;
this.Reference = reference;
this.Detail = detail;
this.SkuNumber = skuNumber;
this.Quantity = quantity;
//var context = new ValidationContext(null);
var vaild = Validate(null);
if (new Logic.Validate.SkuTransaction().IsValidResult)
if (vaild.Any())
{
throw new Exception("Invalid parameters set");
}
}
public IEnumerable Validate(ValidationContext validationContext)
{
var result = new List();
if (Logic.Validate.Format.DateTime(TransactionDate) == false)
{
result.Add(new ValidationResult("Invalid transaction date"));
}
if (string.IsNullOrEmpty(SkuTransactionTypeCode))
{
result.Add(new ValidationResult("Invalid transaction type code"));
}
if (Logic.Validate.Format.SkuNumber(SkuNumber) == false)
{
result.Add(new ValidationResult("Invalid SKU number"));
}
return result;
}
}
}