public IHttpActionResult PostCart_Item(Cart_Item cart_Item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Cart_Item.Add(cart_Item); try { db.SaveChanges(); } catch (DbUpdateException) { if (Cart_ItemExists(cart_Item.ItemID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = cart_Item.ItemID }, cart_Item)); }
public virtual int AddProduct(int productNo, string username, int quantity) { var usercart = db.Cart.SingleOrDefault(x => x.Username == username); if (usercart == null) { var newcart = new Cart(username); db.Cart.Add(newcart); db.SaveChanges(); var newcartitem = new Cart_Item(productNo, quantity, newcart.CartId); db.Cart_Item.Add(newcartitem); db.SaveChanges(); return(newcart.CartId); } else { var usercartitem = db.Cart_Item.SingleOrDefault(p => p.ProductNo == productNo && p.CartId == usercart.CartId); if (usercartitem == null) { var newcartitem = new Cart_Item(productNo, quantity, usercart.CartId); db.Cart_Item.Add(newcartitem); db.SaveChanges(); } else { usercartitem.Quantity += quantity; } db.SaveChanges(); return(usercart.CartId); } }
public async Task <RedirectToActionResult> AddItemToCart([FromRoute] int id, [FromRoute] int?number) { var item = await _itemRepository.GetSingleItem(id); if (item == null) { throw new Exception("Item was not found."); } var user = await _userManager.FindByNameAsync(GetUserName()); var cartItemFromDb = await _cartItemRepository.GetCartItem(id, user.Id); if (cartItemFromDb != null) { var newNumber = cartItemFromDb.Number + (number ?? 1); await _cartItemRepository.EditCartItem(cartItemFromDb.Id, newNumber); } else { var cartItem = new Cart_Item { ItemId = id, UserId = user.Id, Number = number ?? 1, Type = "Tipas" }; await _cartItemRepository.Create(cartItem); } return(RedirectToAction("ItemDetails", "Item")); }
//public ActionResult TextBox(int? Quantity, int? id) //{ // Cart_Item c = db.Cart_Items.Find(id); // Item p = db.Items.Find(c.item_id); // if (Quantity > c.quantity) // { // c.quantity = c.quantity + (Convert.ToInt16(Quantity) - c.quantity); // if (c.quantity > p.QuantityInStock) // { // TempData["Show"] = "There is not enough stock for your request, avaliable stock " + p.QuantityInStock; // return RedirectToAction("Index"); // } // p.QuantityInStock = p.QuantityInStock - c.quantity; // c.price = p.Price * c.quantity; // db.Entry(c).State = EntityState.Modified; // db.Entry(p).State = EntityState.Modified; // db.SaveChanges(); // } // else if (Quantity < c.quantity) // { // c.quantity = c.quantity - (c.quantity - Convert.ToInt16(Quantity)); // p.QuantityInStock = p.QuantityInStock + c.quantity; // c.price = p.Price * c.quantity; // db.Entry(c).State = EntityState.Modified; // db.Entry(p).State = EntityState.Modified; // db.SaveChanges(); // } // return RedirectToAction("ShoppingCart"); //} public ActionResult Checkout(int?Quantity, int?id) { var I = new Item(); Item p = db.Items.Find(I.ItemCode); var C = new Cart_Item(); if (C.quantity > I.QuantityInStock) { TempData["Message"] = "<script>alert('There is not enough stock for your request, avaliable stock ');</script>" + I.QuantityInStock; return(RedirectToAction("Index")); } if (C.quantity > I.QuantityInStock) { TempData["Message"] = "<script>alert('There is not enough stock for your request, avaliable stock ');</script>" + I.QuantityInStock; return(RedirectToAction("Index")); } else if (cart_Service.get_Cart_Items().Count == 0) { ViewBag.Err = "Opps... you should have atleat one cart item, please shop a few items"; return(RedirectToAction("Index")); } else { return(RedirectToAction("HowToGetMyOrder")); } }
public IHttpActionResult PutCart_Item(int ItemID, int CartID, Cart_Item cart_Item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (ItemID != cart_Item.ItemID && CartID != cart_Item.Cart_ID) { return(BadRequest()); } db.Entry(cart_Item).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { //if (!Cart_ItemExists(id)) //{ // return NotFound(); //} //else //{ // throw; //} } return(StatusCode(HttpStatusCode.NoContent)); }
/// <summary> /// Add custom made pizza to Cart /// Then resets custom panel data /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Add_Btn_Copy_Click(object sender, RoutedEventArgs e) { Change_Panel("Home"); Cart_Item Cart_Item = new Cart_Item(); Cart_Item.Size = (Model.Size)Custom_Size_Combo.SelectedItem; Cart_Item.Menu_Item = new Menu_Items(Menu_Items.Count() + 1, "Custom Pizza"); List <Ingredient> ingredients = Ingredients.Where(x => x.Type == Ingredient_Type.Topping && x.Selected).ToList(); ingredients.Add((Ingredient)Custom_Dough_Combo.SelectedItem); List <Menu_Item_Ingredients> menu_Item_Ingredients = new List <Menu_Item_Ingredients>(); foreach (Ingredient item in ingredients) { Menu_Item_Ingredients newIngredient = new Menu_Item_Ingredients(Menu_Items.Count() + 1, item.ID); newIngredient.Menu_Item = Cart_Item.Menu_Item; newIngredient.Ingredient = item; menu_Item_Ingredients.Add(newIngredient); } Cart_Item.Menu_Item.Ingredients = menu_Item_Ingredients; Cart.Cart_Items.Add(Cart_Item); foreach (var topping in Ingredients.Where(x => x.Type == Ingredient_Type.Topping && x.Selected)) { topping.Selected = false; } PrepareCustom(); CheckCart(); }
public async Task <int> Create(Cart_Item cartItem) { await _cartCartItems.AddAsync(cartItem); await _context.SaveChangesAsync(); return(cartItem.Id); }
public async Task <int> Delete(int id) { Cart_Item cartItem = _cartCartItems.Single(c => c.Id == id); _cartCartItems.Remove(cartItem); await _context.SaveChangesAsync(); return(id); }
public IHttpActionResult GetCart_Item(int ItemID, int CartID) { Cart_Item cart_Item = db.Cart_Item.Find(ItemID, CartID); if (cart_Item == null) { return(NotFound()); } return(Ok(cart_Item)); }
public IHttpActionResult DeleteCart_Item(int ItemID, int CartID) { Cart_Item cart_Item = db.Cart_Item.Find(ItemID, CartID); if (cart_Item == null) { return(NotFound()); } db.Cart_Item.Remove(cart_Item); db.SaveChanges(); return(Ok(cart_Item)); }
/// <summary> /// Add specified amount of selected product based on amount on Amount_txt with specified data /// then reset all changed data /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Add_Amount_Btn_Click(object sender, RoutedEventArgs e) { for (int i = 0; i < Convert.ToInt32(Amount_txt.Text); i++) { Cart_Item NewCartItem = new Cart_Item(); NewCartItem.Menu_Item = Menu_Items[Menu_Id]; NewCartItem.RemovedIngredients = Menu_Items[Menu_Id].Ingredients.Where(x => !x.Selected).Select(x => x.Ingredient).ToList(); NewCartItem.Size = (Model.Size)Sizes_combo.SelectedItem; float PizzaDefPrice = Convert.ToInt32(NewCartItem.Menu_Item.Price.Split(' ')[0]); NewCartItem._Price = PizzaDefPrice + (PizzaDefPrice * (NewCartItem.Size.PriceMod / 100)); Cart.Cart_Items.Add(NewCartItem); } Change_Panel("Menu"); CheckCart(); }
public async Task <Cart_Item> Add(Cart_Item cart_Item) { var shopping = await _context.ShoppingSeccions.FirstOrDefaultAsync(x => x.Id == cart_Item.IdShoppingSeccion); var Article = await _context.Articles.FirstOrDefaultAsync(x => x.Id == cart_Item.IdArticle); shopping.Total = shopping.Total + cart_Item.Quantity * Article.Price; _context.ShoppingSeccions.Update(shopping); _context.Cart_Items.Add(cart_Item); await _context.SaveChangesAsync(); return(cart_Item); }
public ActionResult AddToCart(int ProductID) { Cart_Item cart_Item = new Cart_Item(); cart_Item.Cart_ID = Convert.ToInt32(Session["userID"]); cart_Item.ItemID = ProductID; cart_Item.Quantity = 1; Cart_ItemViewModel cim = new Cart_ItemViewModel(); cim.cart_Item = cart_Item; Cart_ItemClient CIC = new Cart_ItemClient(); CIC.Create(cim.cart_Item); return(Content("")); }
public ActionResult UpdateCart(int ProductID, int Quantity) { Cart_Item cart_Item = new Cart_Item(); cart_Item.Cart_ID = Convert.ToInt32(Session["userID"]); cart_Item.ItemID = ProductID; cart_Item.Quantity = Quantity; Cart_ItemViewModel cim = new Cart_ItemViewModel(); cim.cart_Item = cart_Item; Cart_ItemClient CIC = new Cart_ItemClient(); CIC.Edit(cim.cart_Item); return(Content("")); }
public ActionResult add_to_cart(int id) { var UserName = User.Identity.GetUserName(); int qty = 1; var item = item_Service.GetItem(id); Cart_Item ct = new Cart_Item(); if (item != null) { cart_Service.UpdateQuantity(id, qty); //cart_Service.UpdateCart(item.ItemCode,item.Cart_Items.); cart_Service.AddItemToCart(id, UserName); return(RedirectToAction("AllItems")); } else { return(RedirectToAction("Not_Found", "Error")); } }
public async Task <int> AddCartItemAsync(CartItemmodel cartItemmodel) { var CartItemPar = await _dbContext.Cart_Items.FindAsync(cartItemmodel.cart_item_id); if (CartItemPar != null) { throw new ArgumentException("Item already exist"); //Add exceptions middleware } var CartItemobj = new Cart_Item { cart_id = cartItemmodel.cart_id, cart_item_id = cartItemmodel.cart_item_id, item_id = cartItemmodel.item_id, quantity = cartItemmodel.quantity, price = cartItemmodel.price, }; await _dbContext.Cart_Items.AddAsync(CartItemobj); return(await _dbContext.SaveChangesAsync()); }
public IActionResult AddingToOrder(int productid, int quantity, int customerid) { TempData["CustomerId"] = TempData["CustomerId"]; List <Cart_Item> CartItems = _context.cart_items.Where(c => c.customer_id == customerid).Where(c => c.product_id == productid).ToList(); if (CartItems.Count() > 0) { Cart_Item CurrentCartItem = CartItems.First(); CurrentCartItem.product_quantity += quantity; _context.SaveChanges(); return(RedirectToAction("AllOrders")); } else { Cart_Item InstallingCartItem = new Cart_Item(); InstallingCartItem.customer_id = customerid; InstallingCartItem.product_id = productid; InstallingCartItem.product_quantity = quantity; _context.cart_items.Add(InstallingCartItem); _context.SaveChanges(); return(RedirectToAction("AllOrders")); } }