public HttpResponseMessage UpdateCart(ItemCmdDTO item) { try { int portalID = PortalController.Instance.GetCurrentPortalSettings().PortalId; StoreInfo storeSettings = StoreController.GetStoreInfo(portalID); if (storeSettings.InventoryManagement && storeSettings.AvoidNegativeStock) { ProductController controler = new ProductController(); ProductInfo currentProduct = controler.GetProduct(portalID, item.ID); if (currentProduct.StockQuantity < item.Quantity) { return(Request.CreateResponse(HttpStatusCode.Conflict, LocalizeString("NotEnoughProducts"))); } } CurrentCart.UpdateItem(portalID, storeSettings.SecureCookie, item.ID, item.Quantity); return(Request.CreateResponse(HttpStatusCode.OK)); } catch { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, LocalizeString("Unexpected.Error"))); } }
protected void grdItems_ItemCommand(object source, DataGridCommandEventArgs e) { Page.Validate("vgCart"); if (!Page.IsValid) { return; } int itemID; int quantity; switch (e.CommandName) { case "Update": itemID = (int)grdItems.DataKeys[Convert.ToInt32(e.CommandArgument)]; TextBox txtQuantity = (TextBox)((WebControl)e.CommandSource).Parent.FindControl("txtQuantity"); quantity = int.Parse(txtQuantity.Text); if (quantity > 0) { CurrentCart.UpdateItem(PortalId, StoreSettings.SecureCookie, itemID, quantity); } else { CurrentCart.RemoveItem(itemID); } UpdateCartGrid(); InvokeEditComplete(); break; case "Delete": itemID = (int)grdItems.DataKeys[Convert.ToInt32(e.CommandArgument)]; CurrentCart.RemoveItem(itemID); UpdateCartGrid(); InvokeEditComplete(); break; case "UpdateCart": foreach (DataGridItem dgItem in grdItems.Items) { itemID = (int)grdItems.DataKeys[dgItem.ItemIndex]; quantity = int.Parse(((TextBox)dgItem.FindControl("txtQuantity")).Text); if (quantity > 0) { CurrentCart.UpdateItem(PortalId, StoreSettings.SecureCookie, itemID, quantity); } else { CurrentCart.RemoveItem(itemID); } } UpdateCartGrid(); InvokeEditComplete(); break; default: break; } }