public TableModelView <T> GetEntityFromFilterOption(FilterOptionModelView filterModelOption, IQueryable <T> db) { IQueryable <T> query; if (filterModelOption.phrase != null) //filter collection using phrase { query = db.Where(FilterFunction); } else { query = db; } if (!filterModelOption.orderMode)//sort element { query = query.OrderBy(SortFunction); } else { query = query.OrderByDescending(SortFunction); } int numberOfFilteredElm = query.Count();//The number will be used to calculate last page. IEnumerable <T> elements = query.Skip((filterModelOption.page - 1) * filterModelOption.elements).Take(filterModelOption.elements); return(new TableModelView <T>() { NumberOfFilteredElm = numberOfFilteredElm, Elements = elements }); }
public TableModelView <PollEntity> GetPollsFromFilterOption(FilterOptionModelView filterModelOption, IQueryable <PollEntity> polls) { PaginationHandler <PollEntity> paginationHandler = new PaginationHandler <PollEntity>(GetProperSortExpression(filterModelOption.nameSort), GetFilterExpression(filterModelOption.phrase)); return(paginationHandler.GetEntityFromFilterOption(filterModelOption, polls)); }
//show list of all user public ActionResult Users(FilterOptionModelView filterOptionModelView) { if (!ModelState.IsValid) { return(new HttpStatusCodeResult(400)); } var tableModelView = appUserManager.GetListUser(filterOptionModelView, db.Set <ApplicationUser>()); ViewBag.Elements = tableModelView.NumberOfFilteredElm; return(View(tableModelView)); }
//show list of all polls public ActionResult Polls(FilterOptionModelView filterOptionModelView) { if (!ModelState.IsValid) { return(new HttpStatusCodeResult(400)); } var tableModelView = AdminPollManager.GetPollsFromFilterOption(filterOptionModelView, db.Set <PollEntity>().Include("UserCreator")); ViewBag.Elements = tableModelView.NumberOfFilteredElm; return(View(tableModelView)); }
//list of all polls public ActionResult Explore(FilterOptionModelView filterOptionModelView) { if (ModelState.IsValid) { var tableModelView = pollManager.GetPollsFromFilterOption(filterOptionModelView, db.Set <PollEntity>()); ViewBag.Elements = tableModelView.NumberOfFilteredElm; return(View(tableModelView)); } else { return(new HttpStatusCodeResult(500)); } }
public void GetPollsFromFilterOption_Option_Phrasepizza_nameSortQuestion_Element2_page1() { var options = new FilterOptionModelView() { elements = 2, page = 1, nameSort = "View", phrase = "pizza" }; var paginationHandler = new PaginationHandler <PollEntity>(x => x.View, x => x.Question.ToLower().Contains(options.phrase)); var resultTable = paginationHandler.GetEntityFromFilterOption(options, listPolls.AsQueryable()); var expectedTable = new TableModelView <PollEntity>() { Elements = new List <PollEntity>() { listPolls[6], listPolls[7] }, NumberOfFilteredElm = 2 }; AreTableModelViewEqual(expectedTable, resultTable); }
public void GetPollsFromFilterOption_Option_nameSortQuestion_Element3_page4() { var options = new FilterOptionModelView() { elements = 3, page = 4, nameSort = "Question" }; var paginationHandler = new PaginationHandler <PollEntity>(x => x.Question, x => true); var resultTable = paginationHandler.GetEntityFromFilterOption(options, listPolls.AsQueryable()); var expectedTable = new TableModelView <PollEntity>() { Elements = new List <PollEntity>() { listPolls[7], listPolls[6] }, NumberOfFilteredElm = 11 }; AreTableModelViewEqual(expectedTable, resultTable); }
public void GetPollsFromFilterOption_Option_Element5_page3() { var options = new FilterOptionModelView() { elements = 5, page = 3 }; var paginationHandler = new PaginationHandler <PollEntity>(x => x.DateTime, x => true); var resultTable = paginationHandler.GetEntityFromFilterOption(options, listPolls.AsQueryable()); var expectedTable = new TableModelView <PollEntity>() { Elements = new List <PollEntity>() { listPolls[9] }, NumberOfFilteredElm = 11 }; AreTableModelViewEqual(expectedTable, resultTable); }
public TableModelView <ApplicationUser> GetListUser(FilterOptionModelView filterOptionModelView, IQueryable <ApplicationUser> applicationUsers) { var paginationHandler = new PaginationHandler <ApplicationUser>(GetProperSortExpression(filterOptionModelView.nameSort), GetFilterExpression(filterOptionModelView.phrase)); return(paginationHandler.GetEntityFromFilterOption(filterOptionModelView, applicationUsers)); }