コード例 #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));
        }
コード例 #2
0
ファイル: RateMenuInteractor.cs プロジェクト: kgtrue/lunchApp
        public RateMenuResponse Handle(RateMenuRequest message)
        {
            var lunchMenu = menuRepo.GetById(message.MenuId);
            var errors    = new List <string>();

            message.ReviewScores.ToList().ForEach(review =>
            {
                if (!lunchMenu.AddUpdateReview(review.courseId, message.RevierwToken, review.reviewScore))
                {
                    errors.Add($"Unable to register review for cource with id: {review.courseId} and score {review.reviewScore}");
                }
            });
            menuRepo.SaveUpdate(lunchMenu);
            return(new RateMenuResponse(!errors.Any(), errors));
        }
コード例 #3
0
        public CreateMenuResponse Handle(CreateMenuRequest message)
        {
            var errors          = new List <string>();
            var lunchMenuLookup = lunchMenuLookupRepo.GetByDate(message.Date).Result;
            int?menuId          = null;

            if (lunchMenuLookup.Result)
            {
                var lunchMenu     = new Menu(lunchMenuLookup.Menu.Date);
                var exsistingMenu = lunchMenuRepo.GetById(lunchMenu.Id);

                if (exsistingMenu != null)
                {
                    errors.Add($"Menu already exists.");
                }

                foreach (var courceLookup in lunchMenuLookup.Menu.Course)
                {
                    if (!lunchMenu.AddMenuCourse(courceLookup))
                    {
                        errors.Add($"The dish { courceLookup} can not be added to menu.");
                    }
                }

                if (!errors.Any())
                {
                    lunchMenuRepo.SaveUpdate(lunchMenu);
                    menuId = lunchMenu.Id;
                }
            }
            else
            {
                errors.Add($"No menu exists on { message.Date.ToString("dd/MM/yy")}");
            }

            return(new CreateMenuResponse(!errors.Any(), errors, menuId));
        }