Example #1
0
        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));
        }
Example #2
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));
        }