public async Task ShouldCreateOneVendorFromVendorDomainObj() { ResetDatabase(); var vendor = new VendorDomainObj { AccountNumber = "TESTVEN0001", Name = "Test Vendor", CreditRating = CreditRating.Superior, PreferredVendor = true, IsActive = true }; string jsonVendor = JsonConvert.SerializeObject(vendor); HttpContent content = new StringContent(jsonVendor, Encoding.UTF8, "application/json"); var response = await _client.PostAsync($"{serviceAddress}{rootAddress}/", content); Assert.True(response.IsSuccessStatusCode); var jsonResponse = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <VendorDomainObj>(jsonResponse); Assert.Equal(vendor.AccountNumber, result.AccountNumber); }
public static void Map(this Vendor entityObj, VendorDomainObj domainObj) { entityObj.BusinessEntityID = domainObj.BusinessEntityID; entityObj.AccountNumber = domainObj.AccountNumber; entityObj.Name = domainObj.Name; entityObj.CreditRating = domainObj.CreditRating; entityObj.PreferredVendor = domainObj.PreferredVendor; entityObj.PurchasingWebServiceURL = domainObj.PurchasingWebServiceURL; entityObj.IsActive = domainObj.IsActive; }
public async Task ShouldRaiseExceptionDuplicateVendorAccountNumberWhileCreating() { var vendorDomainObj = new VendorDomainObj { AccountNumber = "CYCLERU0001", Name = "Test Vendor", CreditRating = CreditRating.Superior, PreferredVendor = true, IsActive = true }; var exception = await Assert.ThrowsAsync <AdventureWorksUniqueIndexException>(() => _vendorRepo.CreateVendor(vendorDomainObj)); Assert.Equal("Error: This operation would result in a duplicate vendor account number!", exception.Message); }
public async Task ShouldCreateVendorFromVendorDomainObj() { var vendorDomainObj = new VendorDomainObj { AccountNumber = "TESTVEN0001", Name = "Test Vendor", CreditRating = CreditRating.Superior, PreferredVendor = true, IsActive = true }; await _vendorRepo.CreateVendor(vendorDomainObj); var vendor = await _vendorRepo.GetVendorByID(vendorDomainObj.BusinessEntityID); Assert.NotNull(vendor); Assert.Equal("TESTVEN0001", vendor.AccountNumber); }
public async Task ShouldDeleteOneVendorFromVendorDomainObj() { ResetDatabase(); var vendor = new VendorDomainObj { BusinessEntityID = 3, AccountNumber = "DESOTOB0001", Name = "Desoto Bicycle Exchange", CreditRating = CreditRating.Superior, PreferredVendor = true, IsActive = true }; var response = await _client.DeleteAsJsonAsync($"{serviceAddress}{rootAddress}", vendor); Assert.True(response.IsSuccessStatusCode); }
public async Task ShouldFailToDeleteVendorBecauseOfBadVendorID() { ResetDatabase(); var vendor = new VendorDomainObj { BusinessEntityID = 3321, AccountNumber = "DESOTOB0001", Name = "Desoto Bicycle Exchange", CreditRating = CreditRating.Superior, PreferredVendor = true, IsActive = true }; var response = await _client.DeleteAsJsonAsync($"{serviceAddress}{rootAddress}", vendor); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); }
public async Task ShouldUpdateOneVendorFromVendorDomainObj() { ResetDatabase(); var vendor = new VendorDomainObj { BusinessEntityID = 3, AccountNumber = "DESOTOB0001", Name = "Desoto Bicycle Exchange", CreditRating = CreditRating.Superior, PreferredVendor = true, IsActive = true }; string jsonVendor = JsonConvert.SerializeObject(vendor); HttpContent content = new StringContent(jsonVendor, Encoding.UTF8, "application/json"); var response = await _client.PutAsync($"{serviceAddress}{rootAddress}/", content); Assert.True(response.IsSuccessStatusCode); }
public async Task <IActionResult> Edit([FromForm] VendorDomainObj vendor) { if (ModelState.IsValid) { try { await _repository.Vendor.UpdateVendor(vendor); } catch (Exception ex) { ModelState.AddModelError(nameof(VendorDomainObj), ex.Message); var creditRatingLookup = CreditRatingLookupCollection.CreditRatingStatuses(); ViewBag.CreditRatingLookup = creditRatingLookup; return(View(vendor)); } } else { return(View(vendor)); } return(RedirectToAction(nameof(List))); }
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()); }
public async Task <IActionResult> DeleteVendor([FromBody] VendorDomainObj vendor) { await _repository.Vendor.DeleteVendor(vendor); return(NoContent()); }
public async Task <IActionResult> CreateVendor([FromBody] VendorDomainObj vendor) { await _repository.Vendor.CreateVendor(vendor); return(CreatedAtRoute("VendorById", new { id = vendor.BusinessEntityID }, vendor)); }