public async Task <IActionResult> PutFood(int id, Food food) { if (id != food.Id) { return(BadRequest()); } _context.Entry(food).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FoodExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> AddToCart(int id) { var exisingFood = await _context.PurchaseOrder.FirstOrDefaultAsync(m => m.FoodId == id); if (exisingFood != null) { exisingFood.Quantity++; } else { PurchaseOrder purchaseOrder = new PurchaseOrder() { Customer = "anagha", Quantity = 1, FoodId = id, DateCreated = DateTime.UtcNow }; _context.Add(purchaseOrder); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("Id,Name,Description")] Category category) { if (ModelState.IsValid) { category.CreatedDate = DateTime.UtcNow; _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("Id,Name,Description,Price,Quantity,CategoryId,Ingredients")] Food food) { if (ModelState.IsValid) { _context.Add(food); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Id", food.CategoryId); return(View(food)); }