public async Task <EntityResponse <ProductApproval> > Handle(UpdateProductApprovalCommand request, CancellationToken cancellationToken)
        {
            var response = new EntityResponse <ProductApproval> ()
            {
                ReponseName = nameof(UpdateProductApprovalCommand), Content = new List <ProductApproval> ()
                {
                }
            };
            var entity = await _approvalRepository.GetOneAsync(p => p.Id == request.Id);

            if (entity == null)
            {
                response.Status  = ResponseType.Warning;
                response.Message = $"{nameof(ProductApproval)} not found.";
                response.Content = null;
            }
            else
            {
                _mapper.Map(request, entity, typeof(UpdateProductApprovalCommand), typeof(ProductApproval));
                await _approvalRepository.UpdateAsync(entity);

                response.Status  = ResponseType.Success;
                response.Message = $"{nameof(ProductApproval)} updated successfully.";
                response.Content.Add(entity);
            }
            return(response);
        }
Beispiel #2
0
        public async Task <ActionResult <EntityResponse <ProductApproval> > > UpdateProductApprovalEntity(UpdateProductApprovalCommand command)
        {
            try {
                var result = await _mediator.Send(command);

                return(Ok(result));
            } catch (ValidationException ex) {
                var err = new EntityResponse <ProductApproval> ();
                err.ReponseName = nameof(UpdateProductApprovalEntity);
                err.Status      = ResponseType.Error;
                err.Message     = ex.Message;
                err.Content     = null;
                return(Ok(err));
            }
        }