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 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 OrderRepresentation Complete(int orderId) { var order = _repository.FindById(orderId); if (order == null) { throw new NoSuchOrderException(orderId); } if (order.Status != OrderStatus.Ready) { throw new UnexpectedOrderStateException(orderId); } order.Take(); var representation = _orderRepresentationMapper.GetRepresentation(order); return(representation); }
public OrderRepresentation Remove(int orderId) { var order = _repository.FindById(orderId); if (order == null) { throw new NoSuchOrderException(orderId); } if (order.Status == OrderStatus.Preparing || order.Status == OrderStatus.Ready) { throw new UnexpectedOrderStateException(orderId); } var representation = _orderRepresentationMapper.GetRepresentation(order); _repository.Remove(orderId); return(representation); }