public dynamic Get()
        {
            var echo = HttpContext.Current.Request.Params["sEcho"];
            var totalRecords = Convert.ToInt32(HttpContext.Current.Request.Params["iTotalRecords"]);
            var guestFilter = new GuestFilter();

            guestFilter.DisplayLength = Convert.ToInt32(HttpContext.Current.Request["iDisplayLength"]);
            guestFilter.DisplayStart = Convert.ToInt32(HttpContext.Current.Request["iDisplayStart"]);
            guestFilter.GlobalSearch = HttpContext.Current.Request.Params["sSearch"];
            guestFilter.Name = HttpContext.Current.Request["sSearch_0"];
            guestFilter.MailAddress = HttpContext.Current.Request["sSearch_1"];
            guestFilter.Country = HttpContext.Current.Request["sSearch_2"];
            guestFilter.SetAnniversary(HttpContext.Current.Request["sSearch_3"]);
            guestFilter.Gender = HttpContext.Current.Request["sSearch_4"];
            guestFilter.SetSortingCol(HttpContext.Current.Request["iSortCol_0"]);
            guestFilter.SetSortingDir(HttpContext.Current.Request["sSortDir_0"]);

            var guestRepository = new GuestRepository(DataCache.Guests);
            var data = guestRepository.GetGuests(guestFilter).Select(g => new { 
                    g.Name,
                    g.MailAddress,
                    g.Country,
                    Anniversary = g.Anniversary.ToString("dd/MM/yyyy"),
                    g.Gender
                }).ToList();
            return new
            {
                sEcho = echo,
                iTotalRecords = guestRepository.CountTotalGuests(),
                iTotalDisplayRecords = guestRepository.CountWithFilter(guestFilter),
                aaData = data
            };
        }
 public void MustSetDefaultPropertyOnError() 
 {
     var guestFilter = new GuestFilter();
     guestFilter.SetSortingCol("88");
     var guestName = "Name of the guest";
     var guestMail = "*****@*****.**";
     var guest = new Guest(guestName, guestMail);
     var prop = guestFilter.GetSortingProp(guest);
     Assert.IsTrue(prop.ToString() == guestName);        
 }
        public IList<Guest> GetGuests(GuestFilter guestFilter)
        {
            var query = GetGuestsIEnumerable(guestFilter);
            
            if (guestFilter.SortDirection == SortDirection.Desc)
                query = query.OrderByDescending(guest => guestFilter.GetSortingProp(guest));
            else
                query = query.OrderBy(guest => guestFilter.GetSortingProp(guest));

            return query.Skip(guestFilter.DisplayStart)
                        .Take(guestFilter.DisplayLength)
                        .ToList<Guest>();
        }
        private IEnumerable<Guest> GetGuestsIEnumerable(GuestFilter guestFilter)
        {
            var query = (from p in _guests
                    where
                        !string.IsNullOrEmpty(guestFilter.GlobalSearch) ?
                        (
                                (p.Name.Contains(guestFilter.GlobalSearch) ||
                                p.MailAddress.Contains(guestFilter.GlobalSearch) ||
                                p.Country.Contains(guestFilter.GlobalSearch) ||
                                p.Gender.Contains(guestFilter.GlobalSearch))
                        ) : 1 == 1
                    select p);

            if (guestFilter.IsNameSearch()) {
                query = query.Where(guest => guest.Name != null && guest.Name.ToLower().Contains(guestFilter.Name));
            }
            if (guestFilter.IsMailAddressSearch())
            {
                query = query.Where(guest => guest.MailAddress != null && guest.MailAddress.ToLower().Contains(guestFilter.MailAddress));
            }
            if (guestFilter.IsCountrySearch())
            {
                query = query.Where(guest => guest.Country != null && guest.Country.ToLower().Contains(guestFilter.Country));
            }

            if (guestFilter.IsAnniversarySearch())
            {
                query = query.Where(guest => guest.Anniversary.Date.Equals(guestFilter.Anniversary));
            }

            if (guestFilter.IsGenderSearch()) {
                query = query.Where(guest => guest.Gender != null && guest.Gender.Equals(guestFilter.Gender, StringComparison.CurrentCultureIgnoreCase));
            }

            return query;

        }
 public int CountWithFilter(GuestFilter guestFilter) 
 {
     return GetGuestsIEnumerable(guestFilter).Count();
 }