Exemple #1
0
        public async Task <BaseResponse <Diet> > Handle(UpdateDietCommand request, CancellationToken cancellationToken)
        {
            var response = new BaseResponse <Diet> ()
            {
                ReponseName = nameof(UpdateDietCommand), Content = new List <Diet> ()
                {
                }
            };
            var entity = await _dietRepository.GetOneAsync(p => p.Id == request.Id);

            if (entity == null)
            {
                response.Status  = ResponseType.Error;
                response.Message = $"{nameof(Diet)} not found.";
                response.Content = null;
            }
            else
            {
                _mapper.Map(request, entity, typeof(UpdateDietCommand), typeof(Diet));
                await _dietRepository.UpdateAsync(entity);

                response.Status  = ResponseType.Success;
                response.Message = $"{nameof(Diet)} updated successfully.";
                response.Content.Add(entity);
            }
            return(response);
        }
Exemple #2
0
        public async Task <ActionResult <BaseResponse <Diet> > > UpdateDiet(UpdateDietCommand command)
        {
            try {
                var result = await _mediator.Send(command);

                return(Ok(result));
            } catch (ValidationException ex) {
                var err = new BaseResponse <Diet> ();
                err.Status  = ResponseType.Error;
                err.Message = ex.Message;
                err.Content = null;
                return(Ok(err));
            }
        }
Exemple #3
0
        public async Task <CommandResult> Handle(UpdateDietCommand request, CancellationToken cancellationToken)
        {
            Diet diet = await _dietRepository.GetByIdAsync(request.DietId);

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

            diet.Update(
                request.Name,
                request.Description
                );

            await _dietRepository.UpdateAsync(diet);

            return(await CommitAndPublishDefaultAsync());
        }
        public async Task<IActionResult> UpdateAsync(Guid id, [FromBody]UpdateDietCommand command)
        {
            command.DietId = id;

            return await CreateCommandResponse(command);
        }