/** WERKT **/ public async Task <IActionResult> Order() { if (User.Identity.IsAuthenticated) { // Fetching Dishes into local JArray JArray dishArray = await DishMethods.GetDishes(); // Converting JArray items to Collection object of given type List <Dish> allDishes = dishArray.ToObject <List <Dish> >(); Dictionary <int, List <Meal> > dict = new Dictionary <int, List <Meal> >(); foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek))) { dict.Add((int)day, new List <Meal>()); } // Parsing the given dates through TempData DateTime startDate = DateTime.Parse(TempData["start"].ToString()); DateTime endDate = DateTime.Parse(TempData["end"].ToString()); if (MealMethods.Week(startDate) == MealMethods.Week(endDate)) { // For each meal in retrieved meals add it to the dictionary by specific day of week foreach (var meal in await MealMethods.GetAllWeekMeals(startDate)) { var day = meal.DateValid.DayOfWeek; dict[(int)day].Add(meal); } List <MealDishes> mealDishes = new List <MealDishes>(); var dishes = _mealService.MealDish.ToList(); foreach (var item in dishes) { mealDishes.Add(item); } ViewBag.MealDishes = mealDishes; ViewBag.Dishes = allDishes; ViewBag.Dictionary = dict; return(View()); } ModelState.AddModelError(string.Empty, "Application error: could not load the meals"); return(View()); } else { return(RedirectToAction("Login", "Account")); } }
public IActionResult ChooseWeek(ChooseWeekViewModel model) { if (User.Identity.IsAuthenticated) { if (ModelState.IsValid) { bool nextWeekStart = MealMethods.Week(model.Start) != (MealMethods.Week(DateTime.Now.Date) + 1) ? true : false; bool nextWeekEnd = MealMethods.Week(model.End) != (MealMethods.Week(DateTime.Now.Date) + 1) ? true : false; // To check if the begin date / end date is in the same week if (MealMethods.Week(model.Start) != MealMethods.Week(model.End)) { ModelState.AddModelError(string.Empty, "The given start date and end date were not in the same week!"); return(View()); } else if (model.Start > model.End) { ModelState.AddModelError(string.Empty, "You cannot choose an end data that is passed the given start date!"); return(View()); } //else if (nextWeekStart && nextWeekEnd) //{ // ModelState.AddModelError(string.Empty, "You cannot order for this week only for the next week after the current week!"); // return View(); //} else if (model.Start.DayOfWeek != DayOfWeek.Monday || model.End.DayOfWeek != DayOfWeek.Sunday) { ModelState.AddModelError(string.Empty, "You can only order for a full week!"); return(View()); } else { TempData["start"] = model.Start; TempData["end"] = model.End; return(RedirectToAction("Order", "Order")); } } ModelState.AddModelError(string.Empty, "Please fill in both dates to continue"); return(View()); } else { return(RedirectToAction("Login", "Account")); } }