Пример #1
0
 public async Task <IEnumerable <User> > GetAllWithPaginationAsync(MovieFilters filters)
 {
     return(_repository.GetAllAsync().Result.OrderBy(u => u.Name)
            .Skip((filters.Page - 1) * filters.ItemsPerPage)
            .Take(filters.ItemsPerPage)
            .ToList());
 }
Пример #2
0
        public IEnumerable <dynamic> GetAllWithPaginationAsync(MovieFilters filters)
        {
            var            movies = _repository.GetAllIncludeActorsAsync().Result.AsEnumerable();
            List <dynamic> result = new List <dynamic>();

            if (!string.IsNullOrEmpty(filters.Name))
            {
                movies = movies.Where(x => x.Name.ToLower().Contains(filters.Name.ToLower()));
            }

            if (!string.IsNullOrEmpty(filters.Genre))
            {
                movies = movies.Where(x => x.Genre.Name.ToLower().Contains(filters.Genre.ToLower()));
            }

            if (!string.IsNullOrEmpty(filters.Diretor))
            {
                movies = movies.Where(x => (x.Director.FirstName.ToLower().Contains(filters.Diretor.ToLower()) || (x.Director.LastName.ToLower().Contains(filters.Diretor.ToLower()))));
            }

            if (!string.IsNullOrEmpty(filters.Actor))
            {
                movies = movies.Where(x => x.MovieActor.Any(y => y.Actor.FirstName.ToLower().Contains(filters.Actor.ToLower())));
            }

            if (filters.ItemsPerPage != 0 && filters.Page != 0)
            {
                movies = movies.Skip((filters.Page - 1) * filters.ItemsPerPage).Take(filters.ItemsPerPage);
            }

            movies = movies.OrderByDescending(x => x?.Rating?.Average(y => y?.Rate));

            foreach (var m in movies)
            {
                result.Add(new
                {
                    id          = m.Id,
                    name        = m.Name,
                    description = m.Description,
                    director    = m.Director,
                    actors      = m.MovieActor,
                    genre       = m.Genre,
                    rating      = m?.Rating?.Average(y => y?.Rate) ?? 0
                });
            }

            return(result);
        }
Пример #3
0
        public async Task <IActionResult> Post([FromBody] MovieFilters filters)
        {
            try
            {
                var movies = _movieService.GetAllWithPaginationAsync(filters);

                if (movies == null)
                {
                    return(NotFound());
                }
                return(Ok(movies));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Request Error"));
            }
        }