public OrderRepresentation Read(int orderId, Uri requestUri) { var order = _repository.FindById(orderId); if (order == null) { throw new NoSuchOrderException(orderId); } var representation = _orderRepresentationMapper.GetRepresentation(order); var orderUri = RestbucksResources.GetResourceUri <OrderResource>(requestUri, orderId.ToString()); if (order.Status == OrderStatus.Unpaid) { var paymentUri = RestbucksResources.GetResourceUri <PaymentResource>(requestUri, orderId.ToString()); representation.PaymentLink = paymentUri; representation.CancelLink = orderUri; representation.UpdateLink = orderUri; representation.SelfLink = orderUri; } else if (order.Status == OrderStatus.Preparing) { representation.SelfLink = orderUri; } else if (order.Status == OrderStatus.Ready) { representation.ReceiptLink = RestbucksResources.GetResourceUri <ReceiptResource>(requestUri, orderId.ToString()); } return(representation); }
public ReceiptRepresentation Read(int orderId, Uri requestUri) { var order = _repository.FindById(orderId); if (order == null) { throw new NoSuchOrderException(orderId); } var representation = _receiptMapper.GetRepresentation(order); representation.OrderLink = RestbucksResources.GetResourceUri <OrderResource>(requestUri, orderId.ToString()); representation.CompleteLink = RestbucksResources.GetResourceUri <ReceiptResource>(requestUri, orderId.ToString()); return(representation); }
public OrderRepresentation Create(OrderRepresentation orderRepresentation, Uri requestUri) { var newOrder = _orderRepresentationMapper.GetDomainObject(orderRepresentation); var orderId = _repository.Store(newOrder); var orderUri = RestbucksResources.GetResourceUri <OrderResource>(requestUri, orderId.ToString()); var paymentUri = RestbucksResources.GetResourceUri <PaymentResource>(requestUri, orderId.ToString()); var result = _orderRepresentationMapper.GetRepresentation(newOrder); result.UpdateLink = orderUri; result.SelfLink = orderUri; result.CancelLink = orderUri; result.PaymentLink = paymentUri; return(result); }
public PaymentRepresentation Pay(int orderId, PaymentRepresentation paymentRepresentation, Uri requestUri) { var order = _repository.FindById(orderId); if (order == null) { throw new NoSuchOrderException(orderId); } if (order.Status != OrderStatus.Unpaid) { throw new UnexpectedOrderStateException(orderId); } var payment = _paymentMapper.GetDomainObject(paymentRepresentation); order.Pay(payment); var representation = _paymentMapper.GetRepresentation(order.PaymentInfo); representation.OrderLink = RestbucksResources.GetResourceUri <OrderResource>(requestUri, order.Id.ToString()); representation.ReceiptLink = RestbucksResources.GetResourceUri <ReceiptResource>(requestUri, orderId.ToString()); return(representation); }