public PageOfList<PersonDocument> SearchPersonDocuments(int pageNumber, int numRecordsInPage, string sort, SortDirection sortDirection, PersonDocument searchCriteria)
        {
            // Note the Document Unit of Work will be disposed when out of scope (does not require using statement)
            var unitOfWork = new FootlooseFSDocUnitOfWork();

            // Search, sort, and page the results
            return unitOfWork.Persons.Search(pageNumber, numRecordsInPage, searchCriteria, sort, sortDirection);
        }
        public PageOfPersonDocuments SearchPersons(int pageNumber, int numRecordsInPage, string sort, SortDirection sortDirection, PersonDocument searchCriteria)
        {
            var pageOfListPerson = footlooseService.SearchPersonDocuments(pageNumber, numRecordsInPage, sort, sortDirection, searchCriteria);

            var pageOfPersons = new PageOfPersonDocuments();
            pageOfPersons.Data = pageOfListPerson.Data;
            pageOfPersons.PageIndex = pageOfListPerson.PageIndex;
            pageOfPersons.PageSize = pageOfListPerson.PageSize;
            pageOfPersons.TotalItemCount = pageOfListPerson.TotalItemCount;

            return pageOfPersons;
        }
        public void TestPersonDocumentSearch()
        {
            var uowFactory = new FootlooseFSSqlUnitOfWorkFactory();
            var notificationService = new FootlooseFSNotificationService();
            var service = new FootlooseFSService(uowFactory, notificationService);

            var searchCriteria = new PersonDocument();
            searchCriteria.State = "NY";

            var pageOfListPersonDocuments = service.SearchPersonDocuments(1, 10, "LastName", SortDirection.Ascending, searchCriteria);

            // Verify that only 10 records or less are returned
            Assert.IsTrue(pageOfListPersonDocuments.Data.Count <= 10);

            // Verify that only NY state record are returned
            Assert.IsFalse(pageOfListPersonDocuments.Data.Any(p => p.State != "NY"));
        }
        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);            
        }
        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;
        }
        private string serializePersonToPersonDocumentJson(Person person)
        {
            var personDocument = new PersonDocument();

            personDocument.PersonID = person.PersonID;
            personDocument.EmailAddress = person.EmailAddress;
            personDocument.FirstName = person.FirstName;
            personDocument.LastName = person.LastName;
            personDocument.PhoneNumber = person.Phones.Any(p => p.PhoneTypeID == 1) ? person.Phones.First(p => p.PhoneTypeID == 1).Number : string.Empty;

            var address = person.Addresses.Any(a => a.AddressTypeID == 1) ? person.Addresses.First(a => a.AddressTypeID == 1).Address : null;
            if (address != null)
            {
                personDocument.StreetAddress = address.StreetAddress;
                personDocument.City = address.City;
                personDocument.State = address.State;
                personDocument.Zip = address.Zip;
            }

            return JsonConvert.SerializeObject(personDocument);
        }