コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }