public IActionResult SelectActiveToppings(SelectToppingViewModel selectedItems) { //var items = _ctx.Topping; var items = _ctx.Topping.Where(i => i.Active == true).Include(y => y.ToppingSystemReference).ThenInclude(x => x.ToppingType); List <Topping> allItems = items.ToList(); foreach (var x in allItems) { if (selectedItems.ToppingNames.Contains(x.ToppingName)) { x.Active = true; foreach (var toppingSysRef in x.ToppingSystemReference) { toppingSysRef.Active = true; } } else { x.Active = false; foreach (var toppingSysRef in x.ToppingSystemReference) { toppingSysRef.Active = false; } } } ; _cathedralKitchenRepository.UpdateToppings(allItems); return(Redirect("SelectActiveToppings")); }
public IActionResult SelectActiveToppings() { var toppings = _ctx.Topping; var distinctToppings = toppings.DistinctBy(x => x.ToppingName).ToList(); var toppingsViewModel = new SelectToppingViewModel { Toppings = distinctToppings, }; return(View(toppingsViewModel)); }