public ActionResult AddBook(int id, AddToCartViewModel model) { var book = db.Books.Where(q => q.DeletedAt == null && q.Id == id).FirstOrDefault(); if (book == null) { return(NotFound()); } CartViewModel cart = GetCart(); CartItemViewModel cartItem = new CartItemViewModel() { Id = book.Id, Name = book.Name, Slug = book.Slug, Quantity = model.Quantity <= 0 ? 1 : model.Quantity, Price = book.Price, Discount = book.Discount, Image = book.DecodedImages()[0] }; cart.UpdateItem(cartItem); if (cart.GetItem(book.Id).Quantity > book.Quantity) { return(BadRequest("NOT_ENOUGH_BOOK")); } SaveCart(cart); return(Success(cart)); }