// GET: Posters public ActionResult Index([FromQuery] PosterQuery query) { try { return(View(getPosters.Execute(query))); } catch (EntityNotAllowedException) { return(RedirectToAction("PageNotFound", "Redirections")); } catch (Exception e) { TempData["error"] = e.Message; } return(RedirectToAction("Home", "Index")); }
public IActionResult Get([FromQuery] PosterQuery query) { try { return(Ok(getPosters.Execute(query))); } catch (Exception e) { return(StatusCode(500, new { Errors = new List <string> { e.Message } })); } }
public PagedResponse <PosterDto> Execute(PosterQuery request) { var query = Context.Posters .Include(m => m.Movie) .AsQueryable(); query = query.Where(p => p.IsDeleted == false); if (request.PosterName != null) { query = query.Where(p => p.PosterTitle.ToLower().Contains(request.PosterName.ToLower())); } if (request.MovieName != null) { query = query.Where(m => m.Movie.Title.ToLower().Contains(request.MovieName.ToLower())); } if (request.MovieId > 0) { query = query.Where(p => p.MovieId == request.MovieId); } var totalCount = query.Count(); query = query.Skip((request.PageNumber - 1) * request.PerPage).Take(request.PerPage); var pagesCount = (int)Math.Ceiling((double)totalCount / request.PerPage); return(new PagedResponse <PosterDto> { CurrentPage = request.PageNumber, PagesCount = pagesCount, TotalCount = totalCount, Data = query.Select(p => new PosterDto { Id = p.Id, PosterTitle = p.PosterTitle, Name = p.Name, Alt = p.Alt, MovieId = p.MovieId, MovieName = p.Movie.Title }) }); }