Example #1
0
        public SrvObj.OrderItemResponse ToOrderItemResponse(int orderId, Domain.OrderItem item)
        {
            var orderItemReponse = Mapper.Map <SrvObj.OrderItemResponse>(item);

            var productId   = orderItemReponse.Product.Id;
            var orderLink   = "orders/{0}".Fmt(orderId);
            var itemsLink   = "/items/{0}".Fmt(item.Id);
            var productLink = "products/{0}".Fmt(productId);

            orderItemReponse.Links.Add(SelfLink(orderLink + itemsLink));
            orderItemReponse.Links.Add(ParentLink(orderLink));
            orderItemReponse.Product.Links.Add(SelfLink(productLink));

            return(orderItemReponse);
        }
        public OrderItemResponse Get(GetOrderItem request)
        {
            var order = OrderRepository.GetById(request.OrderId);

            Domain.OrderItem orderItem =
                order
                .Items
                .FirstOrDefault(x => x.Id == request.ItemId);

            if (orderItem == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            OrderItemResponse response =
                OrderMapper
                .ToOrderItemResponse(order.Id, orderItem);

            return(response);
        }