public RsvpSet GetFilteredRSVPs(int dinnerId, int start, int count, string sortType, string sortColumn, string filter) { var rsvps = _rsvps.Where(a => a.DinnerId == dinnerId).ToList(); var totalCount = rsvps.Count(); var filteredCount = rsvps.Count; var toReturn = rsvps.Skip(start).Take(count); var result = new RsvpSet() {FilteredRsvpCount = filteredCount, Rsvps = toReturn.ToList(), TotalRsvpCount = totalCount}; return result; }
/// <summary> /// Returns a filtered set of RSVPs /// </summary> /// <param name="dinnerId"> /// The dinner id. /// </param> /// <param name="start"> /// The start. /// </param> /// <param name="count"> /// The count. /// </param> /// <param name="filter"> /// The filter. /// </param> /// <param name="sortType"> /// The sort type. /// </param> /// <param name="sortColumn"> /// The sort column. /// </param> /// <returns> /// A set of RSVPs /// </returns> public RsvpSet GetFilteredRSVPs(int dinnerId, int start, int count, string filter, string sortType, string sortColumn) { using (NerdDinnersDb nerdDinnersDb = new NerdDinnersDb()) { var rsvps = nerdDinnersDb.RSVPs.Where(a => a.DinnerId == dinnerId); var totalCount = rsvps.Count(); var filteredQuery = rsvps.AsQueryable(); if (!string.IsNullOrEmpty(filter)) { filteredQuery = from d in rsvps where d.AttendeeEmail.Contains(filter) select d; } var filteredCount = filteredQuery.Count(); var sortColumnLower = sortColumn.ToLower(); var orderingFunction = new Func<Rsvp, IComparable>(d => d.AttendeeEmail); List<Rsvp> sortedRSVPs; if (sortType == "asc") { sortedRSVPs = ( from d in filteredQuery select d).OrderBy(orderingFunction).ToList(); } else if (sortType == "desc") { sortedRSVPs = (from d in filteredQuery select d).OrderByDescending(orderingFunction).ToList(); } else { sortedRSVPs = filteredQuery.ToList(); } var pageRSVPs = sortedRSVPs.Skip(start).Take(count); var result = new RsvpSet() { Rsvps = pageRSVPs.ToList(), FilteredRsvpCount = filteredCount, TotalRsvpCount = totalCount }; return result; } }