示例#1
0
        public async Task <CommandResult> Handle(AddDietMealCommand request, CancellationToken cancellationToken)
        {
            Diet diet = await _dietRepository.GetByIdAsync(request.DietId);

            if (!FoundValidDiet(diet))
            {
                return(FailureDueToEntityNotFound());
            }

            Time timeOfDay = new Time(request.TimeOfDay.Hour, request.TimeOfDay.Minute, request.TimeOfDay.Second);

            diet.AddMeal(request.Name, request.Description, timeOfDay);
            if (!diet.IsValid)
            {
                return(FailureDueToEntityStateInconsistency(diet));
            }

            await _dietRepository.UpdateAsync(diet);

            return(await CommitAndPublishDefaultAsync());
        }
示例#2
0
        public async Task<IActionResult> AddMealAsync(Guid dietId, [FromBody]AddDietMealCommand command)
        {
            command.DietId = dietId;

            return await CreateCommandResponse(command);
        }