예제 #1
0
        public ActionResult Index()
        {
            var thisWeekLunches = LunchRepository.GetLunchesForThisWeek().ToList();
            var user            = UserRepository.GetUserByName(User.Identity.Name);

            if (user == null)
            {
                return(RedirectToAction("LogOff", "Account"));
            }
            var model = new EnrollmentModel()
            {
                MyLunches = new HashSet <Guid>(user.Enrollments.Select(e => e.EnrolledForLunchId)),
                Lunches   = thisWeekLunches
            };

            var userRatings = MealRepository.GetUserRatings(user.Id);
            var meals       = MealRepository.GetAll();
            var ratingModel = new RatingModel()
            {
                Meals       = meals,
                UserRatings = userRatings.ToDictionary(m => m.RatedMealId, m => m.Rating)
            };

            model.RatingModel = ratingModel;

            return(View(model));
        }