コード例 #1
0
        public async Task <ApiResponse <CreateCustomerTypeDto> > CreateCustomerType(CustomerTypeVm customerTypeViewModel)
        {
            try
            {
                ApiResponse <CreateCustomerTypeDto> apiResponse = new ApiResponse <CreateCustomerTypeDto>();
                CreateCustomerTypeCommand           createCustomerTypeCommand = _mapper.Map <CreateCustomerTypeCommand>(customerTypeViewModel);
                var createCustomerTypeCommandResponse = await _client.AddCustomerTypeAsync(createCustomerTypeCommand);

                if (createCustomerTypeCommandResponse.Success)
                {
                    apiResponse.Data    = _mapper.Map <CreateCustomerTypeDto>(createCustomerTypeCommandResponse.CustomerType);
                    apiResponse.Success = true;
                }
                else
                {
                    apiResponse.Data = null;
                    foreach (var error in createCustomerTypeCommandResponse.ValidationErrors)
                    {
                        apiResponse.ValidationErrors += error + Environment.NewLine;
                    }
                }
                return(apiResponse);
            }
            catch (ApiException ex)
            {
                return(ConvertApiExceptions <CreateCustomerTypeDto>(ex));
            }
        }
コード例 #2
0
        public async Task <ActionResult <CreateCustomerTypeCommandResponse> > Create([FromBody] CreateCustomerTypeCommand createCustomerTypeCommand)
        {
            var response = await _mediator.Send(createCustomerTypeCommand);

            return(Ok(response));
        }