예제 #1
0
        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));
        }