Exemplo n.º 1
0
        //[ResponseCache(Duration = 0)]
        public IActionResult GetContactsList(
            [FromQuery] ContactsResourceParameters contactsResourceParameters)
        {
            if (!_propertyMappingService.ValidMappingExistsFor <ContactDto, Contact>
                    (contactsResourceParameters.OrderBy))
            {
                return(BadRequest());
            }

            if (!_propertyCheckerService.TypeHasProperties <Contact>
                    (contactsResourceParameters.Fields))
            {
                return(BadRequest());
            }

            var ContactsFromRepo = _contactRepo.GetContacts(contactsResourceParameters);

            var paginationMetaData = new
            {
                totalCount  = ContactsFromRepo.TotalCount,
                pageSize    = ContactsFromRepo.PageSize,
                currentPage = ContactsFromRepo.CurrentPage,
                totalPages  = ContactsFromRepo.TotalPages
            };

            Response.Headers.Add("X-Pagination",
                                 JsonSerializer.Serialize(paginationMetaData));

            var links = CreateLinksForContacts(contactsResourceParameters,
                                               ContactsFromRepo.HasNext, ContactsFromRepo.HasPrevious);

            var shapedContacts = ContactsFromRepo.ShapeDatas(contactsResourceParameters.Fields);

            var shapedContactsWithLinks = shapedContacts.Select(contact =>
            {
                var contactAsDictionary = contact as IDictionary <string, object>;
                //var contactLinks = CreateLinksForContact((int)contactAsDictionary["Id"], null);
                //contactAsDictionary.Add("links", contactLinks);
                return(contactAsDictionary);
            });

            var linkedCollectionResource = new
            {
                value = shapedContactsWithLinks,
                links
            };

            return(Ok(shapedContacts));
        }
Exemplo n.º 2
0
        private async void LoadDb()
        {
            SelectedContact = null;
            SelectedContact = new Contact();

            Contacts = await repository.GetContacts();

            if (Contacts.Count == 0)
            {
                GridContacts = false;
                NoContacts   = true;
            }
            else
            {
                GridContacts = true;
                NoContacts   = false;
            }
        }
Exemplo n.º 3
0
 public ActionResult <IEnumerable <Contact> > Get([FromServices] IContactRepo contactRepo)
 {
     return(contactRepo.GetContacts());
 }