public async Task <IActionResult> CreateOrder([FromBody] DataContracts.Order orderDto, CancellationToken cancellationToken) { Order newOrder; try { newOrder = new Order(Guid.NewGuid(), orderDto.CustomerId); } catch (DataValidationException ex) { return(BadRequest(new DataContracts.Error(ex.Message))); } await repository.StoreOrder(newOrder, cancellationToken); var newOrderUrl = CreateOrderUrl(newOrder); return(Created(newOrderUrl, newOrder.ToDto(newOrderUrl))); }
public async Task <IActionResult> UpdateOrder(Guid id, [FromBody] DataContracts.Order orderDto, CancellationToken cancellationToken) { var order = await repository.GetOrder(id, cancellationToken); if (order == null) { return(NotFound()); } try { order.CustomerId = orderDto.CustomerId; } catch (DataValidationException ex) { return(BadRequest(new DataContracts.Error(ex.Message))); } await repository.StoreOrder(order, cancellationToken); return(Ok(order.ToDto(CreateOrderUrl(order)))); }
public async Task <Order> CreateOrder(Guid customerId, CancellationToken cancellationToken) { try { var orderToCreate = new DataContracts.Order { CustomerId = customerId }; var httpResponse = await httpClient.PostAsync( $"{ApiVersion}/orders", SerializeContent(orderToCreate), cancellationToken); await HandleFailure(httpResponse, "Creating an order"); var createdOrder = await DeserializeContent <DataContracts.Order>(httpResponse); return(createdOrder.ToModel(this)); } catch (HttpRequestException ex) { throw new OrderingClientException("An unexpected error occured while accessing ordering service.", ex); } }