Exemple #1
0
        public IActionResult Index()
        {
            var date        = DateTime.Now.Date;
            var reviewToken = DateTime.Now.GetHashCode();
            var model       = new MenuViewModel()
            {
                SelectedDate = date, ReviewToken = reviewToken.GetHashCode()
            };
            var menu = lunchMenuRepo.GetById(date.GetHashCode());


            if (menu == null)
            {
                var interactor = new CreateMenuInteractor(lunchMenuRepo, lunchMenuLookupRepo);
                var response   = interactor.Handle(new Core.Contracts.Dtos.CreateMenuRequest(date));
                if (response.Result)
                {
                    menu = lunchMenuRepo.GetById(response.MenuId.Value);
                }
                else
                {
                    model.Errors = response.Messages;
                }
            }
            if (menu != null)
            {
                model.NumberOfReviews = reviewRepo.GetAllMenuReviews(menu.Id).Count();
                model.Id         = menu.Id;
                model.MenuRating = menu.AverageMenuReviewScore;
                model.Courses    = menu.Courses.Select(ld =>
                                                       new CourseViewModel()
                {
                    Id   = ld.Id,
                    Name = ld.Name,
                    ReviewScoreAverage = ld.AverageCourseReviewScore,
                }
                                                       ).ToList();
            }
            return(View(model));
        }