Ejemplo n.º 1
0
        public async Task <ActionResult <BaseResponse <Diet> > > CreateDiet(CreateDietCommand 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));
            }
        }
        public async Task <BaseResponse <Diet> > Handle(CreateDietCommand request, CancellationToken cancellationToken)
        {
            var response = new BaseResponse <Diet> {
                ReponseName = nameof(CreateDietCommand), Content = new List <Diet> ()
                {
                }
            };
            var entity    = _mapper.Map <Diet> (request);
            var newentity = await _dietRepository.AddAsync(entity);

            if (newentity == null)
            {
                response.Status  = ResponseType.Error;
                response.Message = $"{nameof(Diet)} could not be created.";
                response.Content = null;
            }
            else
            {
                response.Status  = ResponseType.Success;
                response.Message = $"{nameof(Diet)} created successfully.";
                response.Content.Add(newentity);
            }
            return(response);
        }