public Models.CustomerResponse CreateCustomer(Models.CustomerRequest body) { Task <Models.CustomerResponse> t = CreateCustomerAsync(body); APIHelper.RunTaskSynchronously(t); return(t.Result); }
public async Task <Models.CustomerResponse> CreateCustomerAsync(Models.CustomerRequest body) { string _baseUri = Configuration.GetBaseURI(); StringBuilder _queryBuilder = new StringBuilder(_baseUri); _queryBuilder.Append("/customers"); string _queryUrl = APIHelper.CleanUrl(_queryBuilder); var _headers = Utilities.APIHelper.GetHeader(); var _body = APIHelper.JsonSerialize(body); HttpRequest _request = ClientInstance.PostBody(_queryUrl, _headers, _body); HttpStringResponse _response = (HttpStringResponse)await ClientInstance.ExecuteAsStringAsync(_request).ConfigureAwait(false); HttpContext _context = new HttpContext(_request, _response); base.ValidateResponse(_response, _context); try { return(APIHelper.JsonDeserialize <Models.CustomerResponse>(_response.Body)); } catch (Exception _ex) { throw new APIException("Failed to parse the response: " + _ex.Message, _context); } }
public async Task <IActionResult> Post([FromBody] Models.CustomerRequest customerRequest, CancellationToken cancellationToken) { if (customerRequest == null) { throw new ArgumentNullException("customer body request is missing!"); } await _mediator.Publish(new CustomerPublisher( ControllerContext, new DomainModels.Business.CustomerDomain.Customer() { Id = Guid.NewGuid(), CorrelationId = _correlationId, Name = customerRequest.Name, BirthDate = customerRequest.BirthDate, Country = customerRequest.Country, Email = customerRequest.Email, Mobile = customerRequest.Mobile }, _messagePublisher, _middlewareConfiguration, _correlationId, _operationalUnit), cancellationToken); return(Ok()); }