Ejemplo n.º 1
0
        public async Task <IActionResult> Index(MenuViewModel model)
        {
            if (ModelState.IsValid)
            {
                /*String selectedVegetables = "";
                 * foreach (VegWithChkBxViewModel vegWithChkBx in model.ListVegetablesWithCheckBoxes)
                 * {
                 *  if(vegWithChkBx.Checked == true)
                 *  {
                 *      selectedVegetables += vegWithChkBx.Id + "/";
                 *  }
                 * }
                 * Debug.WriteLine("-------------- selectedSandwich : " + model.SelectedSandwich);
                 * Debug.WriteLine("-------------- selectedVegetables : " + selectedVegetables);
                 */
                if (model.SelectedSandwich != null)
                {
                    OrderLine newOrderLine = new OrderLine {
                        Quantity = 1, VegetablesPrice = model.VegetablesPrice, OrderLineVegetables = new List <OrderLineVegetable>()
                    };

                    Sandwich selectedSandwich = model.ListSandwiches.Where(s => s.Id == Int32.Parse(model.SelectedSandwich)).First();
                    newOrderLine.Sandwich = selectedSandwich;

                    foreach (VegWithChkBxViewModel vegWithChkBx in model.ListVegetablesWithCheckBoxes)
                    {
                        if (vegWithChkBx.Checked == true)
                        {
                            VegWithChkBxViewModel selectedVegWithChkBx = model.ListVegetablesWithCheckBoxes.Where(v => v.Id == vegWithChkBx.Id).First();
                            Vegetable             selectedVegetable    = new Vegetable {
                                Id = selectedVegWithChkBx.Id, Name = selectedVegWithChkBx.Name, Description = selectedVegWithChkBx.Description
                            };
                            newOrderLine.AddVegetable(selectedVegetable);
                        }
                    }

                    AddOrderLineToCartSession(newOrderLine);
                }
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            RemoteCall      remoteCaller = RemoteCall.GetInstance();
            CommWrap <Menu> responseMenu = await remoteCaller.GetMenu();

            MenuViewModel menuViewModel = new MenuViewModel();

            if (responseMenu.RequestStatus == 1)
            {
                Menu menu = responseMenu.Content;

                menuViewModel.ListSandwiches   = menu.Sandwiches.ToList();
                menuViewModel.SelectedSandwich = null;

                menuViewModel.VegetablesPrice = menu.VegetablesPrice;
                List <VegWithChkBxViewModel> listVegWithChkBxViewModels = new List <VegWithChkBxViewModel>();
                foreach (Vegetable veg in menu.Vegetables)
                {
                    VegWithChkBxViewModel vegWithChkBxViewModel = new VegWithChkBxViewModel {
                        Checked = false, Id = veg.Id, Name = veg.Name, Description = veg.Description
                    };
                    listVegWithChkBxViewModels.Add(vegWithChkBxViewModel);
                }
                menuViewModel.ListVegetablesWithCheckBoxes = listVegWithChkBxViewModels;

                return(View("Index", menuViewModel));
            }
            AddErrors("Le menu n'a pu être chargé correctement");

            return(View("Index", menuViewModel));

            /*string id = _userManager.GetUserId(User);
             *
             * if (id == null)
             * {
             *  return NotFound();
             * }
             *
             * var employee = await _context.Employees
             *                  .Include(emp => emp.Orders)
             *                      .ThenInclude(order => order.OrderLines)
             *                          .ThenInclude(orderLine => orderLine.Sandwich)
             *                  .Include(emp => emp.Orders)
             *                      .ThenInclude(order => order.OrderLines)
             *                          .ThenInclude(orderLine => orderLine.OrderLineVegetables)
             *                              .ThenInclude(orderLineVegetable => orderLineVegetable.Vegetable)
             *                  .SingleOrDefaultAsync(m => m.Id == id);
             *
             */

            //string id = _userManager.GetUserId(User);

            //Employee emp = _context.Employees.Where(e => e.Id == id).FirstOrDefault();

            //Order order = GetCurrentOrder(emp);

            //string serializable = HttpContext.Session.GetString("cart");

            //Order order = JsonConvert.DeserializeObject<Order>(serializable);

            //return View(order.OrderLines.ToList());
        }