Пример #1
0
        private Select2PagedResult ToSelect2Format(List <Student> students, int totalStudents, bool byLastName)
        {
            Select2PagedResult jsonStudents = new Select2PagedResult();

            jsonStudents.Results = new List <Select2Result>();

            //Loop through our attendees and translate it into a text value and an id for the select list
            if (byLastName)
            {
                foreach (Student a in students)
                {
                    jsonStudents.Results.Add(new Select2Result {
                        id = a.ID.ToString(), text = a.LastName + ", " + a.FirstName
                    });
                }
            }
            else
            {
                foreach (Student a in students)
                {
                    jsonStudents.Results.Add(new Select2Result {
                        id = a.ID.ToString(), text = a.FirstName + " " + a.LastName
                    });
                }
            }

            //Set the total count of the results from the query.
            jsonStudents.Total = totalStudents;

            return(jsonStudents);
        }
Пример #2
0
        public ActionResult GetStudentsName(string searchTerm, int pageSize, int pageNum, bool byLastName)  // true: get by last name
                                                                                                            // false: get by first name
        {
            //Get the paged results and the total count of the results for this query.
            LitProReadEntities db = new LitProReadEntities();

            List <Student> students     = db.GetStudents(searchTerm, pageSize, pageNum, byLastName);
            int            studentCount = db.GetStudentsCount(searchTerm, pageSize, pageNum);

            //Translate the attendees into a format the select2 dropdown expects
            Select2PagedResult pagedStudents = ToSelect2Format(students, studentCount, byLastName);

            //Return the data as a jsonp result
            return(new JsonpResult
            {
                Data = pagedStudents,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }