示例#1
0
        public List <UserDto> GetUsers()
        {
            var userDtos = userService.GetUsers();

            var supplierBases      = supplierBaseBusinessEntity.GetAllActiveSupplierBases();
            var deliverySlots      = deliverySlotsBusinessEntity.GetDeliverySlots();
            var standaradInventory = standardInventoryBusinessEntity.GetStandardInventories();
            var zones = zoneBusinessEntity.GetZones();

            var userDtoList = userDtos.Select(p => new UserDto()
            {
                ID       = p.ID, Name = p.Name, Address = p.Address, ContactNo = p.ContactNo,
                Email    = p.Email, UserType = p.UserType, DefaultSupplierBaseId = p.DefaultSupplierBaseId, DeliverySlotId = p.DeliverySlotId,
                Category = p.Category, StandaradInventoryID = p.StandaradInventoryID, RelevantZoneId = p.RelevantZoneId
            }).ToList();

            userDtoList.ForEach(p => {
                var supplierBase = supplierBases.FirstOrDefault(s => s.SupplierBaseId == p.DefaultSupplierBaseId);

                if (supplierBase != null)
                {
                    p.DefaultSupplierBaseName = supplierBase.SupplierBaseName;
                }
            });
            userDtoList.ForEach(p => {
                var deliverySlot = deliverySlots.FirstOrDefault(s => s.ID == p.DeliverySlotId);

                if (deliverySlot != null)
                {
                    p.DeliverySlotName = deliverySlot.SlotName;
                }
            });
            userDtoList.ForEach(p => {
                var supplierStandardInventories = standaradInventory.FirstOrDefault(s => s.ID == p.StandaradInventoryID);

                if (supplierStandardInventories != null)
                {
                    p.StandaradInventoryName = supplierStandardInventories.ItemName;
                }
            });
            userDtoList.ForEach(p =>
            {
                var zone = zones.FirstOrDefault(s => s.ID == p.RelevantZoneId);
                if (zone != null)
                {
                    p.RelevantZoneName = zone.Name;
                }
            });


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