Exemple #1
0
        private Select2PagedResult AttendeesToSelect2Format(List<Attendee> attendees, int totalAttendees)
        {
            Select2PagedResult jsonAttendees = new Select2PagedResult();
            jsonAttendees.Results = new List<Select2Result>();

            //Loop through our attendees and translate it into a text value and an id for the select list
            foreach (Attendee a in attendees)
            {
                jsonAttendees.Results.Add(new Select2Result { id = a.AttendeeId.ToString(), text = a.FirstName + " " + a.LastName });
            }
            //Set the total count of the results from the query.
            jsonAttendees.Total = totalAttendees;

            return jsonAttendees;
        }
        public ActionResult GetAttendees(string searchTerm, int pageSize, int pageNum)
        {
            //Get the paged results and the total count of the results for this query.
            AttendeeRepository ar        = new AttendeeRepository();
            List <Attendee>    attendees = ar.GetAttendees(searchTerm, pageSize, pageNum);
            int attendeeCount            = ar.GetAttendeesCount(searchTerm, pageSize, pageNum);

            //Translate the attendees into a format the select2 dropdown expects
            Select2PagedResult pagedAttendees = AttendeesToSelect2Format(attendees, attendeeCount);

            //Return the data as a jsonp result
            return(new JsonpResult
            {
                Data = pagedAttendees,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        private Select2PagedResult AttendeesToSelect2Format(List <Attendee> attendees, int totalAttendees)
        {
            Select2PagedResult jsonAttendees = new Select2PagedResult();

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

            //Loop through our attendees and translate it into a text value and an id for the select list
            foreach (Attendee a in attendees)
            {
                jsonAttendees.Results.Add(new Select2Result {
                    id = a.AttendeeId.ToString(), text = a.FirstName + " " + a.LastName
                });
            }
            //Set the total count of the results from the query.
            jsonAttendees.Total = totalAttendees;

            return(jsonAttendees);
        }