public ActionResult List(ContactQuery query)
 {
     var list = this.ContactRepository.GetList(query);
     var data = list.Data.Select(c => ContactModel.From(c)).ToList();
     var result = new { total = list.RecordCount, rows = data};
     return Json(result);
 }
 public Contact GetById(Guid id)
 {
     using (var connection = context.CreateConnection())
     {
         return(connection.Query <Contact>(ContactQuery.ById(id)).SingleOrDefault());
     }
 }
 public IEnumerable <Contact> GetAll()
 {
     using (var connection = context.CreateConnection())
     {
         return(connection.Query <Contact>(ContactQuery.All()));
     }
 }
 public void Delete(Guid id)
 {
     using (var connection = context.CreateConnection())
     {
         connection.Execute(ContactQuery.Delete(id));
     }
 }
Exemple #5
0
        public ActionResult List(ContactQuery query)
        {
            var list   = this.ContactRepository.GetList(query);
            var data   = list.Data.Select(c => ContactModel.From(c)).ToList();
            var result = new { total = list.RecordCount, rows = data };

            return(Json(result));
        }
 public Contact Update(Contact сontact)
 {
     using (var connection = context.CreateConnection())
     {
         connection.Execute(ContactQuery.Update(сontact));
         return(сontact);
     }
 }
Exemple #7
0
        public async Task CanCreateContact()
        {
            /* Get Contact */
            var contactQuery = new ContactQuery
            {
                UserId = TestUserId
            };
            var queryResult = await contactRepository.QueryContact(contactQuery);

            var baseContact = queryResult.Items.FirstOrDefault();

            baseContact.Id     = null;
            baseContact.UserId = TestUserId + Guid.NewGuid().ToString("N").Substring(0, 4);

            /* Create Contact */
            SaveContact saveContactCmd = new SaveContact
            {
                Contact = baseContact
            };
            var saveResult = await contactRepository.ManageContact(saveContactCmd);

            var newContactId = saveResult.ContactId;

            /* Get New Contact */
            var newContactQuery = new ContactQuery
            {
                ContactId = newContactId
            };
            var newQueryResult = await contactRepository.QueryContact(newContactQuery);

            var newContact = newQueryResult.Items.FirstOrDefault();

            newContact.ShouldNotBeNull().Id.ShouldBe(newContactId);

            /* Delete New Contact */
            DeleteContact deleteCmd = new DeleteContact
            {
                ContactId = newContactId
            };
            var deleteResult = await contactRepository.ManageContact(deleteCmd);

            var deletedContactId = deleteResult.ContactId;

            /* Get Deleted Contact */
            var deletedCaseQuery = new ContactQuery
            {
                ContactId = deletedContactId
            };
            var deletedQueryResult = await contactRepository.QueryContact(deletedCaseQuery);

            var deletedContact = (Contact)deletedQueryResult.Items.LastOrDefault();

            deletedContact.ShouldBeNull();
        }
        public Contact Create(Contact сontact)
        {
            if (сontact.Id == Guid.Empty)
            {
                сontact.Id = Guid.NewGuid();
            }

            using (var connection = context.CreateConnection())
            {
                connection.Execute(ContactQuery.Insert(сontact));
                return(сontact);
            }
        }
        public void ItCreateAnCorrectQueryStringForContacts()
        {
            var query = new ContactQuery()
            {
                Page    = 2,
                PerPage = 45,
                Query   = "test"
            };

            var queryString = query.ToQueryString();

            Assert.Equal("?query=test&page=2&per_page=45", queryString);
        }
Exemple #10
0
        public async Task <IEnumerable <Task <int[]> > > FindContactsAsync(ContactQuery query)
        {
            var i = _counter++;

            Console.WriteLine($"[{_sw.Elapsed}] [{i}] FindContactsAsync invoking");

            try
            {
                return(await _searchServices.FindContactsAsync(query));
            }
            finally
            {
                Console.WriteLine($"[{_sw.Elapsed}] [{i}] FindContactsAsync invoked");
            }
        }
Exemple #11
0
        /// <summary>
        /// Test Find using the Query class
        /// </summary>
        private void Step_30_TestFindByQuery_Generated()
        {
            using (TransactionManager tm = CreateTransaction())
            {
                //Insert Mock Instance
                Contact mock   = CreateMockInstance(tm);
                bool    result = DataRepository.ContactProvider.Insert(tm, mock);

                Assert.IsTrue(result, "Could Not Test FindByQuery, Insert Failed");

                ContactQuery query = new ContactQuery();

                query.AppendEquals(ContactColumn.ContactId, mock.ContactId.ToString());
                query.AppendEquals(ContactColumn.NameStyle, mock.NameStyle.ToString());
                if (mock.Title != null)
                {
                    query.AppendEquals(ContactColumn.Title, mock.Title.ToString());
                }
                query.AppendEquals(ContactColumn.FirstName, mock.FirstName.ToString());
                if (mock.MiddleName != null)
                {
                    query.AppendEquals(ContactColumn.MiddleName, mock.MiddleName.ToString());
                }
                query.AppendEquals(ContactColumn.LastName, mock.LastName.ToString());
                if (mock.Suffix != null)
                {
                    query.AppendEquals(ContactColumn.Suffix, mock.Suffix.ToString());
                }
                if (mock.EmailAddress != null)
                {
                    query.AppendEquals(ContactColumn.EmailAddress, mock.EmailAddress.ToString());
                }
                query.AppendEquals(ContactColumn.EmailPromotion, mock.EmailPromotion.ToString());
                if (mock.Phone != null)
                {
                    query.AppendEquals(ContactColumn.Phone, mock.Phone.ToString());
                }
                query.AppendEquals(ContactColumn.PasswordHash, mock.PasswordHash.ToString());
                query.AppendEquals(ContactColumn.PasswordSalt, mock.PasswordSalt.ToString());
                query.AppendEquals(ContactColumn.Rowguid, mock.Rowguid.ToString());
                query.AppendEquals(ContactColumn.ModifiedDate, mock.ModifiedDate.ToString());

                TList <Contact> results = DataRepository.ContactProvider.Find(tm, query);

                Assert.IsTrue(results.Count == 1, "Find is not working correctly.  Failed to find the mock instance");
            }
        }
        public async Task CanGetContact()
        {
            var contactQuery = new ContactQuery
            {
                UserId = TestUserId
            };
            var queryResult = await contactRepository.QueryContact(contactQuery);

            queryResult.Items.ShouldNotBeEmpty();

            var contact = (Contact)queryResult.Items.First();

            contact.ShouldNotBeNull();

            contact.PrimaryAddress.Country.ShouldNotBeNull().ShouldNotBeNull();
            contact.PrimaryAddress.Country.ShouldNotBeNull();
        }
Exemple #13
0
        public async Task CanUpdateContact()
        {
            /* Get Contact */
            var contactQuery = new ContactQuery
            {
                UserId = TestUserId
            };
            var queryResult = await contactRepository.QueryContact(contactQuery);

            var contact = queryResult.Items.FirstOrDefault();

            var currentCity = contact.PrimaryAddress.Community;
            var newCity     = currentCity == "406adfaf-9f97-ea11-b813-005056830319"
                ? "226adfaf-9f97-ea11-b813-005056830319"
                : "406adfaf-9f97-ea11-b813-005056830319";

            contact.PrimaryAddress.Community = newCity;

            /* Update Contact */
            SaveContact saveContactCmd = new SaveContact
            {
                Contact = contact
            };
            var saveResult = await contactRepository.ManageContact(saveContactCmd);

            var updatedContactId = saveResult.ContactId;

            /* Get Updated Contact */
            var updatedContactQuery = new ContactQuery
            {
                ContactId = updatedContactId
            };
            var updatedQueryResult = await contactRepository.QueryContact(updatedContactQuery);

            var updatedContact = updatedQueryResult.Items.FirstOrDefault();

            updatedContact.PrimaryAddress.Community.ShouldBe(newCity);
        }
 public Task <IEnumerable <Task <int[]> > > FindContactsAsync(ContactQuery query)
 {
     return(GenerateRandomResponse());
 }
Exemple #15
0
        public async Task CanCreateContactWithAddressLookupValues()
        {
            var country  = "CAN";
            var province = "BC";
            var city     = "226adfaf-9f97-ea11-b813-005056830319";

            /* Get Contact */
            var contactQuery = new ContactQuery
            {
                UserId = TestUserId
            };
            var queryResult = await contactRepository.QueryContact(contactQuery);

            var baseContact = queryResult.Items.FirstOrDefault();

            baseContact.ShouldNotBeNull();

            baseContact.Id     = null;
            baseContact.UserId = TestUserId + Guid.NewGuid().ToString("N").Substring(0, 4);
            baseContact.PrimaryAddress.Country       = country;
            baseContact.PrimaryAddress.StateProvince = province;
            baseContact.PrimaryAddress.Community     = city;
            baseContact.MailingAddress.Country       = country;
            baseContact.MailingAddress.StateProvince = province;
            baseContact.MailingAddress.Community     = city;

            /* Create Contact */
            SaveContact saveContactCmd = new SaveContact
            {
                Contact = baseContact
            };
            var saveResult = await contactRepository.ManageContact(saveContactCmd);

            var newContactId = saveResult.ContactId;

            /* Get New Contact */
            var newContactQuery = new ContactQuery
            {
                ContactId = newContactId
            };
            var newQueryResult = await contactRepository.QueryContact(newContactQuery);

            var newContact = newQueryResult.Items.FirstOrDefault();

            newContact.ShouldNotBeNull().Id.ShouldBe(newContactId);

            newContact.PrimaryAddress.Country.ShouldBe(country);
            newContact.PrimaryAddress.StateProvince.ShouldBe(province);
            newContact.PrimaryAddress.Community.ShouldBe(city);

            newContact.MailingAddress.Country.ShouldBe(country);
            newContact.MailingAddress.StateProvince.ShouldBe(province);
            newContact.MailingAddress.Community.ShouldBe(city);

            /* Delete New Contact */
            DeleteContact deleteCmd = new DeleteContact
            {
                ContactId = newContactId
            };
            var deleteResult = await contactRepository.ManageContact(deleteCmd);

            var deletedContactId = deleteResult.ContactId;

            /* Get deleted contact */
            var deletedCaseQuery = new ContactQuery
            {
                ContactId = deletedContactId
            };
            var deletedQueryResult = await contactRepository.QueryContact(deletedCaseQuery);

            var deletedContact = (Contact)deletedQueryResult.Items.LastOrDefault();

            deletedContact.ShouldBeNull();
        }