public async Task <bool> ProcessOrder(Guid orderCode) { var order = await orderRepository.FindByOrderCode(orderCode).ConfigureAwait(false); if (order == null) { throw new OrderNotFoundException(orderCode); } if (order.State == OrderState.Processing) { throw new OrderAlreadyProcessingException(orderCode); } order.State = OrderState.Processing; var updatedOrder = await orderRepository.Update(order); if (updatedOrder != null) { var request = CreateInvoiceRequest.Of(updatedOrder); await invoiceApiClient.CreateInvoice(request).ConfigureAwait(false); await cache.Invalidate(updatedOrder.CustomerId).ConfigureAwait(false); } return(updatedOrder != null); }
public async Task <ActionResult <CartResponse> > UpdateMyCart([FromBody] UpdateCartRequest request) { var customerId = getUserMetaData().Id; var cart = await cache.TryGet(customerId); if (cart == null) { cart = new Cart(customerId); } if (request.Count <= 0) { throw new WWSException("Count must be positive", StatusCodes.Status400BadRequest); } try { var item = await inventoryApiClient.GetInventoryItem(request.ItemId).ConfigureAwait(false); var updatedCart = cartService.AddCartItem(cart, item, request); await cache.Invalidate(customerId); await cache.Set(updatedCart); return(Ok(CartResponse.Of(updatedCart))); } catch (StockIsNotEnoughException) { throw new WWSException("Not enough item in stock", StatusCodes.Status400BadRequest); } catch (Refit.ApiException ex) { if (ex.StatusCode == HttpStatusCode.NotFound) { throw new WWSException("Item not found", StatusCodes.Status404NotFound); } else { throw; } } }