Пример #1
0
 public async Task <List <Order> > GetOrders()
 {
     logger.LogInformation($"{nameof(GetOrders)}.");
     return(await orderDataService.GetOrders());
 }
        public List <OrderDto> GetAllOrders()
        {
            var orders = orderDataService.GetOrders().ToList();
            var standardInventories = standardInventoryBusinessEntity.GetAllStandardInventories();
            var deliverySlots       = deliverySlotBusinessEntity.GetDeliverySlots();
            var buyers = userBusinessEntity.GetUsers();

            var orderDetailIds = orders.SelectMany(p => p.OrderDetails).Select(p => p.ID);

            var orderAssigments = orderDataService.GetOrderAssignmentsByOrderDetailByIds(orderDetailIds);

            var orderDtoList = new List <OrderDto>();


            orders.ForEach(r =>
            {
                var deliverySlot = deliverySlots.FirstOrDefault(s => s.ID == r.DeliverySlotId);

                var orderDto = new OrderDto()
                {
                    ID                      = r.ID,
                    OrderRefNo              = r.OrderRefNo,
                    BuyerId                 = r.BuyerId,
                    OrderedDate             = r.OrderedDate,
                    ExpectedDiliveredDate   = r.ExpectedDiliveredDate,
                    OrderType               = r.OrderType,
                    Status                  = r.Status,
                    DeliverySlotId          = r.DeliverySlotId,
                    SupplierCategory        = r.SupplierCategory,
                    IsDeleted               = r.IsDeleted,
                    AssignmentSelectionType = r.AssignmentSelectionType,
                    DeliverySlotName        = deliverySlot != null ? deliverySlot.SlotName : "",
                    OrderDetails            = new List <OrderDetailDto>()
                };


                r.OrderDetails.ForEach(d =>
                {
                    var standardInventory = standardInventories.FirstOrDefault(s => s.ID == d.ID);

                    var orderDetailDto = new OrderDetailDto()

                    {
                        ID                  = d.ID,
                        OrderID             = r.ID,
                        StandardInventoryId = d.StandardInventoryId,
                        Qty                 = d.Qty,
                        ItemName            = standardInventory != null ? standardInventory.ItemName : "",
                        OrderAssignments    = orderAssigments.Where(p => p.OrderDetailID == d.ID).Select(a => new OrderAssignmentDto
                        {
                            ID                      = a.ID,
                            OrderDetailID           = d.ID,
                            SupplierInventoryID     = a.SupplierInventoryID,
                            Qty                     = a.Qty,
                            SupplierAcknowledgement = a.SupplierAcknowledgement,
                            VehicleAcknowledgement  = a.VehicleAcknowledgement,
                            BuyerAcknowledgement    = a.BuyerAcknowledgement
                        })
                    };

                    orderDto.OrderDetails.Add(orderDetailDto);
                });

                orderDtoList.Add(orderDto);
            }

                           );

            return(orderDtoList);
        }