コード例 #1
0
        private async void FindAndLoadContact(string givenName, string familyName)
        {
            ContactQueryOptions options = new ContactQueryOptions();

            options.OrderBy = ContactQueryResultOrdering.GivenNameFamilyName;
            options.DesiredFields.Clear();
            options.DesiredFields.Add(KnownContactProperties.GivenName);
            options.DesiredFields.Add(KnownContactProperties.FamilyName);
            options.DesiredFields.Add(KnownContactProperties.Email);
            options.DesiredFields.Add(KnownContactProperties.Telephone);

            ContactQueryResult            query    = store.CreateContactQuery(options);
            IReadOnlyList <StoredContact> contacts = await query.GetContactsAsync();

            contact = contacts.First(item =>
                                     item.GivenName == givenName && item.FamilyName == familyName);

            IDictionary <string, object> props = await contact.GetPropertiesAsync();

            firstNameInput.Text = contact.GivenName;
            lastNameInput.Text  = contact.FamilyName;
            if (props.ContainsKey(KnownContactProperties.Email))
            {
                emailInput.Text = (string)props[KnownContactProperties.Email];
            }
            if (props.ContainsKey(KnownContactProperties.Telephone))
            {
                phoneInput.Text = (string)props[KnownContactProperties.Telephone];
            }
        }
コード例 #2
0
ファイル: Contacts.cs プロジェクト: tecinfoj/contatos
        /// <summary>
        /// Retrieve list of contacts from the store
        /// </summary>
        /// <param name="parameters"></param>
        async public void GetContactsFromStore(string parameters)
        {
            store = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);

            ContactQueryOptions options = new ContactQueryOptions();

            options.DesiredFields.Add(KnownContactProperties.Email);
            options.DesiredFields.Add(KnownContactProperties.Address);
            options.DesiredFields.Add(KnownContactProperties.Telephone);

            ContactQueryResult result = store.CreateContactQuery(options);

            IReadOnlyList <StoredContact> contacts = await result.GetContactsAsync();

            string jsContacts = "AppMobi.people = [";

            foreach (StoredContact con in contacts)
            {
                IDictionary <string, object> temps = await con.GetPropertiesAsync();

                string displayName = "";
                Windows.Phone.PersonalInformation.ContactAddress address;
                string familyName = "";
                string givenName  = "";
                string email      = "";
                string telephone  = "";

                if (temps.ContainsKey("DisplayName"))
                {
                    displayName = (string)temps["DisplayName"];
                }

                if (temps.ContainsKey("Address"))
                {
                    address = (Windows.Phone.PersonalInformation.ContactAddress)temps["Address"];
                }

                if (temps.ContainsKey("FamilyName"))
                {
                    familyName = (string)temps["FamilyName"];
                }

                if (temps.ContainsKey("GivenName"))
                {
                    givenName = (string)temps["GivenName"];
                }

                if (temps.ContainsKey("Email"))
                {
                    email = (string)temps["Email"];
                }

                if (temps.ContainsKey("Telephone"))
                {
                    telephone = (string)temps["Telephone"];
                }
            }

            jsContacts += "];";
        }
コード例 #3
0
        public async Task <IActionResult> Index(string filters = null)
        {
            var scope = AuthenticationService.GetScope(User);

            var queryOptions = new ContactQueryOptions(scope, filters);
            var pagedItems   = await ContactService.GetContacts(queryOptions);

            return(Ok(pagedItems));
        }
コード例 #4
0
        public async Task <IActionResult> FindAllAsync([FromQuery] ContactQueryOptions options)
        {
            if (options == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }

            var contacts = await _contactManager.FindAllAsync(options);

            return(this.OkList(contacts, options.Offset, options.Limit));
        }
コード例 #5
0
 private async void btnSearchContacts_Tapped(object sender, TappedRoutedEventArgs e)
 {
     var qs = txtSearch.Text;
     var store = await GetContactStore();
     if (!String.IsNullOrWhiteSpace(qs))
     {
         var cqo = new ContactQueryOptions(qs, ContactQuerySearchFields.All);
         var reader = store.GetContactReader(cqo);
         await ShowContacts(reader);
     }
 }
コード例 #6
0
 /// <summary>
 /// Search for contacts
 /// </summary>
 /// <param name="text"></param>
 /// <returns></returns>
 internal async Task SearchForTextAsync(string text)
 {
     if (!String.IsNullOrWhiteSpace(text))
     {
         ContactQueryOptions option = new ContactQueryOptions(text, ContactQuerySearchFields.All);
         ContactReader       reader = store.GetContactReader(option);
         await DisplayContactsFromReaderAsync(reader);
     }
     // A null query string is beeing treated as query for "*"
     else
     {
         ContactReader reader = store.GetContactReader();
         await DisplayContactsFromReaderAsync(reader);
     }
 }
コード例 #7
0
        /// <summary>
        /// Retrieves a collection of contacts with the given filter parameters as an asynchronous operation.
        /// </summary>
        /// <param name="options">The query options to use for searching contacts.</param>
        /// <param name="cancellationToken">The <see cref="T:System.Threading.CancellationToken" /> used to propagate notifications that the operation should be canceled.</param>
        /// <returns>
        /// A <see cref="T:System.Threading.Tasks.Task`1" /> that contains the contacts according to the specified filter parameters.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">options</exception>
        public virtual async Task <IReadOnlyList <ContactItem> > FindAllAsync(ContactQueryOptions options, CancellationToken cancellationToken)
        {
            ThrowIfDisposed();
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(await Contacts
                   .AsNoTracking()
                   .Where(options.Text)
                   .OrderBy(options.OrderBy)
                   .Skip(options.Offset)
                   .Take(options.Limit)
                   .Select(options.Fields)
                   .ToArrayAsync(cancellationToken));
        }
コード例 #8
0
        public async Task Index()
        {
            var contact = new Contact()
            {
                Id            = Guid.NewGuid(),
                ContactTypeId = Guid.NewGuid(),
                ClientId      = Guid.NewGuid(),
                Value         = "*****@*****.**"
            };

            var pagedItems = new PagedItems <Contact>()
            {
                TotalItems = 1,
                Items      = new List <Contact>()
                {
                    contact
                }
            };

            var service     = new Mock <IContactService>();
            var authService = TestHelper.MockAuthenticationService(Scope.Branch);

            ContactQueryOptions queryOptions = null;

            service.Setup(c => c.GetContacts(It.IsAny <ContactQueryOptions>()))
            .Callback((ContactQueryOptions options) => queryOptions = options)
            .ReturnsAsync(pagedItems);

            var controller = new ContactsController(service.Object, authService.Object);

            var result = await controller.Index($"clientId={contact.ClientId}");

            Assert.Equal(Scope.Branch, queryOptions.Scope.Scope);
            Assert.Equal("Value", queryOptions.SortOptions.Column);
            Assert.Equal(SortDirection.Ascending, queryOptions.SortOptions.Direction);
            Assert.Equal(0, queryOptions.PageOptions.Size);
            Assert.Equal(0, queryOptions.PageOptions.Number);

            Assert.Equal(contact.ClientId, queryOptions.ClientId);

            var okResult    = Assert.IsType <OkObjectResult>(result);
            var returnValue = Assert.IsType <PagedItems <Contact> >(okResult.Value);

            Assert.Same(pagedItems, returnValue);
        }
コード例 #9
0
        private async Task SearchForTextAsync(string ContactFilter)
        {
            if (store == null)
            {
                await LoadContactsFromStoreAsync();

                return;
            }
            if (!string.IsNullOrWhiteSpace(ContactFilter))
            {
                ContactQueryOptions option = new ContactQueryOptions(ContactFilter, ContactQuerySearchFields.All);
                ContactReader       reader = store.GetContactReader(option);
                await DisplayContactsFromReaderAsync(reader, false);
            }
            else
            {
                ContactReader reader = store.GetContactReader();
                await DisplayContactsFromReaderAsync(reader, true);
            }
            return;
        }
コード例 #10
0
ファイル: ContactsViewModel.cs プロジェクト: ice0/test
        /// <summary>
        /// Processes contact search.
        /// </summary>
        /// <param name="ContactFilter">Takes in the string inputed by the user</param>
        private async Task SearchForTextAsync(string ContactFilter)
        {
            if (store == null)
            {
                //Shouldn't happen, and I don't want to deal with opening the store in multiple locations
                await LoadContactsFromStoreAsync();

                return;
            }
            //A null query string is being treated as a query for "*"
            if (!string.IsNullOrWhiteSpace(ContactFilter))
            {
                ContactQueryOptions option = new ContactQueryOptions(ContactFilter, ContactQuerySearchFields.All);
                ContactReader       reader = store.GetContactReader(option);
                await DisplayContactsFromReaderAsync(reader, false);
            }
            else
            {
                ContactReader reader = store.GetContactReader();
                await DisplayContactsFromReaderAsync(reader, true);
            }
            return;
        }
コード例 #11
0
        public async Task <PagedItems <Contact> > GetContacts(ContactQueryOptions queryOptions)
        {
            var query = GetContactQuery(queryOptions.Scope);

            //Apply filters ----------------------------------------------------------------------------------------
            if (queryOptions.ClientId.HasValue)
            {
                query = query.Where(b => b.ClientId == queryOptions.ClientId);
            }
            //------------------------------------------------------------------------------------------------------

            var pagedItems = new PagedItems <Contact>();

            //Get total items
            pagedItems.TotalItems = await query.CountAsync();

            //Ordering
            query = query.OrderBy(queryOptions.SortOptions.Column, queryOptions.SortOptions.Direction);

            //Paging
            pagedItems.Items = await query.TakePage(queryOptions.PageOptions.Number, queryOptions.PageOptions.Size).ToListAsync();

            return(pagedItems);
        }
コード例 #12
0
 /// <summary>
 /// Processes contact search.
 /// </summary>
 /// <param name="ContactFilter">Takes in the string inputed by the user</param>
 private async Task SearchForTextAsync(string ContactFilter)
 {
     if (store == null)
     {
         //Shouldn't happen, and I don't want to deal with opening the store in multiple locations
         await LoadContactsFromStoreAsync();
         return;
     }
     //A null query string is being treated as a query for "*"
     if (!string.IsNullOrWhiteSpace(ContactFilter))
     {
         ContactQueryOptions option = new ContactQueryOptions(ContactFilter, ContactQuerySearchFields.All);
         ContactReader reader = store.GetContactReader(option);
         await DisplayContactsFromReaderAsync(reader, false);
     }
     else
     {
         ContactReader reader = store.GetContactReader();
         await DisplayContactsFromReaderAsync(reader, true);
     }
     return;
 }
コード例 #13
0
        public async Task GetContacts_FilterAndSort()
        {
            var options = TestHelper.GetDbContext("GetContacts_FilterAndSort");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);
            var client2 = TestHelper.InsertClient(options, user1.Organisation);

            var user2 = TestHelper.InsertUserDetailed(options);

            //Given
            var contactTypeId1 = Guid.NewGuid();
            var contact1       = new ContactEntity {
                Id = Guid.NewGuid(), ClientId = client1.Client.Id, Value = "A Contact 1", ContactTypeId = contactTypeId1
            };
            var contact2 = new ContactEntity {
                Id = Guid.NewGuid(), ClientId = client2.Client.Id, Value = "B Contact 2", ContactTypeId = contactTypeId1
            };
            var contact3 = new ContactEntity {
                Id = Guid.NewGuid(), ClientId = client1.Client.Id, Value = "C Contact 3", ContactTypeId = contactTypeId1
            };
            var contact4 = new ContactEntity {
                Id = Guid.NewGuid(), ClientId = client2.Client.Id, Value = "D Contact 4", ContactTypeId = contactTypeId1
            };
            var contact5 = new ContactEntity {
                Id = Guid.NewGuid(), ClientId = client1.Client.Id, Value = "E Contact 5", ContactTypeId = contactTypeId1
            };
            var contact6 = new ContactEntity {
                Id = Guid.NewGuid(), ClientId = client1.Client.Id, Value = "F Contact 6", ContactTypeId = contactTypeId1
            };

            using (var context = new DataContext(options))
            {
                //Jumbled order
                context.Contact.Add(contact6);
                context.Contact.Add(contact1);
                context.Contact.Add(contact2);
                context.Contact.Add(contact4);
                context.Contact.Add(contact5);
                context.Contact.Add(contact3);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService = new AuditServiceMock();
                var service      = new ContactService(context, auditService);

                //When
                var scope        = TestHelper.GetScopeOptions(user1);
                var queryOptions = new ContactQueryOptions(scope, $"clientId={client1.Client.Id.ToString()}");
                var actual       = await service.GetContacts(queryOptions);

                //Then
                Assert.Equal(4, actual.TotalItems);

                var contacts = actual.Items.ToArray();

                Assert.Equal(4, contacts.Count());

                var actual1 = contacts[0];
                Assert.Equal(contact1.Id, actual1.Id);
                Assert.Equal(contact1.Value, actual1.Value);
                Assert.Equal(contact1.ClientId, actual1.ClientId);
                Assert.Equal(contact1.ContactTypeId, actual1.ContactTypeId);

                var actual2 = contacts[1];
                Assert.Equal(contact3.Id, actual2.Id);
                Assert.Equal(contact3.Value, actual2.Value);

                var actual6 = contacts[3];
                Assert.Equal(contact6.Id, actual6.Id);
                Assert.Equal(contact6.Value, actual6.Value);

                //Scope check
                scope        = TestHelper.GetScopeOptions(user2);
                queryOptions = new ContactQueryOptions(scope, $"clientId={client1.Client.Id.ToString()}");
                actual       = await service.GetContacts(queryOptions);

                //Then
                Assert.Equal(0, actual.TotalItems);
            }
        }