Exemple #1
0
        public List <WatchListDto> GetAllRelatedSuppliers(int supplierBaseId)
        {
            var suppliers   = userBusinessEntity.GetUsers().Where(r => r.UserType == "Supplier" && r.DefaultSupplierBaseId == supplierBaseId);
            var supplierIds = suppliers.Select(r => r.ID).ToList();
            var supplierStandardInventories = supplierStandardInventoryBusinessEntity.GetInitialSupplierStandardInventories().Where(r => supplierIds.Contains(r.SupplierId)).ToList();
            var supplierInventories         = supplierInventoryBusinessEntity.GetSupplierInventories().Where(r => !r.IsFreeze && !r.IsDeleted);
            var standardInventories         = standardInventoryBusinessEntity.GetStandardInventories();

            var watchListItems = (from stdInv in standardInventories
                                  join supStdInv in supplierStandardInventories on stdInv.ID equals supStdInv.StandardInventoryId
                                  join supInv in supplierInventories on supStdInv.Id equals supInv.SupplierStandardInventoryId
                                  select new
            {
                StandardInventoryId = stdInv.ID,
                SupplierInventoryId = supInv.ID
            });
            var groupedData = from wli in watchListItems
                              group wli by wli.StandardInventoryId into grouped
                              select new { StandardInventoryId = grouped.Key, InvnetoryCount = grouped.Count() };

            var itemwiseSupplierInventories = (from sup in suppliers
                                               join supStdInv in supplierStandardInventories on sup.ID equals supStdInv.SupplierId
                                               join stdInv in standardInventories on supStdInv.StandardInventoryId equals stdInv.ID
                                               join supInv in supplierInventories on supStdInv.Id equals supInv.SupplierStandardInventoryId
                                               join grpData in groupedData on stdInv.ID equals grpData.StandardInventoryId
                                               where grpData.InvnetoryCount == 1
                                               select new WatchListDto()
            {
                SupplierId = sup.ID,
                SupplierName = sup.Name,
                StandardInventoryId = stdInv.ID,
                StandardInventoryName = stdInv.ItemName,
                Price = supInv.UnitPrice,
                QuantityAvailable = supInv.AvailableQty
            }).ToList();

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