public async Task ShouldFailToDeleteOneVendorContactDueToInvalidContactID() { ResetDatabase(); var contact = new ContactDomainObj { BusinessEntityID = 200, EmailAddress = "*****@*****.**", EmailPasswordHash = "8pJsGA+VNldlqxGoEloyXnMv3mSCpZXltUf11tCeVts=", EmailPasswordSalt = "d2tgUmM=", ContactTypeID = 17, ParentEntityID = 3, PersonType = "VC", IsEasternNameStyle = false, Title = "Ms.", FirstName = "Test", MiddleName = "T", LastName = "User", EmailPromotion = EmailPromoPreference.NoPromotions }; string jsonContact = JsonConvert.SerializeObject(contact); var response = await _client.DeleteAsJsonAsync($"{serviceAddress}{rootAddress}/contact", contact); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); }
public async Task ShouldUpdateOneVendorContactFromContactDomainObj() { ResetDatabase(); var contact = new ContactDomainObj { BusinessEntityID = 8, EmailAddress = "*****@*****.**", EmailPasswordHash = "8pJsGA+VNldlqxGoEloyXnMv3mSCpZXltUf11tCeVts=", EmailPasswordSalt = "d2tgUmM=", ContactTypeID = 17, ParentEntityID = 3, PersonType = "VC", IsEasternNameStyle = false, Title = "Ms.", FirstName = "Test", MiddleName = "T", LastName = "User", EmailPromotion = EmailPromoPreference.NoPromotions }; string jsonContact = JsonConvert.SerializeObject(contact); HttpContent content = new StringContent(jsonContact, Encoding.UTF8, "application/json"); var response = await _client.PutAsync($"{serviceAddress}{rootAddress}/contact", content); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); }
public static void Map(this Person.Person entityObj, ContactDomainObj domainObj) { entityObj.BusinessEntityID = domainObj.BusinessEntityID; entityObj.PersonType = domainObj.PersonType; entityObj.IsEasternNameStyle = domainObj.IsEasternNameStyle; entityObj.Title = domainObj.Title; entityObj.FirstName = domainObj.FirstName; entityObj.MiddleName = domainObj.MiddleName; entityObj.LastName = domainObj.LastName; entityObj.Suffix = domainObj.Suffix; entityObj.EmailPromotion = domainObj.EmailPromotion; entityObj.AdditionalContactInfo = domainObj.AdditionalContactInfo; entityObj.Demographics = domainObj.Demographics; }
public async Task ShouldRaiseExceptionContactDomainObjWithInvalidContactType() { var contact = new ContactDomainObj { PersonType = "VC", IsEasternNameStyle = false, Title = "Ms.", FirstName = "Jennifer", LastName = "Lopez", EmailPromotion = EmailPromoPreference.AdventureWorksAndPartners, EmailAddress = "*****@*****.**", EmailPasswordHash = "elZhadf87Lkl3cXx4oYxXdV31zWENyCgo3VUn5l5l/c=", EmailPasswordSalt = "K4sEsXg=", ContactTypeID = 171, ParentEntityID = 2 }; var exception = await Assert.ThrowsAsync <AdventureWorksInvalidContactTypeException>(() => _contactRepo.CreateContact(contact)); Assert.Equal("Error: Invalid contact type detected.", exception.Message); }
public async Task ShouldCreateOneVendorContactUsingContactDomainObj() { var contact = new ContactDomainObj { PersonType = "VC", IsEasternNameStyle = false, Title = "Ms.", FirstName = "Jennifer", LastName = "Lopez", EmailPromotion = EmailPromoPreference.AdventureWorksAndPartners, EmailAddress = "*****@*****.**", EmailPasswordHash = "elZhadf87Lkl3cXx4oYxXdV31zWENyCgo3VUn5l5l/c=", EmailPasswordSalt = "K4sEsXg=", ContactTypeID = 17, ParentEntityID = 2 }; await _contactRepo.CreateContact(contact); var result = await _contactRepo.GetContactByID(contact.BusinessEntityID); Assert.NotNull(result); Assert.Equal(contact.EmailPasswordHash, result.EmailPasswordHash); }
public async Task <IActionResult> DeleteVendorContact([FromBody] ContactDomainObj contact) { await _repository.Contact.DeleteContact(contact); return(NoContent()); }
public async Task <IActionResult> CreateVendorContact([FromBody] ContactDomainObj contact) { await _repository.Contact.CreateContact(contact); return(CreatedAtRoute(nameof(GetVendorContactByID), new { contactID = contact.BusinessEntityID }, contact)); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { /*** View models ***/ modelBuilder.Query <PhoneViewModel>().ToQuery(() => PhoneViewModel.FromSql( @"SELECT BusinessEntityID, PhoneNumber, ph.PhoneNumberTypeID, phtype.Name AS PhoneNumberType FROM Person.PersonPhone ph INNER JOIN Person.PhoneNumberType phtype ON ph.PhoneNumberTypeID = phtype.PhoneNumberTypeID" ).AsQueryable()); modelBuilder.Query <PhoneViewModel>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <PhoneViewModel>(query => query.Ignore(e => e.ModifiedDate)); modelBuilder.Query <AddressViewModel>().ToQuery(() => AddressViewModel.FromSql( @"SELECT bea.BusinessEntityID, a.AddressID, AddressLine1, AddressLine2, City, a.StateProvinceID, StateProvinceCode, PostalCode, a.SpatialLocation, CountryRegionCode, bea.AddressTypeID, t.Name AS AddressTypeName FROM Person.Address a INNER JOIN Person.StateProvince st ON a.StateProvinceID = st.StateProvinceID INNER JOIN Person.BusinessEntityAddress bea ON a.AddressID = bea.AddressID INNER JOIN Person.AddressType t ON bea.AddressTypeID = t.AddressTypeID" ).AsQueryable()); modelBuilder.Query <AddressViewModel>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <AddressViewModel>(query => query.Ignore(e => e.ModifiedDate)); modelBuilder.Query <VendorContactViewModel>().ToQuery(() => VendorContactViewModel.FromSql( @"SELECT pp.BusinessEntityID, pp.PersonType, pp.NameStyle AS IsEasternNameStyle, pp.Title, pp.FirstName, pp.MiddleName, pp.LastName, pp.Suffix, pp.EmailPromotion, pp.AdditionalContactInfo, pp.Demographics, email.EmailAddressID, email.EmailAddress, pw.PasswordHash AS EmailPasswordHash, pw.PasswordSalt AS EmailPasswordSalt, bec.ContactTypeID, ct.Name AS ContactPosition, bec.BusinessEntityID AS VendorID FROM Person.Person pp INNER JOIN Person.EmailAddress email ON pp.BusinessEntityID = email.BusinessEntityID INNER JOIN Person.[Password] pw ON pp.BusinessEntityID = pw.BusinessEntityID INNER JOIN Person.BusinessEntityContact bec ON pp.BusinessEntityID = bec.PersonID INNER JOIN Person.ContactType ct ON bec.ContactTypeID = ct.ContactTypeID WHERE bec.BusinessEntityID IN (SELECT BusinessEntityID FROM Purchasing.Vendor)" ).AsQueryable()); modelBuilder.Query <VendorContactViewModel>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <VendorContactViewModel>(query => query.Ignore(e => e.ModifiedDate)); modelBuilder.Query <VendorViewModel>().ToQuery(() => VendorViewModel.FromSql( @"SELECT ven.BusinessEntityID, ven.AccountNumber, ven.Name, CAST(ven.CreditRating AS int) AS CreditRating, ven.PreferredVendorStatus AS PreferredVendor, ven.PurchasingWebServiceURL, ven.ActiveFlag AS IsActive FROM Purchasing.Vendor ven" ).AsQueryable()); modelBuilder.Query <VendorViewModel>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <VendorViewModel>(query => query.Ignore(e => e.ModifiedDate)); modelBuilder.Query <EmployeeViewModel>().ToQuery(() => EmployeeViewModel.FromSql( @"SELECT pp.BusinessEntityID, pp.PersonType, pp.NameStyle AS IsEasternNameStyle, pp.Title, pp.FirstName, pp.MiddleName, pp.LastName, pp.Suffix, pp.EmailPromotion, pp.AdditionalContactInfo, pp.Demographics, email.EmailAddressID, email.EmailAddress, pw.PasswordHash AS EmailPasswordHash, pw.PasswordSalt AS EmailPasswordSalt, ee.NationalIDNumber, ee.LoginID, ee.JobTitle, ee.BirthDate, ee.MaritalStatus, ee.Gender, ee.HireDate, ee.SalariedFlag AS IsSalaried, ee.VacationHours, ee.SickLeaveHours, ee.CurrentFlag AS IsActive FROM Person.Person pp INNER JOIN Person.EmailAddress email ON pp.BusinessEntityID = email.BusinessEntityID INNER JOIN Person.[Password] pw ON pp.BusinessEntityID = pw.BusinessEntityID INNER JOIN HumanResources.Employee ee ON ee.BusinessEntityID = pp.BusinessEntityID" ).AsQueryable()); modelBuilder.Query <EmployeeViewModel>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <EmployeeViewModel>(query => query.Ignore(e => e.ModifiedDate)); /*** Domain objects ***/ // VendorDomainObj modelBuilder.Query <VendorDomainObj>().ToQuery(() => VendorDomainObj.FromSql( @"SELECT ven.BusinessEntityID, ven.AccountNumber, ven.Name, CAST(ven.CreditRating AS int) AS CreditRating, ven.PreferredVendorStatus AS PreferredVendor, ven.PurchasingWebServiceURL, ven.ActiveFlag AS IsActive FROM Purchasing.Vendor ven" ).AsQueryable()); modelBuilder.Query <VendorDomainObj>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <VendorDomainObj>(query => query.Ignore(e => e.ModifiedDate)); // ContactDomainObj modelBuilder.Query <ContactDomainObj>().ToQuery(() => ContactDomainObj.FromSql( @"SELECT pp.BusinessEntityID, pp.PersonType, pp.NameStyle AS IsEasternNameStyle, pp.Title, pp.FirstName, pp.MiddleName, pp.LastName, pp.Suffix, pp.EmailPromotion, pp.AdditionalContactInfo, pp.Demographics, email.EmailAddressID, email.EmailAddress, pw.PasswordHash AS EmailPasswordHash, pw.PasswordSalt AS EmailPasswordSalt, bec.ContactTypeID, bec.BusinessEntityID AS ParentEntityID FROM Person.Person pp INNER JOIN Person.EmailAddress email ON pp.BusinessEntityID = email.BusinessEntityID INNER JOIN Person.[Password] pw ON pp.BusinessEntityID = pw.BusinessEntityID INNER JOIN Person.BusinessEntityContact bec ON pp.BusinessEntityID = bec.PersonID INNER JOIN Person.ContactType ct ON bec.ContactTypeID = ct.ContactTypeID" ).AsQueryable()); modelBuilder.Query <ContactDomainObj>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <ContactDomainObj>(query => query.Ignore(e => e.ModifiedDate)); // AddressDomainObj modelBuilder.Query <AddressDomainObj>().ToQuery(() => AddressDomainObj.FromSql( @"SELECT a.AddressID, AddressLine1, AddressLine2, City, a.StateProvinceID, PostalCode, a.SpatialLocation, bea.AddressTypeID, bea.BusinessEntityID AS ParentEntityID FROM Person.Address a INNER JOIN Person.StateProvince st ON a.StateProvinceID = st.StateProvinceID INNER JOIN Person.BusinessEntityAddress bea ON a.AddressID = bea.AddressID INNER JOIN Person.AddressType t ON bea.AddressTypeID = t.AddressTypeID" ).AsQueryable()); modelBuilder.Query <AddressDomainObj>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <AddressDomainObj>(query => query.Ignore(e => e.ModifiedDate)); // EmployeeDomainObj modelBuilder.Query <EmployeeDomainObj>().ToQuery(() => EmployeeDomainObj.FromSql( @"SELECT pp.BusinessEntityID, pp.PersonType, pp.NameStyle AS IsEasternNameStyle, pp.Title, pp.FirstName, pp.MiddleName, pp.LastName, pp.Suffix, pp.EmailPromotion, pp.AdditionalContactInfo, pp.Demographics, email.EmailAddress, pw.PasswordHash, pw.PasswordSalt, ee.NationalIDNumber, ee.LoginID, ee.JobTitle, ee.BirthDate, ee.MaritalStatus, ee.Gender, ee.HireDate, ee.SalariedFlag AS IsSalaried, ee.VacationHours, ee.SickLeaveHours, ee.CurrentFlag AS IsActive FROM Person.Person pp INNER JOIN Person.EmailAddress email ON pp.BusinessEntityID = email.BusinessEntityID INNER JOIN Person.[Password] pw ON pp.BusinessEntityID = pw.BusinessEntityID INNER JOIN HumanResources.Employee ee ON ee.BusinessEntityID = pp.BusinessEntityID" ).AsQueryable()); modelBuilder.Query <EmployeeDomainObj>(query => query.Ignore(e => e.RowGuid)); modelBuilder.Query <EmployeeDomainObj>(query => query.Ignore(e => e.ModifiedDate)); modelBuilder.ApplyConfiguration(new BusinessEntityConfig()); modelBuilder.ApplyConfiguration(new AddressConfig()); modelBuilder.ApplyConfiguration(new AddressTypeConfig()); modelBuilder.ApplyConfiguration(new BusinessEntityAddressConfig()); modelBuilder.ApplyConfiguration(new BusinessEntityContactConfig()); modelBuilder.ApplyConfiguration(new ContactTypeConfig()); modelBuilder.ApplyConfiguration(new CountryRegionConfig()); modelBuilder.ApplyConfiguration(new EmailAddressConfig()); modelBuilder.ApplyConfiguration(new PersonConfig()); modelBuilder.ApplyConfiguration(new PersonPhoneConfig()); modelBuilder.ApplyConfiguration(new PasswordConfig()); modelBuilder.ApplyConfiguration(new PhoneNumberTypeConfig()); modelBuilder.ApplyConfiguration(new StateProvinceConfig()); modelBuilder.ApplyConfiguration(new VendorConfig()); modelBuilder.ApplyConfiguration(new SalesTaxRateConfig()); modelBuilder.ApplyConfiguration(new SalesTerritoryConfig()); modelBuilder.ApplyConfiguration(new DepartmentConfig()); modelBuilder.ApplyConfiguration(new EmployeeConfig()); modelBuilder.ApplyConfiguration(new EmployeeDepartmentHistoryConfig()); modelBuilder.ApplyConfiguration(new EmployeePayHistoryConfig()); modelBuilder.ApplyConfiguration(new JobCandidateConfig()); modelBuilder.ApplyConfiguration(new ShiftConfig()); }