public async Task <EntityResponse <ProductApproval> > Handle(CreateProductApprovalCommand request, CancellationToken cancellationToken)
        {
            var response = new EntityResponse <ProductApproval> ()
            {
                ReponseName = nameof(CreateProductApprovalCommand), Content = new List <ProductApproval> ()
                {
                }
            };
            var entity    = _mapper.Map <ProductApproval> (request);
            var newentity = await _approvalRepository.AddAsync(entity);

            if (newentity == null)
            {
                response.Status  = ResponseType.Warning;
                response.Message = $"{nameof(ProductApproval)} could not be created.";
                response.Content = null;
            }
            else
            {
                response.Status  = ResponseType.Success;
                response.Message = $"{nameof(ProductApproval)} created successfully.";
                response.Content.Add(newentity);
            }
            return(response);
        }
コード例 #2
0
        public async Task <ActionResult <EntityResponse <ProductApproval> > > CreateProductApprovalEntity(CreateProductApprovalCommand command)
        {
            try {
                var result = await _mediator.Send(command);

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