public JsonResult AddSku(SkuForTransactionMetadata skuForTransactionMetadata) { ModelState.Remove("CompanyId"); ModelState.Remove("BrandId"); ModelState.Remove("ProductId"); ModelState.Remove("CompanyName"); ModelState.Remove("BrandName"); ModelState.Remove("ProductName"); ModelState.Remove("SkuName"); if (!ModelState.IsValid) { return(Json(new AjaxResult { IsError = true, ErrorMessages = ModelState.Values.SelectMany(v => v.Errors).ToList() })); } var transactionInfo = GetTransactionSession(); if (transactionInfo != null) { var cartInfo = _transaction.AddSkuToInvoice(transactionInfo, skuForTransactionMetadata); if (cartInfo.Key) { SetTransactionSession(cartInfo.Value); } var ajaxresult = new AjaxResult { IsError = !cartInfo.Key, }; if (!cartInfo.Key) { ajaxresult.ErrorMessages.Add(new ModelError("Out of Stock.")); } return(Json(ajaxresult)); } var productNotFountresult = new AjaxResult { IsError = true, }; productNotFountresult.ErrorMessages.Add(new ModelError("SKU Is not Found.")); return(Json(productNotFountresult)); }
public KeyValuePair <bool, TransactionMetadata> AddSkuToInvoice(TransactionMetadata transactionMetadata, SkuForTransactionMetadata skuForTransactionMetadata) { if (transactionMetadata.Products == null) { transactionMetadata.Products = new List <StockMetaData>(); } var skuFortansaction = transactionMetadata.Products.FirstOrDefault(x => x.SkuId == skuForTransactionMetadata.SkuId); if (skuFortansaction != null) { if (transactionMetadata.IsSales) { if (skuForTransactionMetadata.SkuId != null) { var stackInfo = _basicUnit.Stocks.GetStockBySkuId((Int64)skuForTransactionMetadata.SkuId); if ((skuFortansaction.Quantity + skuForTransactionMetadata.TransactionQuantity) > stackInfo.Quantity) { return(new KeyValuePair <bool, TransactionMetadata>(false, transactionMetadata)); } } } skuFortansaction.Quantity += skuForTransactionMetadata.TransactionQuantity; skuForTransactionMetadata.Rate = skuForTransactionMetadata.TransactionRate; skuForTransactionMetadata.Amount = skuForTransactionMetadata.TransactionAmount; return(new KeyValuePair <bool, TransactionMetadata>(true, transactionMetadata)); } if (skuForTransactionMetadata.SkuId != null) { var skuInfo = _basicUnit.Skus.GetSkuById((Int64)skuForTransactionMetadata.SkuId); transactionMetadata.Products.Add(new StockMetaData { Amount = skuForTransactionMetadata.TransactionAmount, BrandId = skuInfo.BrandId, SkuName = skuInfo.SkuName, BrandName = skuInfo.BrandName, CompanyId = skuInfo.CompanyId, CompanyName = skuInfo.CompanyName, ProductId = skuInfo.ProductId, ProductName = skuInfo.ProductName, Quantity = skuForTransactionMetadata.TransactionQuantity, Rate = skuForTransactionMetadata.TransactionRate, SkuId = skuForTransactionMetadata.SkuId }); return(new KeyValuePair <bool, TransactionMetadata>(true, transactionMetadata)); } return(new KeyValuePair <bool, TransactionMetadata>(false, transactionMetadata)); }