Exemplo n.º 1
0
        public async Task <IActionResult> GetContacts([FromQuery] RequstModels.PagingFilter pagingFilter)
        {
            try
            {
                var pagedCagegoryList = await _contactRepository.GetContacts(pagingFilter);

                var vContacts = new List <ViewModels.Contact>();
                foreach (var sContact in pagedCagegoryList)
                {
                    vContacts.Add(new ViewModels.Contact
                    {
                        Id             = sContact.Id.ToString(),
                        Name           = sContact.Name,
                        Email          = sContact.Email,
                        Address        = sContact.Address,
                        Mobile         = sContact.Mobile,
                        ProfilePicture = sContact.ProfilePicture,
                        Category       = sContact.Category.Title,
                        CategoryId     = sContact.Category.Id.ToString()
                    });
                }

                return(Ok(new
                {
                    Pagination = new ViewModels.Pagination(pagedCagegoryList.PageIndex, pagedCagegoryList.PageSize, pagedCagegoryList.TotalCount, pagedCagegoryList.TotalPages),
                    Contacts = vContacts
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Exemplo n.º 2
0
        public async Task <PagedList <Contact> > GetContacts(RequestModels.PagingFilter pagingFilter)
        {
            var contacts = _dbContext.Contacts.Include(c => c.Category).OrderBy(c => c.Name);

            return(await PagedList <Contact> .CreateAsync(contacts, pagingFilter.PageIndex, pagingFilter.PageSize));
        }