public void SaveClicked() { m_view.ReadUserInput(); Customer customerDataEntity = m_viewModel.CustomerData; List <string> lstMessages = new List <string>(); bool isValid = m_PersonDao.Validate(customerDataEntity, out lstMessages); if (isValid) { Person mypersonEntity = customerDataEntity as Person; if (customerDataEntity.PersonId == 0) { m_PersonDao.Insert(mypersonEntity); } else { m_PersonDao.Update(mypersonEntity); } GetAllCustomer(); } else { string strMessages = String.Join(Environment.NewLine, lstMessages.Select(a => a.ToString())); m_view.Message = strMessages; m_view.ShowError(); } }
public void IntegrationTest() { var connection = TestSession.GetConnection(); connection.Open(); #region good insertion and select by id test PersonModel inserted = new PersonModel(); inserted.BusinessEntityID = TestSession.Random.Next(); inserted.PersonType = TestSession.Random.RandomString(2); inserted.NameStyle = Convert.ToBoolean(TestSession.Random.Next(1)); inserted.Title = TestSession.Random.RandomString(8); inserted.FirstName = TestSession.Random.RandomString(50); inserted.MiddleName = TestSession.Random.RandomString(50); inserted.LastName = TestSession.Random.RandomString(50); inserted.Suffix = TestSession.Random.RandomString(10); inserted.EmailPromotion = TestSession.Random.Next(); inserted.AdditionalContactInfo = null; //TODO define how to generate random xml; inserted.Demographics = null; //TODO define how to generate random xml; inserted.rowguid = Guid.NewGuid(); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Insert(connection, new[] { inserted }); var selectedAfterInsertion = _tested.GetByPrimaryKey(connection, new PersonModelPrimaryKey() { BusinessEntityID = inserted.BusinessEntityID, }); CollectionAssert.IsNotEmpty(selectedAfterInsertion); var selectedAfterInsert = selectedAfterInsertion.Single(); Assert.AreEqual(inserted.BusinessEntityID, selectedAfterInsert.BusinessEntityID); Assert.AreEqual(inserted.PersonType, selectedAfterInsert.PersonType); Assert.AreEqual(inserted.NameStyle, selectedAfterInsert.NameStyle); Assert.AreEqual(inserted.Title, selectedAfterInsert.Title); Assert.AreEqual(inserted.FirstName, selectedAfterInsert.FirstName); Assert.AreEqual(inserted.MiddleName, selectedAfterInsert.MiddleName); Assert.AreEqual(inserted.LastName, selectedAfterInsert.LastName); Assert.AreEqual(inserted.Suffix, selectedAfterInsert.Suffix); Assert.AreEqual(inserted.EmailPromotion, selectedAfterInsert.EmailPromotion); Assert.AreEqual(inserted.AdditionalContactInfo, selectedAfterInsert.AdditionalContactInfo); Assert.AreEqual(inserted.Demographics, selectedAfterInsert.Demographics); Assert.AreEqual(inserted.rowguid, selectedAfterInsert.rowguid); Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate); #endregion #region update and select by id test inserted.PersonType = TestSession.Random.RandomString(2); inserted.NameStyle = Convert.ToBoolean(TestSession.Random.Next(1)); inserted.Title = TestSession.Random.RandomString(8); inserted.FirstName = TestSession.Random.RandomString(50); inserted.MiddleName = TestSession.Random.RandomString(50); inserted.LastName = TestSession.Random.RandomString(50); inserted.Suffix = TestSession.Random.RandomString(10); inserted.EmailPromotion = TestSession.Random.Next(); inserted.AdditionalContactInfo = null; //TODO define how to generate random xml; inserted.Demographics = null; //TODO define how to generate random xml; inserted.rowguid = Guid.NewGuid(); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Update(connection, new[] { inserted }); var selectedAfterUpdateAddresss = _tested.GetByPrimaryKey(connection, new PersonModelPrimaryKey() { BusinessEntityID = inserted.BusinessEntityID, }); CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss); var selectedAfterUpdate = selectedAfterUpdateAddresss.Single(); Assert.AreEqual(inserted.BusinessEntityID, selectedAfterUpdate.BusinessEntityID); Assert.AreEqual(inserted.PersonType, selectedAfterUpdate.PersonType); Assert.AreEqual(inserted.NameStyle, selectedAfterUpdate.NameStyle); Assert.AreEqual(inserted.Title, selectedAfterUpdate.Title); Assert.AreEqual(inserted.FirstName, selectedAfterUpdate.FirstName); Assert.AreEqual(inserted.MiddleName, selectedAfterUpdate.MiddleName); Assert.AreEqual(inserted.LastName, selectedAfterUpdate.LastName); Assert.AreEqual(inserted.Suffix, selectedAfterUpdate.Suffix); Assert.AreEqual(inserted.EmailPromotion, selectedAfterUpdate.EmailPromotion); Assert.AreEqual(inserted.AdditionalContactInfo, selectedAfterUpdate.AdditionalContactInfo); Assert.AreEqual(inserted.Demographics, selectedAfterUpdate.Demographics); Assert.AreEqual(inserted.rowguid, selectedAfterUpdate.rowguid); Assert.AreEqual(inserted.ModifiedDate, selectedAfterUpdate.ModifiedDate); #endregion #region delete test _tested.Delete(connection, new[] { inserted }); var selectedAfterDeleteAddresss = _tested.GetByPrimaryKey(connection, new PersonModelPrimaryKey() { BusinessEntityID = inserted.BusinessEntityID, }); CollectionAssert.IsEmpty(selectedAfterDeleteAddresss); #endregion connection.Close(); }
public void Update() { PersonDao pdao = new PersonDao(); pdao.Update(this); }
public void ModifyManagedEmployees(IList <ManagedEmployee> updatedEmployees, IList <ManagedEmployee> newEmployees) { foreach (var updatedEmployee in updatedEmployees) { var person = _personDao.FindById(updatedEmployee.BusinessEntityID); person.FirstName = updatedEmployee.FirstName; person.LastName = updatedEmployee.LastName; person.EmailPromotion = updatedEmployee.EmailPromotion; person.ModifiedDate = DateTime.Now; _personDao.Update(person); var employee = _employeeDao.FindById(updatedEmployee.BusinessEntityID); employee.NationalIDNumber = updatedEmployee.NationalIDNumber; employee.LoginID = updatedEmployee.LoginID; employee.JobTitle = updatedEmployee.JobTitle; employee.BirthDate = updatedEmployee.BirthDate; employee.MaritalStatus = updatedEmployee.MaritalStatus; employee.Gender = updatedEmployee.Gender; employee.HireDate = updatedEmployee.HireDate; employee.SalariedFlag = updatedEmployee.SalariedFlag; employee.VacationHours = updatedEmployee.VacationHours; employee.SickLeaveHours = updatedEmployee.SickLeaveHours; employee.CurrentFlag = updatedEmployee.CurrentFlag; employee.ModifiedDate = DateTime.Now; _employeeDao.Update(employee); } foreach (var newEmployee in newEmployees) { var businessEntity = _businessEntityDao.Insert(); var person = new Person { BusinessEntityID = businessEntity.BusinessEntityID, PersonType = "EM", FirstName = newEmployee.FirstName, LastName = newEmployee.LastName, EmailPromotion = newEmployee.EmailPromotion, ModifiedDate = DateTime.Now }; _personDao.Insert(person); var employee = new Employee { BusinessEntityID = businessEntity.BusinessEntityID, NationalIDNumber = newEmployee.NationalIDNumber, LoginID = newEmployee.LoginID, JobTitle = newEmployee.JobTitle, BirthDate = newEmployee.BirthDate, MaritalStatus = newEmployee.MaritalStatus, Gender = newEmployee.Gender, HireDate = newEmployee.HireDate, SalariedFlag = newEmployee.SalariedFlag, VacationHours = newEmployee.VacationHours, SickLeaveHours = newEmployee.SickLeaveHours, CurrentFlag = newEmployee.CurrentFlag, ModifiedDate = DateTime.Now }; _employeeDao.Insert(employee); } }