public Task <ListDto <FileDto> > ListAsync(ListFileQuery query, string email) { var queryable = _context.Files .Include(x => x.Recivers) .Where(x => x.CreatedAt < DateTime.Now && DateTime.Now < x.ExpiredAt) .Where(x => x.Recivers.Any(y => y.Email == email)); if (!string.IsNullOrEmpty(query.SearchBy)) { var searchBy = query.SearchBy.Trim().ToLower(); queryable = queryable.Where(x => x.Author.ToLower().Contains(searchBy) || x.Filename.ToLower().Contains(searchBy) || x.Id.ToLower().Contains(searchBy) ); } if (query.FileState.HasValue) { queryable = queryable.Where(x => x.FileState == query.FileState.Value); } if (query.FileType.HasValue) { queryable = queryable.Where(x => x.FileType == query.FileType.Value); } return(queryable .ProjectAndPageAsync <Db.Models.File, FileDto>(query)); }
public Task <ListDto <FileDto> > ListAsync(ListFileQuery query) { var queryable = _context.Files.AsQueryable(); if (!string.IsNullOrEmpty(query.SearchBy)) { var searchBy = query.SearchBy.Trim().ToLower(); queryable = queryable.Where(x => x.Author.ToLower().Contains(searchBy) || x.Filename.ToLower().Contains(searchBy) || x.Id.ToLower().Contains(searchBy) ); } if (query.FileState.HasValue) { queryable = queryable.Where(x => x.FileState == query.FileState.Value); } if (query.FileType.HasValue) { queryable = queryable.Where(x => x.FileType == query.FileType.Value); } return(queryable .ProjectAndPageAsync <Db.Models.File, FileDto>(query)); }
public async Task <IActionResult> ListAsync([FromQuery] ListFileQuery query) { string email = string.Empty; if (User.Identity.IsAuthenticated) { email = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Email).Value; } if (string.IsNullOrEmpty(email)) { return(Unauthorized()); } return(Ok(await _externalFileService.ListAsync(query, email))); }
public FileList List([FromQuery] ListFileQuery query) { var dir = query.Dir; if (dir == null) { dir = ""; } dir = DefaultTargetFileInfo.RemovePathBase(dir, HttpContext.Request.PathBase); return(new FileList { Directories = fileFinder.EnumerateContentDirectories(dir).Select(i => i.Replace('\\', '/')), Files = fileFinder.EnumerateContentFiles(dir).Select(i => i.Replace('\\', '/')), Path = dir }); }
public async Task ListFiles_ExpectedBehaviour() { //Arrange var authClient = await GetAuthorizedClientAsync(); var query = new ListFileQuery() { PageSize = 20, PageIndex = 0, }; //Act var result = await authClient.GetAsync($"/file/list?pageSize={query.PageSize}&pageIndex={query.PageIndex}"); var jsonResult = await result.Content.ReadAsAsync <ListDto <FileDto> >(); //Assert Assert.NotNull(jsonResult); Assert.True(jsonResult.Items.Count > 1); Assert.Equal(0, jsonResult.PageIndex); Assert.True(jsonResult.Count > 1); Assert.Equal(20, jsonResult.PageSize); }
public async Task <IActionResult> ListAsync([FromQuery] ListFileQuery query) { return(Ok(await _fileService.ListAsync(query))); }