public PaginatedList <MovieGetModel> GetAll(DateTime?from, DateTime?to, int page) { IQueryable <Movie> result = context .Movies .OrderBy(f => f.Id) .Include(f => f.Comments); PaginatedList <MovieGetModel> paginatedResult = new PaginatedList <MovieGetModel>(); paginatedResult.CurrentPage = page; if (from != null) { result = result.Where(f => f.DateAdded >= from); } if (to != null) { result = result.Where(f => f.DateAdded <= to); } paginatedResult.NumberOfPages = (result.Count() - 1) / PaginatedList <MovieGetModel> .EntriesPerPage + 1; result = result .Skip((page - 1) * PaginatedList <MovieGetModel> .EntriesPerPage) .Take(PaginatedList <MovieGetModel> .EntriesPerPage); paginatedResult.Entries = result.Select(f => MovieGetModel.FromMovie(f)).ToList(); return(paginatedResult); }
public PaginatedList <MovieGetModel> GetAll(int page, DateTime?from = null, DateTime?to = null) { IQueryable <Movie> result = context .Movies .OrderBy(m => m.Id) .Include(c => c.Comments).OrderByDescending(m => m.ReleaseYear); PaginatedList <MovieGetModel> paginatedResult = new PaginatedList <MovieGetModel>(); paginatedResult.CurrentPage = page; if (from != null) { result = result.Where(e => e.DateAdded >= from); } if (to != null) { result = result.Where(e => e.DateAdded <= to); } paginatedResult.NumberOfPages = (result.Count() - 1) / PaginatedList <MovieGetModel> .EntriesPerPage + 1; result = result .Skip((page - 1) * PaginatedList <MovieGetModel> .EntriesPerPage) .Take(PaginatedList <MovieGetModel> .EntriesPerPage); paginatedResult.Entries = result.Select(m => MovieGetModel.FromMovie(m)).ToList(); return(paginatedResult); }
public PaginatedList <MovieGetModel> GetAll(int page, DateTime?from = null, DateTime?to = null, Genre?genre = null) { IQueryable <Movie> result = context .Movies .OrderBy(m => m.Id) .Include(m => m.Owner) .Include(m => m.Comments); PaginatedList <MovieGetModel> paginatedResult = new PaginatedList <MovieGetModel>(); paginatedResult.CurrentPage = page; if (from != null) { result = result.Where(m => m.Date >= from); } if (to != null) { result = result.Where(m => m.Date <= to); } if (genre != null) { result = result.Where(m => m.Genre == genre); } paginatedResult.NumberOfPages = (result.Count() - 1) / PaginatedList <MovieGetModel> .EntriesPerPage + 1; result = result .Skip((page - 1) * PaginatedList <MovieGetModel> .EntriesPerPage) .Take(PaginatedList <MovieGetModel> .EntriesPerPage); paginatedResult.Entries = result.Select(m => MovieGetModel.FromMovie(m)).ToList(); return(paginatedResult); }
public PaginatedList <MovieGetModel> GetAll(int page, DateTime?from = null, DateTime?to = null) { IQueryable <Movie> result = context .Movies .OrderBy(m => m.Id) .Include(m => m.Comments); PaginatedList <MovieGetModel> paginatedResult = new PaginatedList <MovieGetModel>(); paginatedResult.CurrentPage = page; if (from != null) { result = result.Where(f => f.DateAdded >= from); } if (to != null) { result = result.Where(f => f.DateAdded <= to); } paginatedResult.NumberOfPages = (result.Count() - 1) / PaginatedList <MovieGetModel> .EntriesPerPage + 1; result = result .Skip((page - 1) * PaginatedList <MovieGetModel> .EntriesPerPage) .Take(PaginatedList <MovieGetModel> .EntriesPerPage); paginatedResult.Entries = result.Select(f => MovieGetModel.FromMovie(f)).ToList(); return(paginatedResult); //IQueryable<Movie> result = context // .Movies // .Include(f => f.Comments); //if (from == null && to == null) //{ // return result.Select(f => MovieGetModel.FromMovie(f)); //} //if (from != null) //{ // result = result.Where(f => f.DateAdded >= from); //} //if (to != null) //{ // result = result.Where(f => f.DateAdded <= to); //} //result = result.OrderBy(x => x.YearRelease); //return result.Select(f => MovieGetModel.FromMovie(f)); }
public IEnumerable <MovieGetModel> GetAll(DateTime?from = null, DateTime?to = null) { IQueryable <Movie> result = context.Movies.Include(c => c.Comments).OrderByDescending(m => m.ReleaseYear); if (from == null && to == null) { return(result.Select(m => MovieGetModel.FromMovie(m))); } if (from != null) { result = result.Where(e => e.DateAdded >= from); } if (to != null) { result = result.Where(e => e.DateAdded <= to); } return(result.Select(m => MovieGetModel.FromMovie(m))); }
public IEnumerable <MovieGetModel> GetAll(DateTime?from = null, DateTime?to = null) { IQueryable <Movie> result = context .Movies .Include(f => f.Comments); if (from == null && to == null) { return(result.Select(f => MovieGetModel.FromMovie(f))); } if (from != null) { result = result.Where(m => m.Date >= from); } if (to != null) { result = result.Where(m => m.Date <= to); } return(result.Select(m => MovieGetModel.FromMovie(m))); }
public IEnumerable <MovieGetModel> GetAll(DateTime?from = null, DateTime?to = null) { IQueryable <Movie> result = context .Movies .Include(f => f.Comments); if (from == null && to == null) { return(result.Select(f => MovieGetModel.FromMovie(f))); } if (from != null) { result = result.Where(f => f.DateAdded >= from); } if (to != null) { result = result.Where(f => f.DateAdded <= to); } result = result.OrderBy(x => x.YearRelease); return(result.Select(f => MovieGetModel.FromMovie(f))); }
public IEnumerable <MovieGetModel> GetAllMovies(DateTime?from = null, DateTime?to = null) { IQueryable <Movie> result = DbContext.Movies.Include(f => f.Comment).OrderByDescending(f => f.ReleaseYear); if (from == null && to == null) { return(result.Select(movie => MovieGetModel.FromMovie(movie))); } if (from != null) { result = result.Where(f => f.DateAdded > from); } if (to != null) { result = result.Where(f => f.DateAdded < to); } foreach (var entity in result.Select(movie => MovieGetModel.FromMovie(movie))) { Console.WriteLine(entity.ToString()); } return(result.Select(movie => MovieGetModel.FromMovie(movie))); }