예제 #1
0
        public async Task <IActionResult> Create(IFormCollection frm, PizzaVM vm)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (!await _pizzaRepo.CreatePizzaAsync(vm.Pizza, vm.SelectedToppingsString, vm.SelectedSizesString))
                    {
                        throw new Exception();
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    ModelState.AddModelError("CreateError", "Creating pizza failed");
                    return(View(new PizzaVM(_pizzaRepo, _toppingRepo, _sizeRepo, vm.Pizza)));
                }
            }
            else
            {
                vm.SelectedSizes = await _pizzaRepo.GetPizzaSizes(vm.Pizza.Name);

                vm.SelectedToppings = await _pizzaRepo.GetPizzaToppings(vm.Pizza.Name);

                return(View(vm));
            }
        }
예제 #2
0
        public async Task <ActionResult <List <SizeDTO> > > GetPizzaSizeAsync(string name)
        {
            var sizes = await _pizzaRepo.GetPizzaSizes(name);

            List <SizeDTO> sizesdto = new List <SizeDTO>();

            sizes.ForEach(t => sizesdto.Add(_mapper.Map <SizeDTO>(t)));
            return(sizesdto);
        }
예제 #3
0
        public PizzaVM(IPizzaRepo pizzaRepo, IToppingRepo toppingRepo, ISizeRepo sizeRepo, Pizza pizza)
        {
            Pizza = pizza;

            SelectedToppings = pizzaRepo.GetPizzaToppings(pizza.Name).Result;
            Toppings         = new MultiSelectList(toppingRepo.GetToppingsAsync().Result, "ToppingId", "Name", SelectedToppings);

            SelectedSizes = pizzaRepo.GetPizzaSizes(pizza.Name).Result;
            Sizes         = new MultiSelectList(sizeRepo.GetSizesAsync().Result, "SizeId", "Name", SelectedSizes);
        }
예제 #4
0
        public OrderVM(Order order, IOrderRepo orderRepo, IPizzaRepo pizzaRepo)
        {
            Order = order;

            SelectedPizzas = orderRepo.GetPizzasAsync(order.OrderId).Result;
            Pizzasorder    = new MultiSelectList(pizzaRepo.GetPizzasAsync().Result, "PizzaId", "Name", SelectedPizzas);

            foreach (var pizza in pizzaRepo.GetPizzasAsync().Result)
            {
                Dictionary <Pizza, List <Size> > PizzaSizes = new Dictionary <Pizza, List <Size> >();
                PizzaSizes.Add(pizza, pizzaRepo.GetPizzaSizes(pizza.Name).Result);
            }
        }
예제 #5
0
        public PizzaOrdersVM(IOrderRepo orderRepo, IPizzaRepo pizzaRepo, Order order)
        {
            Order = order;

            SelectedPizzas      = orderRepo.GetPizzasAsync(order.OrderId).Result;       //Voor de pizza's in een order
            SelectedOrderPizzas = orderRepo.GetOrderPizzasAsync(order.OrderId).Result;  //Voor de prijs uit de tussentabel te halen
            SelectedOrderSizes  = orderRepo.GetOrderSizes(order.OrderId).Result;        //Om de grootte van de pizza op te halen

            Pizzas = new MultiSelectList(pizzaRepo.GetPizzasAsync().Result, "PizzaId", "Name", SelectedPizzas);

            PizzaSizes = new Dictionary <string, SelectList>();

            foreach (var pizza in pizzaRepo.GetPizzasAsync().Result)
            {
                PizzaSizes.Add(pizza.Name, new SelectList(pizzaRepo.GetPizzaSizes(pizza.Name).Result, "SizeId", "Name", SelectedPizzaSizes));
            }
        }