public SearchViewModel GetSearchResults( object id, int?page, string locationName, string fileName, long?fromSize, long?toSize, string fileType, string dim, string sortBy, int recordsOnPage) { long byteMultiplier = AssemblyHelpers.ConvertDimentionLiteralToByteMultiplier(dim); long fromSizeInDim = (fromSize ?? 0) * byteMultiplier; long toSizeInDim = (toSize ?? 0) * byteMultiplier; IQueryable <FileEntity> files = null; int dirId; Guid userId; string searchLocation = null; bool inUserPage = false; // When we are searching in directory if (int.TryParse(id.ToString(), out dirId)) { files = ((DirectoryEntity)this.Data.Files.GetById(dirId)).FilesContained.AsQueryable(); searchLocation = "Directory " + locationName; } // When we are searching files of specific user else if (Guid.TryParse(id.ToString(), out userId)) { if (dim == null) { files = this.Data.Users.GetById(id).Files.Where(f => f.LocationId == -1).AsQueryable(); } else { files = this.Data.Users.GetById(id).Files.AsQueryable(); } searchLocation = "User " + locationName; inUserPage = true; } // When we are searching in the whole database else { files = this.Data.Files.All().AsQueryable(); } fileName = fileName ?? string.Empty; var searchResult = CommonFunc.FileSearchQuery( files, fileName, fileType, fromSizeInDim, toSizeInDim) .Project() .To <FileViewModel>(); sortBy = sortBy ?? "Name"; switch (sortBy) { case "Name desc": searchResult = searchResult.OrderByDescending(f => f.Name); break; case "Size desc": searchResult = searchResult.OrderByDescending(f => f.Size); break; case "Size": searchResult = searchResult.OrderBy(f => f.Size); break; case "Owner desc": searchResult = searchResult.OrderByDescending(f => f.OwnerName); break; case "Owner": searchResult = searchResult.OrderBy(f => f.OwnerName); break; default: searchResult = searchResult.OrderBy(f => f.Name); break; } var founded = searchResult.ToPagedList(page ?? 1, recordsOnPage); var result = new SearchViewModel(founded, searchLocation, inUserPage, sortBy); return(result); }
public UploadViewModel GetSearchResults( int?id, int?page, string fileName, long?fromSize, long?toSize, string fileType, string dim, string sortBy, User currentUser, int recordsOnPage) { long byteMultiplier = AssemblyHelpers.ConvertDimentionLiteralToByteMultiplier(dim); long fromSizeInDim = (fromSize ?? 0) * byteMultiplier; long toSizeInDim = (toSize ?? 0) * byteMultiplier; id = id ?? -1; IQueryable <FileEntity> files = null; fileName = (fileName ?? string.Empty).ToLower(); IQueryable <FileViewModel> searchResult = null; string searchLocation = null; int? currentDirectoryId = 0; if (dim == null) { string currenDirectoryName = string.Empty; currentDirectoryId = id; if (id == -1) { files = currentUser.Files.Where(f => f.LocationId == -1).AsQueryable(); currenDirectoryName = "<Main Directory>"; } else { files = ((DirectoryEntity)currentUser.Files.Where(f => f.Id == id).FirstOrDefault()).FilesContained.AsQueryable(); currenDirectoryName = currentUser.Files.Where(f => f.Id == id).FirstOrDefault().Name; } searchLocation = "Directory - (" + currenDirectoryName + ")"; searchResult = files.Project().To <FileViewModel>();; } else { files = currentUser.Files.AsQueryable(); searchResult = CommonFunc.FileSearchQuery( files, fileName, fileType, fromSizeInDim, toSizeInDim) .Project() .To <FileViewModel>(); } sortBy = sortBy ?? "Name"; switch (sortBy) { case "Name desc": searchResult = searchResult.OrderByDescending(f => f.Name); break; case "Size desc": searchResult = searchResult.OrderByDescending(f => f.Size); break; case "Size": searchResult = searchResult.OrderBy(f => f.Size); break; default: searchResult = searchResult.OrderBy(f => f.Name); break; } var founded = searchResult.ToPagedList(page ?? 1, recordsOnPage); var result = new UploadViewModel(founded, searchLocation, currentDirectoryId, sortBy); return(result); }