Exemple #1
0
        public IActionResult GetAllContacts([FromQuery] ContactQueryParameters contactQueryParameters)
        {
            try
            {
                var contacts = _unitofwork.ContactRepository.GetAllContactsAsyc(contactQueryParameters);
                var metadata = new
                {
                    contacts.TotalCount,
                    contacts.PageSize,
                    contacts.CurrentPage,
                    contacts.TotalPages,
                    contacts.HasNext,
                    contacts.HasPrevious
                };

                var contactsResults = _mapper.Map <IEnumerable <ContactDto> >(contacts);

                Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));
                return(Ok(contactsResults));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, "Internal server error"));
            }
        }
Exemple #2
0
        public async Task <PagedList <Contact> > GetContacts(ContactQueryParameters contactQueryParameters)
        {
            var contacts = FindAll();

            if (!string.IsNullOrEmpty(contactQueryParameters.FirstName))
            {
                SearchByFirstName(ref contacts, contactQueryParameters.FirstName);
            }
            if (!string.IsNullOrEmpty(contactQueryParameters.LastName))
            {
                SearchByLastName(ref contacts, contactQueryParameters.LastName);
            }
            if (contactQueryParameters.PhoneNumber > 0)
            {
                SearchByNumber(ref contacts, contactQueryParameters.PhoneNumber);
            }

            return(PagedList <Contact> .ToPagedList(contacts,
                                                    contactQueryParameters.PageNumber,
                                                    contactQueryParameters.PageSize));
        }
        public async Task <IActionResult> Get([FromQuery] ContactQueryParameters contactQueryParameters)
        {
            var contacts = await _contactService.GetContacts(contactQueryParameters);


            var metadata = new
            {
                contacts.TotalCount,
                contacts.PageSize,
                contacts.CurrentPage,
                contacts.TotalPages,
                contacts.HasNext,
                contacts.HasPrevious
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));

            _logger.LogInformation($"Returned {contacts.TotalCount} contacts from database.");

            return(Ok(contacts));
        }
        public async Task <PagedList <Contact> > GetContacts(ContactQueryParameters contactQueryParameters)
        {
            var contact = await _repositoryWrapper.contact.GetContacts(contactQueryParameters);

            return(contact);
        }