Exemplo n.º 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);
        }
Exemplo n.º 2
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 IEnumerable <OrderOptimizedPossibilityDto> SearchPossibilities(Order order, List <OrderDetail> orderDetails)
        {
            //var order = new Order
            //{
            //    ID = orderDto.ID,
            //    OrderRefNo = orderDto.OrderRefNo,
            //    BuyerId = orderDto.BuyerId,
            //    OrderedDate = DateTime.Today,
            //    ExpectedDiliveredDate = orderDto.ExpectedDiliveredDate,
            //    IsPreOrder = orderDto.IsPreOrder,
            //    Status = orderDto.Status,   //1-Active, 2-Hold, 3-Procedded, 4- Cancelled
            //    DeliverySlotId = orderDto.DeliverySlotId,
            //    SupplierCategory = orderDto.SupplierCategory
            //};

            //var orderDetails = orderDto.OrderDetails.Select(od => new OrderDetail()
            //{
            //    ID = od.ID,
            //    StandardInventoryId = od.ItemID,
            //    Qty = od.Qty,
            //    IsDeleted = false
            //}).ToList();

            var standardInventories = standardInventoryBusinessEntity.GetStandardInventories();
            var orderDetailStandardInventoryData = from od in orderDetails
                                                   join si in standardInventories on od.StandardInventoryId equals si.ID
                                                   select new
            {
                OrderDetailId       = od.ID,
                StandardInventoryId = si.ID,
                si.ItemName,
                si.QuantityUnitOfMeasureName
            };
            var supplierBases = supplierBaseService.GetAllSupplierBases();

            var orderPossibilities = optimizationEngine.SearchBestAvailbalities(order, orderDetails);

            if (orderPossibilities == null || orderPossibilities.Count() == 0)
            {
                return(null);
            }
            var orderPossibilityDtos = orderPossibilities.Select(
                p => new OrderOptimizedPossibilityDto()
            {
                SupplierBaseId = p.SupplierBaseId,
                SupplierBase   = supplierBases.Where(x => x.SupplierBaseId == p.SupplierBaseId).FirstOrDefault().SupplierBaseName,
                DeliveryCost   = p.DeliveryCost,
                ItemCost       = p.ItemCost,
                OrderValue     = p.OrderValue,
                OrderOptimizedPossibilityId = p.OrderOptimizedPossibilityId,
                OrderPossibilityType        = p.OrderPossibilityType,
                OrderOptimizedDetails       = p.OrderOptimizedDetails.Select(
                    r => new OrderOptimizedDetailDto()
                {
                    OrderDetailID       = r.OrderDetailID,
                    ItemName            = orderDetailStandardInventoryData.Where(a => a.OrderDetailId == r.OrderDetailID).FirstOrDefault().ItemName,
                    UnitOfMeasureName   = orderDetailStandardInventoryData.Where(a => a.OrderDetailId == r.OrderDetailID).FirstOrDefault().QuantityUnitOfMeasureName,
                    SupplierQuality     = r.SupplierQuality,
                    SupplierInventoryID = r.SupplierInventoryID,
                    Qty       = r.Qty,
                    UnitPrice = r.UnitPrice,
                    Value     = r.Value
                }).ToList()
            });

            return(orderPossibilityDtos);
        }