public List <Meal> GetAllMeals() { try { return(MealManager.GetAllMeals()); } catch { return(new List <Meal>()); } }
// // GET: /Admin/Meal/ public ActionResult Index(string Page) { var todaysTotal = mealManager.GetAllMeals().Where(x => x.MealDate.ToShortDateString() == DateTime.Now.ToShortDateString()).ToList(); var todaysTotalPaging = mealManager.GetAllMeals().Where(x => x.MealDate.ToShortDateString() == DateTime.Now.ToShortDateString()).ToList(); ViewBag.Exist = todaysTotal.Count(); int TodaysTotalLunchMeal = todaysTotal.Select(x => x.Lunch).Sum(); ViewBag.TodaysTotalLunchMeal = TodaysTotalLunchMeal; int TodaysTotalDinnerMeal = todaysTotal.Select(x => x.Dinner).Sum(); ViewBag.TodaysTotalDinnerMeal = TodaysTotalDinnerMeal; int TodaysTotalDinnerGuestMeal = todaysTotal.Select(x => x.DinnerGuestMeal).Sum(); ViewBag.TodaysTotalDinnerGuestMeal = TodaysTotalDinnerGuestMeal; int TodaysTotalLunchGuestMeal = todaysTotal.Select(x => x.LunchGuestMeal).Sum(); ViewBag.TodaysTotalLunchGuestMeal = TodaysTotalLunchGuestMeal; int totalMeal = TodaysTotalLunchMeal + TodaysTotalDinnerMeal + TodaysTotalDinnerGuestMeal + TodaysTotalLunchGuestMeal; ViewBag.totalMeal = totalMeal; var studentLunchsGuestMeal = mealManager.GetAllMeals().Select(x => new { x.StudentId, x.LunchGuestMeal }).GroupBy(x => x.StudentId).ToList(); ViewBag.studentLunchsGuestMeal = studentLunchsGuestMeal; ViewBag.TotalPages = Math.Ceiling(todaysTotalPaging.Count() / 5.0); int page = int.Parse(Page == null ? "1" : Page); ViewBag.Page = page; todaysTotal = todaysTotalPaging.Skip((page - 1) * 5).Take(5).ToList(); ViewBag.EligibleLunchId = mealManager.GetAllMeals().Where(x => x.MealDate.ToShortDateString() == DateTime.Now.ToShortDateString() && x.Lunch != 0).Select(x => x.StudentId); ViewBag.EligibleDinnerId = mealManager.GetAllMeals().Where(x => x.MealDate.ToShortDateString() == DateTime.Now.ToShortDateString() && x.Dinner != 0).Select(x => x.StudentId); return(View(todaysTotal)); }