public ActionResult UpdateCart(UpdateCartDto postModel) { try { using (var uow = _uowProvider.Create()) { var store = CurrentPage.GetStore(); var order = _sessionManager.GetOrCreateCurrentOrder(store.Id) .AsWritable(uow); foreach (var orderLine in postModel.OrderLines) { order.WithOrderLine(orderLine.Id) .SetQuantity(orderLine.Quantity); } _orderService.SaveOrder(order); uow.Complete(); } } catch (ValidationException ex) { ModelState.AddModelError("productReference", "Failed to update cart"); return(CurrentUmbracoPage()); } TempData["cartUpdated"] = "true"; return(RedirectToCurrentUmbracoPage()); }
public async Task <IActionResult> updateCart(int userId, int id, string currentRowVersion, [FromBody] JsonPatchDocument <UpdateCartDto> patchDoc) { if (patchDoc == null) { return(BadRequest()); } var itemToUpdate = _context.Carts.Where(c => c.CardId == userId && c.Id == id).FirstOrDefault(); if (itemToUpdate == null) { return(NotFound()); } string dbRowVersion = Common.ByteArrayToString(itemToUpdate.RowVersion); if (dbRowVersion == currentRowVersion) { return(BadRequest("Data has updated, please refresh page!")); } var itemToPatch = new UpdateCartDto() { quantity = itemToUpdate.Quantity, note = itemToUpdate.Note }; patchDoc.ApplyTo(itemToPatch, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } itemToUpdate.Quantity = itemToPatch.quantity; itemToUpdate.Note = itemToPatch.note; await _context.SaveChangesAsync(); return(NoContent()); }
public IHttpActionResult UpdateCart(UpdateCartDto cartDto) { HttpSessionState session = HttpContext.Current.Session; var carts = session["cart"] as List <CartViewModel>; if (carts == null) { return(NotFound()); } for (var i = 0; i < carts.Count; i++) { carts[i].Quantity = cartDto.Quantity[i]; } if (cartDto.ChkCartRemove != null) { carts.Where(c => cartDto.ChkCartRemove.Contains(c.ProductId)).ToList().ForEach(c => carts.Remove(c)); } session["cart"] = carts; return(Ok()); }
public ActionResult UpdateCart(UpdateCartDto postModel) { try { using (var uow = _uowProvider.Create()) { var store = CurrentPage.GetStore(); var order = _sessionManager.GetOrCreateCurrentOrder(store.Id) .AsWritable(uow); foreach (var orderLine in postModel.OrderLines) { order.WithOrderLine(orderLine.Id) .SetQuantity(orderLine.Quantity); } _orderService.SaveOrder(order); uow.Complete(); } } catch (ValidationException ex) { switch (ex.Message) { case "IsProductAvailableForPurchase": ModelState.AddModelError("IsProductAvailableForPurchase", Umbraco.GetDictionaryValue("Checkout.IsProductAvailableForPurchaseError")); break; } return(CurrentUmbracoPage()); } TempData["cartUpdated"] = "true"; return(RedirectToCurrentUmbracoPage()); }