Ejemplo n.º 1
0
        private GetOrdersResponse MapListOfOrdersToOrdersResponse(List <OrderDto> orders)
        {
            GetOrdersResponse getOrdersResponse = new GetOrdersResponse();

            foreach (var order in orders)
            {
                OrderResponse orderResponse = new OrderResponse
                {
                    Id         = order.Id.ToString(),
                    Clientname = order.ClientName,
                    Discount   = (double)order.Discount,
                    Total      = (double)order.Total
                };

                foreach (var orderItem in order.Items)
                {
                    OrderItemResponse orderItemResponse = new OrderItemResponse
                    {
                        Orderid     = orderItem.OrderId.ToString(),
                        Productid   = orderItem.ProductId.ToString(),
                        Productname = orderItem.ProductName,
                        Quantity    = orderItem.Quantity,
                        Unitprice   = (double)orderItem.UnitPrice
                    };
                    orderResponse.Orderitems.Add(orderItemResponse);
                }

                getOrdersResponse.Orderslist.Add(orderResponse);
            }

            return(getOrdersResponse);
        }
Ejemplo n.º 2
0
        public OrderResponse Add(OrderRequest request)
        {
            OrderResponse result = new OrderResponse
            {
                Id           = orderList.OrderList.Count > 0 ? orderList.OrderList.Max(x => x.Id) + 1 : 1,
                CustomerName = request.CustomerName,
                IsTakeAway   = request.IsTakeAway,
                CreatedDate  = request.CreatedDate,
                StatusCode   = request.StatusCode
            };

            result.OrderItemList = new List <OrderItemResponse>();
            for (int i = 0; i < request.OrderItemList.Count; ++i)
            {
                OrderItem orderItemRequest = request.OrderItemList[i];

                OrderItemResponse orderItemResult = new OrderItemResponse
                {
                    Id       = i + 1,
                    Quantity = orderItemRequest.Quantity
                };

                if (orderItemRequest.Product != null)
                {
                    orderItemResult.Product = ProductLogic.Instance.GetProduct(orderItemRequest.Product.Id);
                }

                result.OrderItemList.Add(orderItemResult);
            }

            orderList.OrderList.Add(result);

            return(result);
        }
Ejemplo n.º 3
0
        private OrderItemResponse buildOrderItemResponse(ConfectioneryOrder confOrder)
        {
            Confectionery     confectionery = _context.Confectioneries.Where(c => c.IdConfecti == confOrder.IdConfection).First();
            OrderItemResponse response      = new OrderItemResponse()
            {
                ConfectioneryName = confectionery.Name,
                Type     = confectionery.Type,
                Quantity = confOrder.Quantity
            };

            return(response);
        }
        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);
        }