public ActionResult Create(CartCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateCartService(); var productService = CreateProductService(); productService.GetProductById(model.ProductId); if (service.CreateCart(model)) { TempData["SaveResult"] = "Your cart is up to date!"; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Cart could not be updated."); return(View(model)); }
public bool AddToCart(BookDetail book) { CartCreate cartCreate = new CartCreate() { BookId = book.BookId, Title = book.Title, Price = book.Price, Quantity = 1, ItemTotal = 1, OwnerId = _userId }; return(CreateCart(cartCreate)); }
//Not Real World Usage //[Route("api/cart/purchase")] //public IHttpActionResult GetCartByPurchaseDate([FromBody] DateTime date) //{ // CartService cartService = CreateCartService(); // var cart = cartService.GetCartByPurchaseDate(date); // return Ok(cart); //} public IHttpActionResult Post(CartCreate cart) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CartService cartService = CreateCartService(); if (!cartService.CreateCart(cart)) { return(InternalServerError()); } return(Ok()); }
public bool CreateCart(CartCreate model) { var entity = new Cart() { PlantId = model.PlantId, OwnerId = _userId, }; using (var ctx = new ApplicationDbContext()) { ctx.Carts.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateCart(CartCreate model) { var entity = new Cart() { CartUser = _cartId, GiftBoxId = model.GiftBoxId, ItemCount = model.ItemCount, PurchaseDate = DateTime.Now, CustomerId = model.CustomerId, }; using (var ctx = new ApplicationDbContext()) { ctx.Carts.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateCart(CartCreate model) { using (var ctx = new ApplicationDbContext()) { var cart = new Cart() { OwnerId = _userId, CartId = model.CartId, BookId = model.BookId, Quantity = model.Quantity, Price = model.Price, ItemTotal = model.ItemTotal }; cart.ItemTotal = cart.Price * Convert.ToDecimal(model.Quantity); ctx.Cart.Add(cart); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(CartCreate model) { if (!ModelState.IsValid) { return(View(model)); } CartService service = CreateCartService(); if (service.CreateCart(model)) { TempData["SaveResult"] = "Your cart has been successully updated."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "An error was encountered. Your cart was not updated."); return(View(model)); }
public ActionResult Create(CartCreate model) { if (ModelState.IsValid) { return(View(model)); } var service = CreateCartService(); if (service.CreateCart(model)) { TempData["SaveResult"] = "Your cart was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Cart could not be created."); return(View(model)); }