public AssetViewModel GetAssetDetails(AssetViewModel assetView) { assetView.AgentName = _agentRepository.Find(null, a => a.Id == assetView.AgentId).Items?.FirstOrDefault()?.Name; assetView.FileName = _storageFileRepository.Find(null, f => f.Id == assetView.FileId).Items?.FirstOrDefault()?.Name; return(assetView); }
public PaginatedList <FileFolderViewModel> FindAllFilesFoldersView(Guid?driveId, Predicate <FileFolderViewModel> predicate = null, string sortColumn = "", OrderByDirectionType direction = OrderByDirectionType.Ascending, int skip = 0, int take = 100, string path = null) { PaginatedList <FileFolderViewModel> paginatedList = new PaginatedList <FileFolderViewModel>(); var folderItemsList = new PaginatedList <StorageFolder>(); if (string.IsNullOrEmpty(path)) { folderItemsList = base.Find(null, j => j.IsDeleted == false && j.StorageDriveId == driveId); } else { path = path + Path.DirectorySeparatorChar; folderItemsList = base.Find(null, j => j.IsDeleted == false && j.StorageDriveId == driveId && j.StoragePath.Contains(path)); } if (folderItemsList != null && folderItemsList.Items != null && folderItemsList.Items.Count > 0) { var folderItemRecord = from a in folderItemsList.Items join b in dbContext.StorageFolders on a.ParentFolderId equals b.Id into table1 from b in table1.DefaultIfEmpty() join c in dbContext.StorageFolders on a.Id equals c.ParentFolderId into table2 from c in table1.DefaultIfEmpty() join d in dbContext.StorageDrives on a.StorageDriveId equals d.Id into table3 from d in table3.DefaultIfEmpty() select new FileFolderViewModel { Name = a?.Name, Id = a?.Id, ContentType = "Folder", CreatedBy = a?.CreatedBy, CreatedOn = a?.CreatedOn, FullStoragePath = a?.StoragePath, HasChild = c?.ParentFolderId != null ? true : false, IsFile = false, ParentId = a?.ParentFolderId, StoragePath = b?.StoragePath != null ? b?.StoragePath : d?.Name, Size = a?.SizeInBytes, StorageDriveId = a?.StorageDriveId }; if (!string.IsNullOrWhiteSpace(sortColumn)) { if (direction == OrderByDirectionType.Ascending) { folderItemRecord = folderItemRecord.OrderBy(j => j.GetType().GetProperty(sortColumn).GetValue(j)).ToList(); } else if (direction == OrderByDirectionType.Descending) { folderItemRecord = folderItemRecord.OrderByDescending(j => j.GetType().GetProperty(sortColumn).GetValue(j)).ToList(); } } var fileItemsList = new PaginatedList <StorageFile>(); if (string.IsNullOrEmpty(path)) { fileItemsList = _storageFileRepository.Find(null, j => j.IsDeleted == false && j.StorageDriveId == driveId); } else { path = path + Path.DirectorySeparatorChar; fileItemsList = _storageFileRepository.Find(null, j => j.IsDeleted == false && j.StorageDriveId == driveId && j.StoragePath.Contains(path)); } if (fileItemsList != null && fileItemsList.Items != null && fileItemsList.Items.Count > 0) { var fileItemRecord = from a in fileItemsList.Items join b in dbContext.StorageFolders on a.StorageFolderId equals b.Id into table1 from b in table1.DefaultIfEmpty() join c in dbContext.StorageDrives on a.StorageDriveId equals c.Id into table2 from c in table2.DefaultIfEmpty() select new FileFolderViewModel { Name = a?.Name, Id = a?.Id, ContentType = a?.ContentType, CreatedBy = a?.CreatedBy, CreatedOn = a?.CreatedOn, FullStoragePath = a?.StoragePath, HasChild = false, IsFile = true, ParentId = a?.StorageFolderId, StoragePath = b?.StoragePath != null ? b?.StoragePath : c?.Name, Size = a?.SizeInBytes, StorageDriveId = a?.StorageDriveId }; if (!string.IsNullOrWhiteSpace(sortColumn)) { if (direction == OrderByDirectionType.Ascending) { fileItemRecord = fileItemRecord.OrderBy(j => j.GetType().GetProperty(sortColumn).GetValue(j)).ToList(); } else if (direction == OrderByDirectionType.Descending) { fileItemRecord = fileItemRecord.OrderByDescending(j => j.GetType().GetProperty(sortColumn).GetValue(j)).ToList(); } } List <FileFolderViewModel> filterRecord = null; List <FileFolderViewModel> itemRecord = null; if (folderItemRecord != null || folderItemRecord.Any()) { itemRecord = folderItemRecord.ToList(); itemRecord.AddRange(fileItemRecord); } else { itemRecord = fileItemRecord.ToList(); } if (predicate != null) { filterRecord = itemRecord.ToList().FindAll(predicate); } else { filterRecord = itemRecord.ToList(); } paginatedList.Items = filterRecord.Skip(skip).Take(take).ToList(); paginatedList.Completed = fileItemsList.Completed; paginatedList.Impediments = fileItemsList.Impediments; paginatedList.PageNumber = fileItemsList.PageNumber; paginatedList.PageSize = fileItemsList.PageSize; paginatedList.ParentId = fileItemsList.ParentId; paginatedList.Started = fileItemsList.Started; paginatedList.TotalCount = filterRecord?.Count; } else { List <FileFolderViewModel> filterRecord = null; if (predicate != null) { filterRecord = folderItemRecord.ToList().FindAll(predicate); } else { filterRecord = folderItemRecord.ToList(); } paginatedList.Items = filterRecord.Skip(skip).Take(take).ToList(); paginatedList.Completed = folderItemsList.Completed; paginatedList.Impediments = folderItemsList.Impediments; paginatedList.PageNumber = folderItemsList.PageNumber; paginatedList.PageSize = folderItemsList.PageSize; paginatedList.ParentId = folderItemsList.ParentId; paginatedList.Started = folderItemsList.Started; paginatedList.TotalCount = filterRecord?.Count; } } return(paginatedList); }
public StorageDrive UpdateDrive(string id, StorageDrive drive, string orgId) { Guid organizationId = Guid.Parse(orgId); Guid entityId = Guid.Parse(id); var existingDrive = _storageDriveRepository.Find(null, q => q.Id == entityId && q.OrganizationId == organizationId).Items.FirstOrDefault(); if (existingDrive == null) { throw new EntityDoesNotExistException("Storage drive could not be found or does not exist"); } var existingDriveName = _storageDriveRepository.Find(null, q => q.Name.ToLower() == existingDrive.Name.ToLower() && q.Id != existingDrive.Id).Items.FirstOrDefault(); if (existingDriveName != null) { throw new EntityAlreadyExistsException("Storage drive with same name already exists"); } if (drive.IsDefault == null) { drive.IsDefault = existingDrive.IsDefault; } CheckDefaultDrive(drive, organizationId); var adapterType = drive.FileStorageAdapterType; if (string.IsNullOrEmpty(adapterType)) { adapterType = AdapterType.AzureBlobStorage.ToString(); } //check if updated storage drive can be updated for the current organization long?maxSizeInBytes = drive.MaxStorageAllowedInBytes; //size of updated drive long?organizationStorage = GetTotalOrganizationStorage(organizationId); //sum of all drives for the current organization long?orgMaxSizeInBytes = _organizationManager.GetMaxStorageInBytes(); //max allowed storage for the current organization long?updatedOrgStorage = maxSizeInBytes + (organizationStorage - existingDrive.MaxStorageAllowedInBytes); //sum of updated drive and all existing drives if (orgMaxSizeInBytes != null && maxSizeInBytes > orgMaxSizeInBytes) { throw new EntityOperationException("Drive size would exceed the allowed storage space for this organization"); } existingDrive.IsDefault = drive.IsDefault; if (!string.IsNullOrEmpty(drive.FileStorageAdapterType)) { existingDrive.FileStorageAdapterType = drive.FileStorageAdapterType; } if (drive.MaxStorageAllowedInBytes != null) { existingDrive.MaxStorageAllowedInBytes = drive.MaxStorageAllowedInBytes; } bool existingDriveHasChildren = false; var existingFolders = _storageFolderRepository.Find(null, q => q.ParentFolderId == existingDrive.Id && q.OrganizationId == organizationId).Items; var existingFiles = _storageFileRepository.Find(null, q => q.StorageFolderId == existingDrive.Id && q.OrganizationId == organizationId).Items; if (existingFolders != null && existingFiles != null) { existingDriveHasChildren = true; } if (existingDriveHasChildren && drive.Name != existingDrive.Name) { throw new EntityOperationException("Drive name cannot be changed except when drive is empty"); } else if (existingDrive.Name != drive.Name) { existingDrive.Name = drive.Name; } _storageDriveRepository.Update(existingDrive); _webhookPublisher.PublishAsync("Files.DriveUpdated", drive.Id.ToString(), drive.Name); return(existingDrive); }