示例#1
0
        public IReadOnlyCollection <PhoneBookEntry> Search(string searchText)
        {
            var existingEntries = phoneBookRepository.GetAll().ToList();

            var phoneBook = new PhoneBook(existingEntries);

            return(phoneBook.SearchEntries(searchText));
        }
示例#2
0
        private static void PrintPhoneBook(IPhoneBookRepository phoneBook)
        {
            var lstPhoneBook = phoneBook.GetAll();

            Console.WriteLine("List Phone Book");

            foreach (Person person in lstPhoneBook)
            {
                Console.WriteLine(String.Format("Name: {0} Phone: {1}, Address: {2}", person.FirstName + " " + person.LastName, person.PhoneNumber, person.Address));
            }
        }
        public async Task <PagedResult <PhoneBookViewModel> > HandleAsync(BrowsePhoneBooks query)
        {
            var result = _repository.GetAll();

            if (!string.IsNullOrEmpty(query.SearchText))
            {
                result = result.Where(s => s.Name.Contains(query.SearchText) || s.Phone.Contains(query.SearchText));
            }

            var models = _mapper.ProjectTo <PhoneBookViewModel>(result);

            return(new PagedResult <PhoneBookViewModel> {
                Data = models, Total = models.Count()
            });
        }
        public IEnumerable <PhoneBookForReturnDTO> GetAllOrderedBy(bool orderByFirstName, bool asc)
        {
            var user = _phoneBookRepository.GetAll();

            IEnumerable <PhoneBookForReturnDTO> result = null;

            var users = (from u in user
                         select new PhoneBookForReturnDTO
            {
                Id = u.Id,
                Firstname = u.Name,
                Lastname = u.LastName,
                NumberInfo = u.Numbers.Select(n => new NumberToReturnDTO
                {
                    Id = n.Id,
                    Number = n?.UserNumber ?? string.Empty,
                    Type = n?.Type?.TypeNumber ?? string.Empty
                }).ToList()
            }
                         ).ToList();

            if (!asc)
            {
                if (!orderByFirstName)
                {
                    result = users.OrderByDescending(x => x.Lastname);
                }
                else
                {
                    result = users.OrderByDescending(x => x.Firstname);
                }
            }
            else
            {
                if (!orderByFirstName)
                {
                    result = users.OrderBy(x => x.Lastname);
                }
                else
                {
                    result = users.OrderBy(x => x.Firstname);
                }
            }

            return(result);
        }
示例#5
0
        public IEnumerable <PhoneBookOutDTO> GetAllOrderedBy(bool orderByFirstName, bool asc)
        {
            var user = _phoneBookRepository.GetAll();

            IEnumerable <PhoneBookOutDTO> result = null;

            var users = user.Select(x => new PhoneBookOutDTO
            {
                Id         = x.Id,
                Firstname  = x.FirstName,
                Lastname   = x.LastName,
                NumberInfo = x.UserTypes.Select(y => new NumberInfoOutDTO
                {
                    Id     = y.Id,
                    Number = y?.Number ?? string.Empty,
                    Type   = y?.Type?.Name ?? string.Empty
                }).ToList()
            }).ToList();


            if (!asc)
            {
                if (!orderByFirstName)
                {
                    result = users.OrderByDescending(x => x.Lastname);
                }
                else
                {
                    result = users.OrderByDescending(x => x.Firstname);
                }
            }
            else
            {
                if (!orderByFirstName)
                {
                    result = users.OrderBy(x => x.Lastname);
                }
                else
                {
                    result = users.OrderBy(x => x.Firstname);
                }
            }

            return(result);
        }
示例#6
0
 public IOrderedQueryable <PhoneBook> GetAll() => _phoneBookRepository.GetAll();
示例#7
0
 public IEnumerable <Domain.Models.PhoneBook> GetAll()
 {
     return(_phoneBookRepository.GetAll().Include(record => record.Entries));
 }