public async Task <IActionResult> Edit(int id, [Bind("ID,Chcees,Pepperoni,Onions,Bacon,Sausage,PizzaModelID")] ExtraIngredientsModel extraIngredientsModel) { if (id != extraIngredientsModel.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(extraIngredientsModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExtraIngredientsModelExists(extraIngredientsModel.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["PizzaModelID"] = new SelectList(_context.Pizza, "ID", "ID"); return(View(extraIngredientsModel)); }
public async Task <IActionResult> Create([Bind("ID,Chcees,Pepperoni,Onions,Bacon,Sausage,PizzaModelID")] ExtraIngredientsModel extraIngredientsModel) { if (ModelState.IsValid) { _context.Add(extraIngredientsModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PizzaModelID"] = new SelectList(_context.Pizza, "ID", "ID"); return(View(extraIngredientsModel)); }
public List <ExtraIngredientsModel> ValidateExtraIngredients(List <string> extraIngredients) { foreach (var product in extraIngredients) { if (String.IsNullOrWhiteSpace(product) || !_menu.ExtraIngredientsWithPrices .Any(p => p.Key .Contains(product .ToLower() .Trim())) ) { throw new ArgumentException("Invalid input for Extra Ingredients. Ingredients is not availible on _menu"); } var extraIngredient = new ExtraIngredientsModel() { Name = product.ToLower().Trim(), Price = _menu.Prices[product.ToLower().Trim()], }; ValidExtraIngredients.Add(extraIngredient); } return(ValidExtraIngredients); }
public IActionResult Save(CustomerModel customerModel, PizzaModel pizzaModel, ExtraIngredientsModel extraIngredients, OrderModel orderModel) { if (customerModel.ID == 0) { _context.Customer.Add(customerModel); _context.ExtraIngredients.Add(extraIngredients); var customerID = customerModel.ID; orderModel.CustomerModelID = customerID; _context.Order.Add(orderModel); pizzaModel.OrderModelID = orderModel.ID; pizzaModel.ExtraIngredientsModelID = extraIngredients.ID; _context.Pizza.Add(pizzaModel); } else { throw new System.Exception("Not implemented"); } _context.SaveChanges(); return(RedirectToAction("Index", "CustomerModels")); }