Beispiel #1
0
        public virtual JsonResult UpdateBasketInfo(HeaderCustomInfo model)
        {
            var basket = _basketApi.GetBasketData(model.BasketId.ToString());

            if (model.LineInfo != null)
            {
                if (basket != null)
                {
                    var newLines = (from p in model.LineInfo
                                    where basket.Result.LineItems.Any(l => l.ProductId == p.ProductId.ToUpper()) == false
                                    select new BasketAddModel()
                    {
                        BasketId = model.BasketId.ToString(), ProductId = p.ProductId, DisplayOrder = 0, Qty = p.Qty, StockCode = p.StockCode, CustomInfo2 = p.CustomInfo2
                    }).ToList();
                    if (newLines.Where(x => !string.IsNullOrEmpty(x.StockCode)).Any())
                    {
                        var basketData = _basketApi.BulkAddProduct(newLines);
                        model.BasketId = Guid.Parse(basketData.Result.Id);
                    }

                    var existLines = (from p in basket.Result.LineItems
                                      where model.LineInfo.Any(l => l.ProductId.ToUpper() == p.ProductId.ToUpper()) == true
                                      select p).ToList();
                    model.LineInfo.ForEach(l => l.Qty = Math.Max(l.Qty, existLines.FirstOrDefault(li => li.ProductId.ToUpper() == l.ProductId.ToUpper() && li.ParentProductId == Guid.Empty.ToString())?.Qty ?? 0));
                    //model.LineInfo.ForEach(l => l.Qty = Math.Max(l.Qty, existLines.FirstOrDefault(li => li.ProductId.ToUpper() == l.ProductId.ToUpper()) != null ? existLines.FirstOrDefault(li => li.ProductId.ToUpper() == l.ProductId.ToUpper()).Qty : 0));
                }
                var resp = _basketApi.UpdateBasketInfo(model.BasketId.ToString(), model);
                return(JsonSuccess(resp, JsonRequestBehavior.DenyGet));
            }
            return(JsonSuccess(basket, JsonRequestBehavior.DenyGet));
        }
Beispiel #2
0
 public ResponseModel <BasketModel> UpdateBasketInfo(string basketId, HeaderCustomInfo info)
 {
     ResetSessionBasket();
     return(CallApi <BasketModel>(string.Format(ApiUrls.UpdateBasketLineCustomInfo, basketId), JsonConvert.SerializeObject(info), Method.POST));
 }