public async Task <IActionResult> Edit(int id, [Bind("IdOrder,IdItem,Quantity")] ItemsOrdered itemsOrdered) { if (id != itemsOrdered.IdOrder) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(itemsOrdered); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ItemsOrderedExists(itemsOrdered.IdOrder)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(itemsOrdered)); }
public async Task <IActionResult> Create([Bind("IdOrder,IdItem,Quantity")] ItemsOrdered itemsOrdered) { if (ModelState.IsValid) { _context.Add(itemsOrdered); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(itemsOrdered)); }
// GET: Items/Details/5 public async Task <IActionResult> addBasket(int?id, string price) { int OrderID = Convert.ToInt32(Request.Cookies["IdOrder"]); //Cheak if adding new item to basket. if (id == 0 || _context.ItemsOrdered.Find(OrderID, id) != null || id == null) { return(View(await _context.Items.ToListAsync())); } //Pull information on order and customers, to update db with new items. _context.Orders.Find(OrderID).Price = price; ItemsOrdered Newitem = new ItemsOrdered(); Newitem.IdItem = Convert.ToInt32(id); Newitem.IdOrder = OrderID; Newitem.Quantity = 1; _context.ItemsOrdered.Add(Newitem); if (ModelState.IsValid) { _context.SaveChanges(); } string cookieValue = Request.Cookies["O"]; if (cookieValue != null) { int value = Convert.ToInt32(cookieValue); value += 1; cookieValue = value.ToString(); } else { cookieValue = "1"; } Response.Cookies.Append(id.ToString(), cookieValue); ViewBag.itemID = id; if (Request.Cookies["uniqueID"] == null) { return(RedirectToAction("Login", "Home")); } return(View(await _context.Items.ToListAsync())); }