コード例 #1
0
        public ParentListViewModel GetParentList(SearchParentsModel searchModel, int page = 1)
        {
            int pageSize = 20;

            if (page < 1)
            {
                page = 1;
            }

            IEnumerable <Parent> records = db.Parents.ToList();

            // Remove any default information
            //searchModel.ParseRouteInfo();

            if (!String.IsNullOrEmpty(searchModel.Name))
            {
                string name = searchModel.Name.ToLower();
                records = records.SelectMany(x => x.Students).Where(y => y.Student.Matches(name)).Select(m => m.Parent);
            }

            if (!String.IsNullOrEmpty(searchModel.ParentName))
            {
                string parentName = searchModel.ParentName.ToLower();
                records = records.Where(x => x.Matches(parentName));
            }

            records = records.Where(x => !x.Terminated.HasValue);

            return(new ParentListViewModel
            {
                Parents = records
                          .OrderByDescending(o => o.Added)
                          .ThenBy(o => o.FullName)
                          .Skip((page - 1) * pageSize)
                          .Take(pageSize),
                SearchModel = searchModel,
                PagingInfo = new PagingInfo
                {
                    CurrentPage = page,
                    PageSize = pageSize,
                    TotalItems = records.Count()
                }
            });
        }
コード例 #2
0
        public ActionResult Index(SearchParentsModel search, int page = 1)
        {
            // Return all Parents
            // If not a post-back (i.e. initial load) set the searchModel to session
            if (Request.Form.Count <= 0)
            {
                if (search.IsEmpty() && Session["SearchParentsModel"] != null)
                {
                    search = (SearchParentsModel)Session["SearchParentsModel"];
                }
            }

            var helper = new ParentHelper();
            var model = helper.GetParentList(search, search.ParsePage(page));

            Session["SearchParentsModel"] = search;
            
            return View(model);
        }