public ActionResult Edit(EditArguments editArgs) { if (this.ModelState.IsValid) { var shoppingCart = this.GetShoppingCart(); int bookId = editArgs.BookId; int quantity = editArgs.Quantity; if (quantity > 0) { var existingLine = shoppingCart.Lines.Single(l => l.Book.Id == bookId); existingLine.Quantity = quantity; } else { shoppingCart.RemoveLineItem(bookId); } return(this.RedirectToAction("Index")); } else { return(this.Index()); } }
//[ValidateInput(true)] public ActionResult Edit(EditArguments editArgs) { if (!ModelState.IsValid) { return(Index()); } var shoppingCart = GetShoppingCart(); int bookId = editArgs.BookId; int quantity = editArgs.Quantity; if (quantity > 0) { var existingLine = shoppingCart.Lines.Single(l => l.Book.Id == bookId); existingLine.Quantity = quantity; } else { shoppingCart.RemoveLineItem(bookId); } HttpContext.Session.SetString(CartSessionKey, JsonConvert.SerializeObject(shoppingCart)); return(RedirectToAction("Index")); }
public ActionResult Edit(EditArguments editArgs) { if (!ModelState.IsValid) return Index(); var shoppingCart = GetShoppingCart(); var existingLine = shoppingCart.Lines.Single(l => l.Book.Id == editArgs.BookId); existingLine.Quantity = editArgs.Quantity; return RedirectToAction("Index"); }
//[ValidateInput(true)] public ActionResult Edit(EditArguments editArgs) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } _shoppingCartLogic.EditBookInCart(HttpContext.Session, editArgs); return(RedirectToAction("Index")); }
public void SetQuantity(string bookTitle, int quantity) { var book = _catalogContext.ReferenceBooks.GetById(bookTitle); using var controller = GetShoppingCartController(); var editArguments = new EditArguments { BookId = book.Id, Quantity = quantity }; controller.Edit(editArguments); }
public ActionResult Edit(EditArguments editArgs) { if (!ModelState.IsValid) { return(Index()); } var shoppingCart = GetShoppingCart(); var existingLine = shoppingCart.Lines.Single(l => l.Book.Id == editArgs.BookId); existingLine.Quantity = editArgs.Quantity; return(RedirectToAction("Index")); }
public void EditBookInCart(ISession session, EditArguments editArgs) { var shoppingCart = GetShoppingCart(session); int bookId = editArgs.BookId; int quantity = editArgs.Quantity; if (quantity > 0) { var existingLine = shoppingCart.Lines.Single(l => l.Book.Id == bookId); existingLine.Quantity = quantity; } else { shoppingCart.RemoveLineItem(bookId); } session.SetString(CartSessionKey, JsonConvert.SerializeObject(shoppingCart)); }
public ActionResult Edit(EditArguments editArgs) { if (!ModelState.IsValid) return Index(); var shoppingCart = GetShoppingCart(); int bookId = editArgs.BookId; int quantity = editArgs.Quantity; if (quantity > 0) { var existingLine = shoppingCart.Lines.Single(l => l.Book.Id == bookId); existingLine.Quantity = quantity; } else shoppingCart.RemoveLineItem(bookId); return RedirectToAction("Index"); }