public ToppingsUserControl() { ViewModel = new ToppingsViewModel(); InitializeComponent(); DataContext = ViewModel; }
public MainWindow() { var pizzaDataAccessLayer = new PizzaDataAccess(); pizzaDataAccessLayer.OnPizzaOrdersReceived += HandlePizzaOrdersReceived; ViewModel = new MainWindowViewModel(pizzaDataAccessLayer); InitializeComponent(); DataContext = ViewModel; var toppingCombinationsUserControl = new ToppingCombinationsUserControl(); combosViewModel = toppingCombinationsUserControl.ViewModel; ToppingCombinationsTab.Content = toppingCombinationsUserControl; var toppingsUserControl = new ToppingsUserControl(); toppingsViewModel = toppingsUserControl.ViewModel; ToppingsTab.Content = toppingsUserControl; }
public IActionResult Remove(long id, string toppingIds) { var ids = new List <long>(); if (toppingIds != null) { string[] splitToppingIds = toppingIds.Split(","); splitToppingIds = splitToppingIds.Where(x => x != "").ToArray(); ids = splitToppingIds.Select(long.Parse).ToList(); } List <OrderItem> cart = SessionHelper.GetObjectFromJson <List <OrderItem> >(HttpContext.Session, "cart"); var toppings = _ctx.Topping.Where(r => ids.Contains(r.Id)).ToList(); var toppingsViewModels = new List <ToppingsViewModel>(); toppings.ForEach(x => { var toppingsViewModel = new ToppingsViewModel { Id = x.Id, Name = x.ToppingName, }; toppingsViewModels.Add(toppingsViewModel); }); int index = isExist(id, toppingsViewModels); //returns index in cart where item id = id and item toppings = toppings if (index >= 0) { cart.RemoveAt(index); } else { TempData["ErrorMessage"] = "Something went wrong, please try again."; return(RedirectToAction("OrderMenu", "Cart")); } SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); return(RedirectToAction("OrderMenu", "Cart")); }
public IActionResult OrderMenu(CustomerOrderViewModel request) { if (request.ItemName != "Pizza") { request.SizeId = 0; } if (!ModelState.IsValid) { return(View()); } var menuItems = _cathedralKitchenRepository.GetActiveMenuItems(); var selectedItem = menuItems.First(x => x.Name == request.ItemName); var toppings = _ctx.Topping; var selectedToppingsViewModels = new List <ToppingsViewModel>(); if (request.Toppings != null) { var selectedToppings = toppings?.Where(x => request.Toppings.Contains(x.Id)).ToList(); foreach (var selectedTopping in selectedToppings) { ToppingsViewModel topping = new ToppingsViewModel { Id = selectedTopping.Id, Name = selectedTopping.ToppingName }; selectedToppingsViewModels.Add(topping); } } MenuItemViewModel selectedItemViewModel = new MenuItemViewModel { Id = selectedItem.Id, Name = selectedItem.Name }; if (SessionHelper.GetObjectFromJson <List <OrderItemViewModel> >(HttpContext.Session, "cart") == null) { List <OrderItemViewModel> cart = new List <OrderItemViewModel>(); cart.Add(new OrderItemViewModel { MenuItem = selectedItemViewModel, Toppings = selectedToppingsViewModels, Quantity = request.Quantity, SizeId = request.SizeId }); SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } else { if (!request.IsEmployee && SessionHelper.GetObjectFromJson <List <OrderItemViewModel> >(HttpContext.Session, "cart").Count > 0) { TempData["ErrorMessage"] = "You may only select one item, please remove your previous item to add a new one."; return(RedirectToAction("OrderMenu", "Cart")); } List <OrderItemViewModel> cart = SessionHelper.GetObjectFromJson <List <OrderItemViewModel> >(HttpContext.Session, "cart"); long index = isExist(selectedItemViewModel.Id, selectedToppingsViewModels); if (index != -1) { cart[(int)index].Quantity += request.Quantity; } else { cart.Add(new OrderItemViewModel { MenuItem = selectedItemViewModel, Toppings = selectedToppingsViewModels, Quantity = request.Quantity, SizeId = request.SizeId }); } SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } return(RedirectToAction("OrderMenu", "Cart")); }
public IActionResult OrderMenu() { if (SessionHelper.GetObjectFromJson <long>(HttpContext.Session, "orderId") == 0) { return(RedirectToAction("ShortendOrderView", "Home")); } if (SessionHelper.GetObjectFromJson <List <OrderItemViewModel> >(HttpContext.Session, "cart") == null) { List <OrderItemViewModel> newCart = new List <OrderItemViewModel>(); SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", newCart); } var isEmployee = SessionHelper.GetObjectFromJson <bool>(HttpContext.Session, "isEmployee"); var cart = SessionHelper.GetObjectFromJson <List <OrderItemViewModel> >(HttpContext.Session, "cart"); ViewBag.cart = cart; //FIX ORDER VIEW MODEL var menuItems = _cathedralKitchenRepository.GetActiveMenuItems(); var toppings = _ctx.Topping.Where(i => i.Active == true).Include(y => y.ToppingSystemReference).ThenInclude(x => x.ToppingType); var filteredPizzaToppings = toppings.Where(x => x.Active == true && x.ToppingSystemReference.Any(y => y.ToppingType.Name == "Pizza")); var filteredTacoToppings = toppings.Where(x => x.Active == true && x.ToppingSystemReference.Any(y => y.ToppingType.Name == "Taco")); var todaysSchedule = _ctx.ScheduleConfig.Include(y => y.Community); var filteredTodaysSchedule = todaysSchedule.Where(x => x.Date == DateTime.Today).Where(y => y.Active == true); bool isAuthenticated = User.Identity.IsAuthenticated; var filteredPizzaToppingsViewModel = new List <ToppingsViewModel>(); var filteredTacoToppingsViewModel = new List <ToppingsViewModel>(); var allToppingsViewModel = new List <ToppingsViewModel>(); var filteredScheduleConfigViewModel = new List <ScheduleConfigViewModel>(); foreach (var config in filteredTodaysSchedule) { var communityViewModel = new CommunityViewModel { Id = config.Community.Id, Name = config.Community.Name }; var scheduleViewModel = new ScheduleConfigViewModel { Id = config.Id, Community = communityViewModel, Date = config.Date, Active = config.Active }; filteredScheduleConfigViewModel.Add(scheduleViewModel); } ; foreach (var topping in filteredPizzaToppings) { var toppingTypes = new List <SystemReference>(); foreach (var sysref in topping.ToppingSystemReference) { toppingTypes.Add(sysref.ToppingType); } var toppingViewModel = new ToppingsViewModel { Name = topping.ToppingName, ToppingTypes = toppingTypes, Id = topping.Id }; filteredPizzaToppingsViewModel.Add(toppingViewModel); } ; foreach (var topping in filteredTacoToppings) { var toppingTypes = new List <SystemReference>(); foreach (var sysref in topping.ToppingSystemReference) { toppingTypes.Add(sysref.ToppingType); } var toppingViewModel = new ToppingsViewModel { Name = topping.ToppingName, ToppingTypes = toppingTypes, Id = topping.Id }; filteredTacoToppingsViewModel.Add(toppingViewModel); } ; foreach (var topping in toppings) { var toppingTypes = new List <SystemReference>(); foreach (var sysref in topping.ToppingSystemReference) { toppingTypes.Add(sysref.ToppingType); } var toppingViewModel = new ToppingsViewModel { Name = topping.ToppingName, ToppingTypes = toppingTypes, Id = topping.Id }; allToppingsViewModel.Add(toppingViewModel); } ; var orderView = new CustomerOrderViewModel { MenuItems = menuItems, PizzaToppings = filteredPizzaToppingsViewModel, TacoToppings = filteredTacoToppingsViewModel, AllToppings = allToppingsViewModel, TodaysSchedule = filteredScheduleConfigViewModel, IsEmployee = isEmployee }; return(View(orderView)); }