public IActionResult Pizza(int id) { List <Pizza> pizzas = repository.GetPizzasFromLocation(id); List <PizzaModel> pizzaModels = new List <PizzaModel>(); List <ToppingsModel> toppModels = new List <ToppingsModel>(); List <Domain.Model.Toppings> toppings = repository.GetToppings(Convert.ToInt32(id)); int userId = Convert.ToInt32(TempData["user"]); bool validateDate = Lib.Handler.OrderHandler.CheckOrderDateTime(repository.GetOrders(), repository.GetLocation(id), repository.GetUser(userId)); TempData["user"] = userId; if (validateDate == true) { if (pizzas != null) { foreach (Domain.Model.Toppings topp in toppings) { ToppingsModel topModel = new ToppingsModel() { TopId = topp.TopId, TName = topp.TName, T_Type = topp.T_Type, Cost = topp.Cost }; toppModels.Add(topModel); } foreach (Pizza pizza in pizzas) { PizzaModel pizzaModel = new PizzaModel() { PizzaId = pizza.PizzaId, PType = pizza.PType, PSize = pizza.PSize, Crust = pizza.Crust, PPrice = pizza.PPrice, SLocationId = pizza.SLocationId }; pizzaModels.Add(pizzaModel); } ViewBag.toppingsModel = toppModels; return(View(pizzaModels)); } else { } } return(RedirectToAction("Message")); }
public void ConvertSpecial(PizzaViewModel pizzaViewModel, PizzaStoreDBContext _db) { var CR = new CrustRepository(_db); var SR = new SizeRepository(_db); var PR = new PizzaRepository(_db); var TR = new ToppingRepository(_db); var OR = new OrderRepository(_db); var UR = new UserRepository(_db); var STR = new StoreRepository(_db); var PF = new PizzaFactory(); var tempSpecialty = PF.Create(); tempSpecialty = PR.Get(SelectedPizza); var tempPizza = PF.Create(); tempPizza.Name = SelectedPizza; tempPizza.Description = tempSpecialty.Description; tempPizza.Size = SR.Get(pizzaViewModel.Size); tempPizza.Crust = CR.Get(pizzaViewModel.Crust); tempPizza.Toppings = new List <ToppingsModel>(); tempPizza.SpecialPizza = true; foreach (var t in tempSpecialty.Toppings) { var tempTopping = new ToppingsModel() { Name = t.Name, Description = t.Description }; tempPizza.Toppings.Add(tempTopping); TR.Add(tempTopping); } var cart = OR.GetCurrentOrder(); var OF = new OrderFactory(); if (cart != null) { OR.AddPizza(cart.Id, tempPizza); } else { cart = OF.Create(); cart.Pizzas.Add(tempPizza); cart.CurrentOrder = true; OR.UpdateCurrentOrder(cart); var tempUser = UR.Get(User); UR.AddOrder(tempUser.Id, cart); var tempStore = STR.Get(Store); STR.AddOrder(tempStore.Id, cart); } }
public IActionResult SaveTopping([FromBody] ToppingsModel topping) { Logger.LogDebug("Entering SaveTopping"); try { ToppingsRepository.AddNewToppingType(topping); return(Created($"api/toppings/{topping.Id}", topping)); } catch (Exception ex) { LogException(ex); return(StatusCode(500, "There was an error when trying to save the topping.")); } }
public void UpdateToppingQuantity(string toppingName, decimal quantity) { var topping = GetByName(toppingName); if (null != topping) { topping.Quantity = quantity; Update(DatabaseName, Collection, topping); } else { ToppingsModel model = new ToppingsModel { Name = toppingName, Quantity = quantity }; Insert(DatabaseName, Collection, model); } }
public void ConvertRegular(PizzaViewModel pizzaViewModel, PizzaStoreDBContext _db) { var UR = new UserRepository(_db); var STR = new StoreRepository(_db); var OR = new OrderRepository(_db); var CR = new CrustRepository(_db); var SR = new SizeRepository(_db); var PR = new PizzaRepository(_db); var TR = new ToppingRepository(_db); var PF = new PizzaFactory(); List <ToppingsModel> TM = new List <ToppingsModel>(); SelectedToppings = new List <CheckBoxTopping>(); foreach (var t in Toppings2) { if (t.IsSelected) { SelectedToppings.Add(t); } } foreach (var t in SelectedToppings) { var throwaway = TR.Get(t.Text); var tempTopping = new ToppingsModel() { Name = throwaway.Name, Description = throwaway.Description }; TM.Add(tempTopping); } //TM.Add(TR.Get(Topping)); var tempPizza = PF.Create(); tempPizza.Name = "custom"; tempPizza.Description = "custom"; tempPizza.Size = SR.Get(pizzaViewModel.Size); tempPizza.Crust = CR.Get(pizzaViewModel.Crust); tempPizza.Toppings = new List <ToppingsModel>(); tempPizza.Toppings = TM; tempPizza.SpecialPizza = false; var cart = OR.GetCurrentOrder(); var OF = new OrderFactory(); if (cart != null) { OR.AddPizza(cart.Id, tempPizza); } else { cart = OF.Create(); cart.Pizzas = new List <PizzaModel>(); cart.Pizzas.Add(tempPizza); cart.CurrentOrder = true; OR.UpdateCurrentOrder(cart); var tempUser = UR.Get(User); UR.AddOrder(tempUser.Id, cart); var tempStore = STR.Get(Store); STR.AddOrder(tempStore.Id, cart); } }
public void AddNewToppingType(ToppingsModel topping) { Insert(DatabaseName, Collection, topping); }