Esempio n. 1
0
        /*Returns a person or a list ordered by firstName , for the sever side search */
        public IList <PersonDto> GetPersons(PersonSearch search)
        {
            List <PersonDto> personDtoList = new List <PersonDto>();

            var personList   = _context.Persons.ToList();
            var ageGroupList = _context.AgeGroups.ToList();

            personDtoList = CommonServices.GetPersonsDto(personList, ageGroupList);

            var personSeachList = personDtoList.Where(p => (string.IsNullOrEmpty(search.FirstName) ? true : p.FirstName.ToLower().Contains(search.FirstName.ToLower())) &&
                                                      (string.IsNullOrEmpty(search.LastName) ? true : p.LastName.ToLower().Contains(search.LastName.ToLower())))
                                  .OrderBy(p => p.FirstName).ToList();

            return(personSeachList);
        }
Esempio n. 2
0
        /*Returns a single person for a given id */
        public PersonDto GetPerson(int Id)
        {
            if (Id < 1)
            {
                PersonDto personDtoObjNull = new PersonDto()
                {
                    Id = 0, FirstName = "", LastName = "", Age = 0, AgeGroup = ""
                };
                return(personDtoObjNull);
            }
            var personObj    = _context.Persons.Where(c => c.Id == Id).FirstOrDefault();
            var ageGroupList = _context.AgeGroups.ToList();

            PersonDto personDtoObj = new PersonDto()
            {
                Id        = personObj.Id,
                FirstName = personObj.FirstName,
                LastName  = personObj.LastName,
                Age       = personObj.Age,
                AgeGroup  = CommonServices.AgeGroupDescription(personObj.Age, ageGroupList)
            };

            return(personDtoObj);
        }