Esempio n. 1
0
        public void Query()
        {
            if (string.IsNullOrWhiteSpace(this.AccountName))
            {
                var query = PointGiftService.Query().Where(x => x.State == PointGiftStates.Normal);


                List         = BuildQuery(query).ToList(this, x => x);
                CurrentPoint = 0;
            }
            else
            {
                var account = AccountService.GetByName(AccountName);
                if (account != null)
                {
                    AccountUser owner = null;
                    if (account.OwnerId.HasValue)
                    {
                        owner = (AccountUser)MembershipService.GetUserById(account.OwnerId.Value);
                    }
                    CurrentPoint = account.Point;
                    var accountLevel = AccountLevelPolicyService.Query().FirstOrDefault(x => x.Level == account.AccountLevel && account.AccountTypeId == x.AccountTypeId);

                    var query = PointGiftService.Query().Where(x => x.IsFor(account, owner, accountLevel, DateTime.Now));

                    List = BuildQuery(query).ToList(this, x => x);
                }
                else
                {
                    ErrorMessage = Localize("nofoundAccount", string.Format("ÕÊ»§ {0} δÕÒµ½", AccountName));
                    List         = new PageOfList <PointGift>(this.OrderBy, this.PageSize);
                }
            }
        }
Esempio n. 2
0
        // GET: MvcAppPager/TestPage
        public ActionResult Index(int pageIndex = 0)
        {
            counts = this._testPageRepository.GetTestPageList().Count();
            var list = this._testPageRepository.GetTestPageList().OrderBy(t => t.OrderNo).Skip(PageSize * pageIndex).Take(PageSize).ToList();
            PageOfList <TestPage> _testList = new PageOfList <TestPage>(list, pageIndex, PageSize, counts);

            return(View(_testList));
        }
Esempio n. 3
0
        public ActionResult Index(int pageIndex = 0)
        {
            counts = list.Count;
            list   = list.Skip(PageSize * pageIndex).Take(PageSize).ToList();
            PageOfList <Order> _orderList = new PageOfList <Order>(list, pageIndex, PageSize, counts);

            return(View(_orderList));
        }
Esempio n. 4
0
        private static PageOfList <TResult> ToList <T, TResult>(int pageIndex, int pageSize, string orderBy, Func <T, TResult> selector,
                                                                IEnumerable <T> list, int totalItemCount)
            where T : new()
        {
            var pageCount = PageOfList <TResult> .GetPageCount(totalItemCount, pageSize);

            if (pageCount < pageIndex)
            {
                pageIndex = pageCount == 0 ? 1 : pageCount;
            }
            var items = list.Select(selector).ToList();

            return(new PageOfList <TResult>(items, orderBy, pageIndex, pageSize, totalItemCount));
        }
Esempio n. 5
0
        public void SetupTests()
        {
            mockFootlooseFSService = new Mock <IFootlooseFSService>();

            pageIndex      = 0;
            pageSize       = 10;
            totalItemCount = 100;

            // Create PersonDocument test data
            PageOfList <PersonDocument> personDocuments = createTestData();

            // Mock SearchPersonDocument and UpdatePerson service methods
            mockFootlooseFSService.Setup(m => m.SearchPersonDocuments(It.IsAny <int>(), It.IsAny <PersonSearchColumn>(), It.IsAny <SortDirection>(), It.IsAny <int>(), It.IsAny <Dictionary <PersonSearchColumn, string> >())).Returns(personDocuments);
            mockFootlooseFSService.Setup(m => m.UpdatePerson(It.IsAny <Person>())).Returns((Person p) => { return(SetupOperationStatus(p)); });
        }
        public ActionResult Search(SearchParameters searchParameters)
        {
            // Serialize sort direction to an enum of SortDirection
            SortDirection sortDirection = SortDirection.Ascending;
            Enum.TryParse<SortDirection>(searchParameters.SortDirection, out sortDirection);

            var searchCriteria = new PersonDocument();

            if (searchParameters.SearchCriteria != null && searchParameters.SearchCriteria.Count() > 0)
            {
                foreach (var searchCriterion in searchParameters.SearchCriteria)
                {
                    if (!string.IsNullOrEmpty(searchCriterion.Value))
                    {
                        if (searchCriterion.Key == "PersonID")
                            searchCriteria.PersonID = Int32.Parse(searchCriterion.Value);
                        else if (searchCriterion.Key == "FirstName")
                            searchCriteria.FirstName = searchCriterion.Value;
                        else if (searchCriterion.Key == "LastName")
                            searchCriteria.LastName = searchCriterion.Value;
                        else if (searchCriterion.Key == "PhoneNumber")
                            searchCriteria.PhoneNumber = searchCriterion.Value;
                        else if (searchCriterion.Key == "StreetAddress")
                            searchCriteria.StreetAddress = searchCriterion.Value;
                        else if (searchCriterion.Key == "City")
                            searchCriteria.City = searchCriterion.Value;
                        else if (searchCriterion.Key == "Zip")
                            searchCriteria.Zip = searchCriterion.Value;
                        else if (searchCriterion.Key == "State")
                            searchCriteria.State = searchCriterion.Value;
                        else if (searchCriterion.Key == "EmailAddress")
                            searchCriteria.EmailAddress = searchCriterion.Value;
                    }
                }
            }

            var personsPage = personService.SearchPersons(searchParameters.PageNumber, searchParameters.NumberRecordsPerPage, searchParameters.SortColumn, sortDirection, searchCriteria);

            var pageOfListPersonDocuments = new PageOfList<PersonDocument>(personsPage.Data, searchParameters.PageNumber, searchParameters.NumberRecordsPerPage, personsPage.TotalItemCount);
            pageOfListPersonDocuments.SearchCriteria = searchParameters.SearchCriteria;

            return PartialView(pageOfListPersonDocuments);            
        }
Esempio n. 7
0
        public void SetupTests()
        {
            mockPersonService = new Mock <IPersonService>();

            pageIndex      = 0;
            pageSize       = 10;
            totalItemCount = 100;

            // Create PersonDocument test data
            PageOfList <PersonDocument> pageOfListPerson = createTestData();
            var pageOfPersonDocuments = new PageOfPersonDocuments();

            pageOfPersonDocuments.Data      = pageOfListPerson.Data;
            pageOfPersonDocuments.PageIndex = pageOfListPerson.PageIndex;
            pageOfPersonDocuments.PageSize  = pageOfListPerson.PageSize;

            // Mock SearchPersonDocument and UpdatePerson service methods
            mockPersonService.Setup(m => m.SearchPersons(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <SortDirection>(), It.IsAny <PersonDocument>())).Returns(pageOfPersonDocuments);
            mockPersonService.Setup(m => m.UpdatePerson(It.IsAny <Person>())).Returns((Person p) => { return(setupOperationStatus(p)); });
        }
        private PageOfList<PersonDocument> createTestData()
        {
            List<PersonDocument> personDocuments = new List<PersonDocument>();

            PersonDocument personDocument = new PersonDocument
            {
                PersonID = 1,
                FirstName = "Pam",
                LastName = "Scicchitano",
                EmailAddress = "*****@*****.**",
                PhoneNumber = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State = "NC",
                Zip = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID = 2,
                FirstName = "Dominique",
                LastName = "Marantz",
                EmailAddress = "*****@*****.**",
                PhoneNumber = "336-418-5159",
                State = "NC",
                Zip = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID = 3,
                FirstName = "Denese",
                LastName = "Cullars",
                EmailAddress = "*****@*****.**",
                PhoneNumber = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State = "NC",
                Zip = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID = 4,
                FirstName = "Gaynelle",
                LastName = "Resetar",
                EmailAddress = "*****@*****.**",
                PhoneNumber = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State = "NC",
                Zip = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID = 5,
                FirstName = "Melynda",
                LastName = "Stockton",
                EmailAddress = "*****@*****.**",
                PhoneNumber = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State = "NC",
                Zip = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID = 6,
                FirstName = "Rubye",
                LastName = "Humphers",
                EmailAddress = "*****@*****.**",
                PhoneNumber = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State = "NC",
                Zip = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID = 7,
                FirstName = "Otto",
                LastName = "Uy",
                EmailAddress = "*****@*****.**",
                PhoneNumber = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State = "NC",
                Zip = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID = 8,
                FirstName = "Carita",
                LastName = "Campain",
                EmailAddress = "*****@*****.**",
                PhoneNumber = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State = "NC",
                Zip = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID = 9,
                FirstName = "Luvenia",
                LastName = "Safe",
                EmailAddress = "*****@*****.**",
                PhoneNumber = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State = "NC",
                Zip = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID = 10,
                FirstName = "David",
                LastName = "ScicMilechitano",
                EmailAddress = "*****@*****.**",
                PhoneNumber = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State = "NC",
                Zip = "27215"
            };
            personDocuments.Add(personDocument);

            PageOfList<PersonDocument> personDocumentPage = new PageOfList<PersonDocument>(personDocuments, pageIndex, pageSize, totalItemCount);

            return personDocumentPage;
        }
Esempio n. 9
0
        private PageOfList <PersonDocument> createTestData()
        {
            List <PersonDocument> personDocuments = new List <PersonDocument>();

            PersonDocument personDocument = new PersonDocument
            {
                PersonID      = 1,
                FirstName     = "Pam",
                LastName      = "Scicchitano",
                EmailAddress  = "*****@*****.**",
                PhoneNumber   = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State         = "NC",
                Zip           = "27215"
            };

            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID     = 2,
                FirstName    = "Dominique",
                LastName     = "Marantz",
                EmailAddress = "*****@*****.**",
                PhoneNumber  = "336-418-5159",
                State        = "NC",
                Zip          = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID      = 3,
                FirstName     = "Denese",
                LastName      = "Cullars",
                EmailAddress  = "*****@*****.**",
                PhoneNumber   = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State         = "NC",
                Zip           = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID      = 4,
                FirstName     = "Gaynelle",
                LastName      = "Resetar",
                EmailAddress  = "*****@*****.**",
                PhoneNumber   = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State         = "NC",
                Zip           = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID      = 5,
                FirstName     = "Melynda",
                LastName      = "Stockton",
                EmailAddress  = "*****@*****.**",
                PhoneNumber   = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State         = "NC",
                Zip           = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID      = 6,
                FirstName     = "Rubye",
                LastName      = "Humphers",
                EmailAddress  = "*****@*****.**",
                PhoneNumber   = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State         = "NC",
                Zip           = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID      = 7,
                FirstName     = "Otto",
                LastName      = "Uy",
                EmailAddress  = "*****@*****.**",
                PhoneNumber   = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State         = "NC",
                Zip           = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID      = 8,
                FirstName     = "Carita",
                LastName      = "Campain",
                EmailAddress  = "*****@*****.**",
                PhoneNumber   = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State         = "NC",
                Zip           = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID      = 9,
                FirstName     = "Luvenia",
                LastName      = "Safe",
                EmailAddress  = "*****@*****.**",
                PhoneNumber   = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State         = "NC",
                Zip           = "27215"
            };
            personDocuments.Add(personDocument);

            personDocument = new PersonDocument
            {
                PersonID      = 10,
                FirstName     = "David",
                LastName      = "ScicMilechitano",
                EmailAddress  = "*****@*****.**",
                PhoneNumber   = "336-418-5159",
                StreetAddress = "38 S Dunworth St #4185",
                State         = "NC",
                Zip           = "27215"
            };
            personDocuments.Add(personDocument);

            PageOfList <PersonDocument> personDocumentPage = new PageOfList <PersonDocument>(personDocuments, pageIndex, pageSize, totalItemCount);

            return(personDocumentPage);
        }
        public ActionResult Search(SearchParameters searchParameters)
        {
            // Serialize sort direction to an enum of SortDirection
            SortDirection sortDirection = SortDirection.Ascending;

            Enum.TryParse <SortDirection>(searchParameters.SortDirection, out sortDirection);

            var searchCriteria = new PersonDocument();

            if (searchParameters.SearchCriteria != null && searchParameters.SearchCriteria.Count() > 0)
            {
                foreach (var searchCriterion in searchParameters.SearchCriteria)
                {
                    if (!string.IsNullOrEmpty(searchCriterion.Value))
                    {
                        if (searchCriterion.Key == "PersonID")
                        {
                            searchCriteria.PersonID = Int32.Parse(searchCriterion.Value);
                        }
                        else if (searchCriterion.Key == "FirstName")
                        {
                            searchCriteria.FirstName = searchCriterion.Value;
                        }
                        else if (searchCriterion.Key == "LastName")
                        {
                            searchCriteria.LastName = searchCriterion.Value;
                        }
                        else if (searchCriterion.Key == "PhoneNumber")
                        {
                            searchCriteria.PhoneNumber = searchCriterion.Value;
                        }
                        else if (searchCriterion.Key == "StreetAddress")
                        {
                            searchCriteria.StreetAddress = searchCriterion.Value;
                        }
                        else if (searchCriterion.Key == "City")
                        {
                            searchCriteria.City = searchCriterion.Value;
                        }
                        else if (searchCriterion.Key == "Zip")
                        {
                            searchCriteria.Zip = searchCriterion.Value;
                        }
                        else if (searchCriterion.Key == "State")
                        {
                            searchCriteria.State = searchCriterion.Value;
                        }
                        else if (searchCriterion.Key == "EmailAddress")
                        {
                            searchCriteria.EmailAddress = searchCriterion.Value;
                        }
                    }
                }
            }

            var personsPage = personService.SearchPersons(searchParameters.PageNumber, searchParameters.NumberRecordsPerPage, searchParameters.SortColumn, sortDirection, searchCriteria);

            var pageOfListPersonDocuments = new PageOfList <PersonDocument>(personsPage.Data, searchParameters.PageNumber, searchParameters.NumberRecordsPerPage, personsPage.TotalItemCount);

            pageOfListPersonDocuments.SearchCriteria = searchParameters.SearchCriteria;

            return(PartialView(pageOfListPersonDocuments));
        }
Esempio n. 11
0
        public PageOfList <Person> SearchPersons(int pageNumber, PersonSearchColumn personSearchColumn, SortDirection sortDirection, int numRecordsInPage, Dictionary <PersonSearchColumn, string> searchCriteria)
        {
            // Search for persons using the SQL repository
            // Determine the starting row
            int startRow;
            int totalItemCount = 0;

            if (numRecordsInPage == -1)
            {
                startRow = 0;
            }
            else
            {
                startRow = (pageNumber - 1) * numRecordsInPage;
            }

            PageOfList <Person> searchResults = null;

            using (var unitOfWork = unitOfWorkFactory.CreateUnitOfWork())
            {
                IQueryable <Person> personsQueryable = unitOfWork.Persons.GetQueryable();

                foreach (KeyValuePair <PersonSearchColumn, string> entry in searchCriteria)
                {
                    if (entry.Key == PersonSearchColumn.PersonID)
                    {
                        var personID = Int32.Parse(entry.Value);
                        personsQueryable = personsQueryable.Where(p => p.PersonID == personID);
                    }

                    if (entry.Key == PersonSearchColumn.FirstName)
                    {
                        personsQueryable = personsQueryable.Where(p => p.FirstName.StartsWith(entry.Value));
                    }

                    if (entry.Key == PersonSearchColumn.LastName)
                    {
                        personsQueryable = personsQueryable.Where(p => p.LastName.StartsWith(entry.Value));
                    }

                    if (entry.Key == PersonSearchColumn.EmailAddress)
                    {
                        personsQueryable = personsQueryable.Where(p => p.EmailAddress.StartsWith(entry.Value));
                    }

                    if (entry.Key == PersonSearchColumn.Phone)
                    {
                        personsQueryable = personsQueryable.Where(p => p.Phones.Any(h => h.PhoneTypeID == 1 && h.Number.StartsWith(entry.Value)));
                    }

                    if (entry.Key == PersonSearchColumn.City)
                    {
                        personsQueryable = personsQueryable.Where(p => p.Addresses.Any(pa => pa.AddressTypeID == 1 && pa.Address.City.StartsWith(entry.Value)));
                    }

                    if (entry.Key == PersonSearchColumn.State)
                    {
                        personsQueryable = personsQueryable.Where(p => p.Addresses.Any(pa => pa.AddressTypeID == 1 && pa.Address.State.StartsWith(entry.Value)));
                    }

                    if (entry.Key == PersonSearchColumn.StreetAddress)
                    {
                        personsQueryable = personsQueryable.Where(p => p.Addresses.Any(pa => pa.AddressTypeID == 1 && pa.Address.StreetAddress.StartsWith(entry.Value)));
                    }

                    if (entry.Key == PersonSearchColumn.Zip)
                    {
                        personsQueryable = personsQueryable.Where(p => p.Addresses.Any(pa => pa.AddressTypeID == 1 && pa.Address.Zip.StartsWith(entry.Value)));
                    }
                }

                // Include the related phones and addresses in the search query
                personsQueryable = personsQueryable.Include("Addresses.Address").Include("Phones");

                IOrderedQueryable <Person> personOrderedQueryable = null;

                // Apply the sorting using the requested sort column and direction
                if (sortDirection == SortDirection.Ascending)
                {
                    if (personSearchColumn == PersonSearchColumn.PersonID)
                    {
                        personOrderedQueryable = personsQueryable.OrderBy(p => p.PersonID);
                    }
                    else if (personSearchColumn == PersonSearchColumn.FirstName)
                    {
                        personOrderedQueryable = personsQueryable.OrderBy(p => p.FirstName);
                    }
                    else if (personSearchColumn == PersonSearchColumn.LastName)
                    {
                        personOrderedQueryable = personsQueryable.OrderBy(p => p.LastName);
                    }
                    else if (personSearchColumn == PersonSearchColumn.EmailAddress)
                    {
                        personOrderedQueryable = personsQueryable.OrderBy(p => p.EmailAddress);
                    }
                    else if (personSearchColumn == PersonSearchColumn.Phone)
                    {
                        personOrderedQueryable = personsQueryable.OrderBy(p => p.Phones.FirstOrDefault().Number);
                    }
                    else if (personSearchColumn == PersonSearchColumn.City)
                    {
                        personOrderedQueryable = personsQueryable.OrderBy(p => p.Addresses.FirstOrDefault().Address.City);
                    }
                    else if (personSearchColumn == PersonSearchColumn.State)
                    {
                        personOrderedQueryable = personsQueryable.OrderBy(p => p.Addresses.FirstOrDefault().Address.State);
                    }
                    else if (personSearchColumn == PersonSearchColumn.StreetAddress)
                    {
                        personOrderedQueryable = personsQueryable.OrderBy(p => p.Addresses.FirstOrDefault().Address.StreetAddress);
                    }
                    else if (personSearchColumn == PersonSearchColumn.Zip)
                    {
                        personOrderedQueryable = personsQueryable.OrderBy(p => p.Addresses.FirstOrDefault().Address.Zip);
                    }
                }
                else
                {
                    if (personSearchColumn == PersonSearchColumn.PersonID)
                    {
                        personOrderedQueryable = personsQueryable.OrderByDescending(p => p.PersonID);
                    }
                    else if (personSearchColumn == PersonSearchColumn.FirstName)
                    {
                        personOrderedQueryable = personsQueryable.OrderByDescending(p => p.FirstName);
                    }
                    else if (personSearchColumn == PersonSearchColumn.LastName)
                    {
                        personOrderedQueryable = personsQueryable.OrderByDescending(p => p.LastName);
                    }
                    else if (personSearchColumn == PersonSearchColumn.EmailAddress)
                    {
                        personOrderedQueryable = personsQueryable.OrderByDescending(p => p.EmailAddress);
                    }
                    else if (personSearchColumn == PersonSearchColumn.Phone)
                    {
                        personOrderedQueryable = personsQueryable.OrderByDescending(p => p.Phones.FirstOrDefault().Number);
                    }
                    else if (personSearchColumn == PersonSearchColumn.City)
                    {
                        personOrderedQueryable = personsQueryable.OrderByDescending(p => p.Addresses.FirstOrDefault().Address.City);
                    }
                    else if (personSearchColumn == PersonSearchColumn.State)
                    {
                        personOrderedQueryable = personsQueryable.OrderByDescending(p => p.Addresses.FirstOrDefault().Address.State);
                    }
                    else if (personSearchColumn == PersonSearchColumn.StreetAddress)
                    {
                        personOrderedQueryable = personsQueryable.OrderByDescending(p => p.Addresses.FirstOrDefault().Address.StreetAddress);
                    }
                    else if (personSearchColumn == PersonSearchColumn.Zip)
                    {
                        personOrderedQueryable = personsQueryable.OrderByDescending(p => p.Addresses.FirstOrDefault().Address.Zip);
                    }
                }

                // Get the number of records
                int recordCount = personOrderedQueryable.Count();

                // Apply the paging and make the SQL call
                List <Person> persons;
                if (numRecordsInPage != -1)
                {
                    persons = personOrderedQueryable.Skip(startRow)
                              .Take(numRecordsInPage)
                              .ToList();
                }
                else
                {
                    persons = personOrderedQueryable.ToList();
                }

                searchResults = new PageOfList <Person>(persons, pageNumber, numRecordsInPage, recordCount);
            }

            return(searchResults);
        }
Esempio n. 12
0
        public PageOfList <PersonDocument> SearchPersonDocuments(int pageNumber, PersonSearchColumn personSearchColumn, SortDirection sortDirection, int numRecordsInPage, Dictionary <PersonSearchColumn, string> searchCriteria)
        {
            // Search for persons using the Document DB repository
            // Determine the starting row
            int startRow;
            int totalItemCount = 0;

            if (numRecordsInPage == -1)
            {
                startRow = 0;
            }
            else
            {
                startRow = (pageNumber - 1) * numRecordsInPage;
            }

            PageOfList <PersonDocument> searchResults = null;

            var unitOfWork = new FootlooseFSDocUnitOfWork();

            IQueryable <PersonDocument> personsQueryable = unitOfWork.Persons.GetQueryable();

            foreach (KeyValuePair <PersonSearchColumn, string> entry in searchCriteria)
            {
                if (entry.Key == PersonSearchColumn.PersonID)
                {
                    var personID = Int32.Parse(entry.Value);
                    personsQueryable = personsQueryable.Where(p => p.PersonID == personID);
                }

                var searchValue = entry.Value.ToLower();

                if (entry.Key == PersonSearchColumn.FirstName)
                {
                    personsQueryable = personsQueryable.Where(p => p.FirstName.ToLower().StartsWith(searchValue));
                }

                if (entry.Key == PersonSearchColumn.LastName)
                {
                    personsQueryable = personsQueryable.Where(p => p.LastName.ToLower().StartsWith(searchValue));
                }

                if (entry.Key == PersonSearchColumn.EmailAddress)
                {
                    personsQueryable = personsQueryable.Where(p => p.EmailAddress.ToLower().StartsWith(searchValue));
                }

                if (entry.Key == PersonSearchColumn.Phone)
                {
                    personsQueryable = personsQueryable.Where(p => p.PhoneNumber.ToLower().StartsWith(searchValue));
                }

                if (entry.Key == PersonSearchColumn.City)
                {
                    personsQueryable = personsQueryable.Where(p => p.City.ToLower().StartsWith(searchValue));
                }

                if (entry.Key == PersonSearchColumn.State)
                {
                    personsQueryable = personsQueryable.Where(p => p.State.ToLower().StartsWith(searchValue));
                }

                if (entry.Key == PersonSearchColumn.StreetAddress)
                {
                    personsQueryable = personsQueryable.Where(p => p.StreetAddress.ToLower().StartsWith(searchValue));
                }

                if (entry.Key == PersonSearchColumn.Zip)
                {
                    personsQueryable = personsQueryable.Where(p => p.Zip.ToLower().StartsWith(searchValue));
                }
            }

            IOrderedQueryable <PersonDocument> personOrderedQueryable = null;

            // Apply the sorting using the requested sort column and direction
            if (sortDirection == SortDirection.Ascending)
            {
                if (personSearchColumn == PersonSearchColumn.PersonID)
                {
                    personOrderedQueryable = personsQueryable.OrderBy(p => p.PersonID);
                }
                else if (personSearchColumn == PersonSearchColumn.FirstName)
                {
                    personOrderedQueryable = personsQueryable.OrderBy(p => p.FirstName);
                }
                else if (personSearchColumn == PersonSearchColumn.LastName)
                {
                    personOrderedQueryable = personsQueryable.OrderBy(p => p.LastName);
                }
                else if (personSearchColumn == PersonSearchColumn.EmailAddress)
                {
                    personOrderedQueryable = personsQueryable.OrderBy(p => p.EmailAddress);
                }
                else if (personSearchColumn == PersonSearchColumn.Phone)
                {
                    personOrderedQueryable = personsQueryable.OrderBy(p => p.PhoneNumber);
                }
                else if (personSearchColumn == PersonSearchColumn.City)
                {
                    personOrderedQueryable = personsQueryable.OrderBy(p => p.City);
                }
                else if (personSearchColumn == PersonSearchColumn.State)
                {
                    personOrderedQueryable = personsQueryable.OrderBy(p => p.State);
                }
                else if (personSearchColumn == PersonSearchColumn.StreetAddress)
                {
                    personOrderedQueryable = personsQueryable.OrderBy(p => p.StreetAddress);
                }
                else if (personSearchColumn == PersonSearchColumn.Zip)
                {
                    personOrderedQueryable = personsQueryable.OrderBy(p => p.Zip);
                }
            }
            else
            {
                if (personSearchColumn == PersonSearchColumn.PersonID)
                {
                    personOrderedQueryable = personsQueryable.OrderByDescending(p => p.PersonID);
                }
                else if (personSearchColumn == PersonSearchColumn.FirstName)
                {
                    personOrderedQueryable = personsQueryable.OrderByDescending(p => p.FirstName);
                }
                else if (personSearchColumn == PersonSearchColumn.LastName)
                {
                    personOrderedQueryable = personsQueryable.OrderByDescending(p => p.LastName);
                }
                else if (personSearchColumn == PersonSearchColumn.EmailAddress)
                {
                    personOrderedQueryable = personsQueryable.OrderByDescending(p => p.EmailAddress);
                }
                else if (personSearchColumn == PersonSearchColumn.Phone)
                {
                    personOrderedQueryable = personsQueryable.OrderByDescending(p => p.PhoneNumber);
                }
                else if (personSearchColumn == PersonSearchColumn.City)
                {
                    personOrderedQueryable = personsQueryable.OrderByDescending(p => p.City);
                }
                else if (personSearchColumn == PersonSearchColumn.State)
                {
                    personOrderedQueryable = personsQueryable.OrderByDescending(p => p.State);
                }
                else if (personSearchColumn == PersonSearchColumn.StreetAddress)
                {
                    personOrderedQueryable = personsQueryable.OrderByDescending(p => p.StreetAddress);
                }
                else if (personSearchColumn == PersonSearchColumn.Zip)
                {
                    personOrderedQueryable = personsQueryable.OrderByDescending(p => p.Zip);
                }
            }

            // Get the number of records
            int recordCount = personOrderedQueryable.Count();

            // Apply the paging
            List <PersonDocument> persons;

            if (numRecordsInPage != -1)
            {
                persons = personOrderedQueryable.Skip(startRow)
                          .Take(numRecordsInPage)
                          .ToList();
            }
            else
            {
                persons = personOrderedQueryable.ToList();
            }

            return(new PageOfList <PersonDocument>(persons, pageNumber, numRecordsInPage, recordCount));
        }