private List <TvShowResponse> FilterByNetworks(SearchByParameters parameters, List <TvShowResponse> finalTvShows, List <TvShowResponse> mappedTvShows) { var tvShowsByNetworkFinal = new List <TvShowResponse>(); foreach (var network in parameters.Networks) { if (parameters.Categories != null && parameters.Categories.Length > 0) { var tvShowsByNetwork = finalTvShows.FindAll(x => x.Network == network); foreach (var tvShow in tvShowsByNetwork) { if (!tvShowsByNetworkFinal.Contains(tvShow)) { tvShowsByNetworkFinal.Add(tvShow); } } } else { var tvShowsByNetwork = mappedTvShows.FindAll(x => x.Network == network); foreach (var tvShow in tvShowsByNetwork) { if (!tvShowsByNetworkFinal.Contains(tvShow)) { tvShowsByNetworkFinal.Add(tvShow); } } } } return(tvShowsByNetworkFinal); }
public async Task <ResponseDto <SortedTvShowsResponse> > GetAllTvShows(SearchByParameters parameters) { var response = new ResponseDto <SortedTvShowsResponse>(); response.DtoObject = new SortedTvShowsResponse(); response.DtoObject.TvShowsList = new List <TvShowResponse>(); var tvShows = await _tvShowRepository.GetAll(x => x.TvSeriesRatings, x => x.Seasons).ToListAsync(); var mappedTvShows = new List <TvShowResponse>(); foreach (var tvShow in tvShows) { var assignments = await _actorAssignmentService.GetTvShowAssignments(tvShow.Id); var mappedTvShow = _mapper.Map <TvShowResponse>(tvShow); var categoryAssignments = await _tvShowCategoriesAssignmentsService.GetTvShowsCategories(tvShow.Id); mappedTvShow.Actors = assignments.DtoObject; mappedTvShow.Categories = categoryAssignments.DtoObject; mappedTvShows.Add(mappedTvShow); } if ((parameters.Categories != null && parameters.Categories.Length > 0) || (parameters.Networks != null && parameters.Networks.Length > 0)) { var finalTvShows = FilterByCategories(parameters.Categories, mappedTvShows); response.DtoObject.TvShowsList = finalTvShows; if (parameters.Networks != null && parameters.Networks.Length > 0) { response.DtoObject.TvShowsList = FilterByNetworks(parameters, finalTvShows, mappedTvShows); } } else { response.DtoObject.TvShowsList = mappedTvShows; } if (parameters.Status != 0) { response.DtoObject.TvShowsList = response.DtoObject.TvShowsList.FindAll(x => x.Status == parameters.Status); } var totalTvShowsNumber = response.DtoObject.TvShowsList.Count; double totalPageCount = Math.Ceiling((double)totalTvShowsNumber / parameters.PageSize); response.DtoObject.TvShowsList = response.DtoObject.TvShowsList.Skip(parameters.PageNumber * parameters.PageSize - parameters.PageSize) .Take(parameters.PageSize).ToList(); response.DtoObject.PageSize = parameters.PageSize; response.DtoObject.ActivePageNumber = parameters.PageNumber; response.DtoObject.TotalPageNumber = totalPageCount; return(response); }
public async Task <IActionResult> GetTvShows([FromBody] SearchByParameters parameters) { var tvShows = await _tvShowService.GetAllTvShows(parameters); return(Ok(tvShows)); }