Exemplo n.º 1
0
        public List <StandardInventoryDto> GetStandardInventories()
        {
            var standardInventory          = istandardInventoryDataService.GetStandardInventories();
            var unitOfMeasures             = unitOfMeasureBusinessEntity.GetUnitOfMeasure();
            var inventoryItemCategories    = inventoryItemCategoriesBusinessEntity.GetInventoryItemCategories();
            var inventoryItemSubCategories = inventoryItemSubCategoryBusinessEntity.GetAllActiveInventoryItemSubCategory();


            var standardInventoryDtoList = standardInventory.Select(p => new StandardInventoryDto()
            {
                ID       = p.ID,
                ItemName = p.ItemName,
                InventoryItemCategoryId    = p.InventoryItemCategoryId,
                InventoryItemSubCategoryId = p.InventoryItemSubCategoryId,
                QuantityUnitOfMesureId     = p.QuantityUnitOfMesureId,
                Seasonality      = p.Seasonality,
                MinimumInventory = p.MinimumInventory,
                FileID           = p.FileServerDetailID
            }).ToList();

            var fileDetails = fileServerBusinessEntity.GetFileDetails(standardInventory.Select(p => p.FileServerDetailID));

            standardInventoryDtoList.ForEach(p =>
            {
                var unitOfMeasure = unitOfMeasures.FirstOrDefault(s => s.ID == p.QuantityUnitOfMesureId);

                if (unitOfMeasure != null)
                {
                    p.QuantityUnitOfMeasureName = unitOfMeasure.Name;
                }

                var fileDto = fileDetails.FirstOrDefault(f => f.ID == p.FileID);

                if (fileDto != null)
                {
                    var url = FileServerUtility.GetPresignedUrl(fileDto.BucketName, fileDto.Key).Result;

                    p.FileUrl = url;
                }

                var inventoryItemCategory = inventoryItemCategories.FirstOrDefault(i => i.ID == p.InventoryItemCategoryId);

                if (inventoryItemCategory != null)
                {
                    p.InventoryItemCategoryName = inventoryItemCategory.Name;
                }

                var inventoryItemSubCategory = inventoryItemSubCategories.FirstOrDefault(c => c.ID == p.InventoryItemSubCategoryId);

                if (inventoryItemSubCategory != null)
                {
                    p.InventoryItemSubCategoryName = inventoryItemSubCategory.Name;
                }
            });


            return(standardInventoryDtoList);
        }
        public List <SupplierInventoryDto> GetSupplierInventories()
        {
            var sandardInventory = standardInventoryBusinessEntity.GetStandardInventories();

            var suppliers = this.userService.GetUsers().Where(p => p.UserType == "Supplier");

            var supplierInventoryList = supplierInventoryDataService.GetSupplierInventoriesBySupplierIds(suppliers.Select(p => p.ID).ToList());

            var supplierInventoryDtoList = supplierInventoryList.Select(r => new SupplierInventoryDto()
            {
                ID = r.Id,
                SupplierStandardInventoryId = r.SupplierStandardInventoryId,
                Qty               = r.Qty,
                UnitPrice         = r.UnitPrice,
                AvailableQty      = r.AvailableQty,
                ProcessingQty     = r.ProcessingQty,
                InventoryDate     = r.InventoryDate,
                SupplierName      = suppliers.FirstOrDefault(p => p.ID == r.SupplierStandardInventory.SupplierId).Name,
                InventoryItemName = r.SupplierStandardInventory.StandardInventory == null ? "" : r.SupplierStandardInventory.StandardInventory.ItemName
            }).ToList();

            //supplierInventoryDtoList.ForEach(p =>
            //{
            //    var supplierInventoryItem = supplierInventoryList.FirstOrDefault(s => s.Id == p.ID);

            //    var standardInventory = sandardInventory.FirstOrDefault(i => i.ID == supplierInventoryItem.SupplierStandardInventory.StandardInventoryId);
            //    if (standardInventory != null)
            //        p.InventoryItemName = standardInventory.ItemName;
            //});

            return(supplierInventoryDtoList.OrderBy(p => p.SupplierName).ToList());
        }