//api/movies public async Task <ActionResult <IEnumerable <MovieInfoDto> > > GetMovies([FromQuery] UserParamsDto userParamsDto) { var movies = await _movieAction.GetMovies(userParamsDto); Response.AddPaginationHeader(movies.CurrentPage, movies.PageSize, movies.TotalCount, movies.TotalPages); return(Ok(movies)); }
public async Task <IActionResult> GetUSers([FromQuery] UserParamsDto userParams) { var callerUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); var callerUser = await _repo.GetUser(callerUserId); userParams.UserId = callerUser.Id; if (string.IsNullOrEmpty(userParams.Gender)) { userParams.Gender = callerUser.Gender == "male"? "female" : "male"; } var users = await _repo.GetUsers(userParams); var userDto = _mapper.Map <IEnumerable <UserForListDto> >(users); Response.AddPaginationHeader( new PaginationHeaders( userParams.PageNumber, userParams.PageSize, users.TotalCount, users.TotalPages)); return(Ok(userDto)); }
public async Task <Grid <UserWithPhotosDto> > FindAll(UserParamsDto userParams) { var query = this.context.User.AsQueryable(); if (userParams.Gender != 0 && userParams.Gender != 0) { query = query.Where(o => o.Gender == userParams.Gender).AsNoTracking(); } var minAge = DateTime.Today.AddYears(-userParams.MaxAge - 1); var maxAge = DateTime.Today.AddYears(-userParams.MinAge); query = query.Where(u => u.DateOfBirth >= minAge && u.DateOfBirth <= maxAge); query = userParams.SortBy switch { "createdAt" => query.OrderByDescending(u => u.CreatedAt), _ => query.OrderByDescending(u => u.LastActive) }; return(await Grid <UserWithPhotosDto> .CreateGridAsync( query.ProjectTo <UserWithPhotosDto>(this.mapper.ConfigurationProvider).AsNoTracking(), userParams.Page, userParams.Limit )); }
public async Task <ActionResult <Grid <UserWithPhotosDto> > > Index([FromQuery] UserParamsDto gridParamsDto) { var result = await this.unitOfWork.UserRepository.FindAll(gridParamsDto); Response.AddPaginationHeader(result.Page, result.Limit, result.Total, result.TotalPages); return(Ok(result)); }
public async Task <PagedList <User> > GetUsers(UserParamsDto userParams) { var users = _context.Users .OrderByDescending(t => t.LastActiveDate) .AsQueryable(); users = users.Where(u => u.Id != userParams.UserId); if (userParams.Likers) { var likers = await GetLikers(userParams.UserId); users = users.Where(u => likers.Contains(u.Id)); } if (userParams.Likees) { var likees = await GetLikees(userParams.UserId); users = users.Where(u => likees.Contains(u.Id)); } if (!userParams.Likers && !userParams.Likees) { users = users.Where(gen => gen.Gender == userParams.Gender); } if (userParams.MinAge != 18) { users = users.Where(mg => mg.DateOfBirth <= DateTime.Today.AddYears(-userParams.MinAge)); } if (userParams.MaxAge != 99) { users = users.Where(xa => xa.DateOfBirth >= DateTime.Today.AddYears(-(userParams.MaxAge - 1))); } if (!string.IsNullOrEmpty(userParams.OrderBy)) { switch (userParams.OrderBy) { case "createDate": users = users.OrderByDescending(t => t.CreateDate); break; default: users = users.OrderByDescending(t => t.LastActiveDate); break; } } var pagedData = await PagedList <User> .CreateAsync(users, userParams.PageNumber, userParams.PageSize); return(pagedData); }
public async Task <PageList <Users> > GetUsers(UserParamsDto query) { var userList = _dbContext.Users.Include(p => p.Photos).AsQueryable(); userList = userList.Where(q => q.UserID != query.UserID); if (!string.IsNullOrEmpty(query.Gender)) { userList = userList.Where(q => q.Gender == query.Gender); } if (query.MinAge != 18 || query.MaxAge != 99) { var minDOB = DateTime.Now.AddYears(-query.MaxAge - 1); var maxDOB = DateTime.Now.AddYears(-query.MinAge); userList = userList.Where(q => q.DateofBirth >= minDOB && q.DateofBirth <= maxDOB); } query.Orderby = string.IsNullOrEmpty(query.Orderby) ? "lastactive" : query.Orderby; switch (query.Orderby) { case "created": userList = userList.OrderByDescending(q => q.CreatedDate); break; default: userList = userList.OrderByDescending(q => q.ActiveDate); break; } // users who like current user if (query.LikedUser) { userList = userList.Include(q => q.LikedUsers) .Where(q => q.LikedUsers.Select(z => z.LikedUserID).FirstOrDefault() == query.UserID); } // users who are liked by current user if (query.LikedByUser) { userList = userList.Include(q => q.LikeByUsers) .Where(q => q.LikeByUsers.Select(z => z.LikeByUserID).FirstOrDefault() == query.UserID); } var pageList = await PageList <Users> .CreateAsync(query.PageNumber, query.PageSize, userList); return(pageList); }
public async Task <IActionResult> GetUsers([FromQuery] UserParamsDto query) { int currentUID = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); query.UserID = currentUID; var users = await _datingrepo.GetUsers(query); var result = _mapper.Map <IEnumerable <UserListDto> >(users); Response.AddPaginationHeader(users.TotalCount, users.TotalPages, users.PageSize, users.CurrentPage); return(Ok(result)); }
public void GetMovies_IfNoSearchText_ReturnAllMoviesWithLatestYear() { //Arrange UserParamsDto userParamsDto = new UserParamsDto() { PageNumber = 1, PageSize = 5, SearchText = string.Empty, SearchTextType = string.Empty }; //Act var result = action.GetMovies(userParamsDto).GetAwaiter().GetResult(); //Assert Assert.AreEqual(result[0].Year, 2021); }
public void GetMovies_IfNoSearchText_ReturnAllMovies() { //Arrange UserParamsDto userParamsDto = new UserParamsDto() { PageNumber = 1, PageSize = 5, SearchText = string.Empty, SearchTextType = string.Empty }; //Act var result = action.GetMovies(userParamsDto).GetAwaiter().GetResult(); //Assert Assert.IsTrue(result.Count == 5); }
public void GetMovies_IfSearchWithText_ButNoMatching_ThenReturnEmpty() { //Arrange UserParamsDto userParamsDto = new UserParamsDto() { PageNumber = 1, PageSize = 5, SearchText = "Test Director 3", SearchTextType = "Director" }; //Act var result = action.GetMovies(userParamsDto).GetAwaiter().GetResult(); //Assert Assert.IsTrue(result.Count == 0); }
public void GetMovies_IfSearchWithYear_ReturnMoviesWithMatchingSearchedYearData() { //Arrange UserParamsDto userParamsDto = new UserParamsDto() { PageNumber = 1, PageSize = 5, SearchText = "2018", SearchTextType = "Year" }; //Act var result = action.GetMovies(userParamsDto).GetAwaiter().GetResult(); //Assert Assert.IsTrue(result.Count == 1); Assert.AreEqual(result[0].Year, 2018); }
public void GetMovies_IfSearchWithTitle_ReturnMoviesWithMatchingSearchedTitledData() { //Arrange UserParamsDto userParamsDto = new UserParamsDto() { PageNumber = 1, PageSize = 5, SearchText = "Movie 1", SearchTextType = "Title" }; //Act var result = action.GetMovies(userParamsDto).GetAwaiter().GetResult(); //Assert Assert.IsTrue(result.Count == 1); Assert.AreEqual(result[0].Title, "Test Movie 1"); }
public void GetMovies_IfSearchWithPlot_AndAnyPlotdataIsNull_ReturnMoviesWithMatchingSearchedPlotData() { //Arrange UserParamsDto userParamsDto = new UserParamsDto() { PageNumber = 1, PageSize = 4, SearchText = "Movie 1", SearchTextType = "Plot" }; //Act var result = action.GetMovies(userParamsDto).GetAwaiter().GetResult(); //Assert Assert.IsTrue(result.TotalCount == 1); Assert.AreEqual(result[0].Year, 2018); }
public void GetMovies_IfSearchWithActor_ReturnMoviesWithMatchingSearchedActorData() { //Arrange UserParamsDto userParamsDto = new UserParamsDto() { PageNumber = 1, PageSize = 5, SearchText = "Test Actor 2", SearchTextType = "Actor" }; //Act var result = action.GetMovies(userParamsDto).GetAwaiter().GetResult(); //Assert Assert.IsTrue(result.Count == 3); }
public async Task <PagedList <MovieInfoDto> > GetMovies(UserParamsDto userParamsDto) { var dbMovies = await _movieRepository.GetMovies(); if (!string.IsNullOrWhiteSpace(userParamsDto.SearchText) && !string.IsNullOrWhiteSpace(userParamsDto.SearchTextType)) { switch (userParamsDto.SearchTextType) { case "Year": dbMovies = dbMovies.Where(x => x.Year.ToString().Contains(userParamsDto.SearchText)); break; case "Plot": dbMovies = dbMovies.Where(x => !string.IsNullOrWhiteSpace(x.Plot) && x.Plot.Contains(userParamsDto.SearchText)); break; case "Title": dbMovies = dbMovies.Where(x => !string.IsNullOrWhiteSpace(x.Title) && x.Title.Contains(userParamsDto.SearchText)); break; case "Genre": dbMovies = dbMovies.Where(x => x.Genres.Select(x => x.Type).ToList().Contains(userParamsDto.SearchText)); break; case "Actor": dbMovies = dbMovies.Where(x => x.Actors.Select(x => x.Name).ToList().Contains(userParamsDto.SearchText)); break; case "Director": dbMovies = dbMovies.Where(x => x.Directors.Select(x => x.Name).ToList().Contains(userParamsDto.SearchText)); break; } } dbMovies = dbMovies.OrderByDescending(x => x.Year).ToList(); var totalCount = dbMovies.Count(); dbMovies = dbMovies.Skip((userParamsDto.PageNumber - 1) * userParamsDto.PageSize).Take(userParamsDto.PageSize).ToList(); var listOfMoviesInfo = _mapper.Map <IEnumerable <MovieInfoDto> >(dbMovies); return(new PagedList <MovieInfoDto>(listOfMoviesInfo, totalCount, userParamsDto.PageNumber, userParamsDto.PageSize)); }
public void GetMovies_IfSearchWithGenre_ReturnMoviesWithMatchingSearchedGenreData() { //Arrange UserParamsDto userParamsDto = new UserParamsDto() { PageNumber = 1, PageSize = 5, SearchText = "Comedy", SearchTextType = "Genre" }; //Act var result = action.GetMovies(userParamsDto).GetAwaiter().GetResult(); //Assert Assert.IsTrue(result.Count == 1); Assert.AreEqual(result[0].Year, 2020); Assert.AreEqual(result[0].Plot, "Test Plot For Movie 2"); }
public void GetMovies_IfTotalListIsGreaterThanPageSize_ThenReturnPagedList() { //Arrange UserParamsDto userParamsDto = new UserParamsDto() { PageNumber = 1, PageSize = 4, SearchText = string.Empty, SearchTextType = string.Empty }; //Act var result = action.GetMovies(userParamsDto).GetAwaiter().GetResult(); //Assert Assert.IsTrue(result.Count == userParamsDto.PageSize); Assert.IsTrue(result.CurrentPage == userParamsDto.PageNumber); Assert.IsTrue(result.TotalPages == 2); Assert.IsTrue(result.TotalCount == 5); }