public void Update(Grooming grooming) { using (ISession session = NHibernateHelper.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.Update(grooming); transaction.Commit(); } }
public void Can_add_multiple_new_groomings() { ISession session = _sessionFactory.OpenSession(); int countBefore = getGroomingTableSize(session); ITransaction tx = session.BeginTransaction(); Grooming grooming1 = new Grooming(); grooming1.GroomingType = _groomingType1; grooming1.Cost = 99.99; grooming1.Date = DateTime.Now; grooming1.Dog = _dog1; grooming1.User = _user1; session.Save(grooming1); Grooming grooming2 = new Grooming(); grooming2.GroomingType = _groomingType2; grooming2.Cost = 199.99; grooming2.Date = DateTime.Now; grooming2.Dog = _dog2; grooming2.User = _user2; session.Save(grooming2); Grooming grooming3 = new Grooming(); grooming3.GroomingType = _groomingType1; grooming3.Cost = 22.16; grooming3.Date = DateTime.Now; grooming3.Dog = _dog1; grooming3.User = _user1; session.Save(grooming3); tx.Commit(); Assert.AreEqual(countBefore + 3, getGroomingTableSize(session)); tx = session.BeginTransaction(); session.Delete(grooming1); session.Delete(grooming2); session.Delete(grooming3); tx.Commit(); session.Close(); }
public void Can_add_new_grooming() { DateTime date = DateTime.Now; // Set the Milliseconds to 0 since MySQL DATETIME does not support milliseconds. date = DateTime.ParseExact(date.ToString(), "M/d/yyyy h:mm:ss tt", null); var grooming = new Grooming(_groomingType1, 245.50, date, _dog1, _user1); IGroomingRepository repository = new GroomingRepository(); repository.Add(grooming); // use session to try to load the grooming using (ISession session = _sessionFactory.OpenSession()) { var fromDb = session.Get<Grooming>(grooming.GroomingId); // Test that the grooming was successfully inserted Assert.IsNotNull(fromDb); Assert.AreNotSame(grooming, fromDb); Assert.AreEqual(grooming.GroomingType, fromDb.GroomingType); Assert.AreEqual(grooming.Cost, fromDb.Cost); Assert.AreEqual(grooming.Date, fromDb.Date); Assert.AreEqual(grooming.Dog, fromDb.Dog); Assert.AreEqual(grooming.User, fromDb.User); } repository.Remove(grooming); }
private bool IsInCollection(Grooming grooming, ICollection<Grooming> fromDb) { bool result = false; foreach (var item in fromDb) { if (grooming.GroomingId == item.GroomingId) { result = true; break; } } return result; }
private void CreateInitialData() { using (ISession session = _sessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { // Save the user to populate its UserId. session.Save(_user1); session.Save(_user2); session.Save(_dog1); session.Save(_dog2); session.Save(_groomingType1); session.Save(_groomingType2); _groomings = new Grooming [4]; _groomings[0] = new Grooming (_groomingType1, 45.50, DateTime.Now, _dog1, _user1); _groomings[1] = new Grooming (_groomingType1, 35.50, DateTime.Now, _dog1, _user2); _groomings[2] = new Grooming (_groomingType2, 25.50, DateTime.Now, _dog2, _user1); _groomings[3] = new Grooming (_groomingType2, 15.50, DateTime.Now, _dog2, _user2); foreach (var grooming in _groomings) { // Get rid of milliseconds to make comparisons work, since MySQL // DateTime does not support milliseconds. grooming.Date = DateTime.ParseExact(grooming.Date.ToString(), "M/d/yyyy h:mm:ss tt", null); session.Save(grooming); } transaction.Commit(); } }
private bool groomingDataGridView_RowValidating(int index, Grooming grooming) { if (grooming.Date < payrollStartDate || grooming.Date > payrollEndDate) { groomingDataGridView.Rows[index].ErrorText = "Grooming Date must be for current payroll period (" + payrollStartDate + " - " + payrollEndDate + ")."; return false; } if (grooming.Dog == null) { groomingDataGridView.Rows[index].ErrorText = "Dog's Name must not be empty."; return false; } else if (grooming.GroomingType == null) { groomingDataGridView.Rows[index].ErrorText = "Groom Type must not be empty."; return false; } else if (groomingDataGridView.Rows[index].Cells["CostColumn"].Value == null) { groomingDataGridView.Rows[index].ErrorText = "Cost must not be empty."; return false; } if (groomingDataGridView.Rows[index].Cells["CostColumn"].Value != null) { string value = groomingDataGridView.Rows[index].Cells["CostColumn"].Value.ToString(); try { Double cost = Convert.ToDouble(value); } catch (FormatException exception) { groomingDataGridView.Rows[index].ErrorText = "Cost must be numeric."; return false; } } if (groomingDataGridView.Rows[index].Cells["TipColumn"].Value != null) { string value = groomingDataGridView.Rows[index].Cells["TipColumn"].Value.ToString(); try { Double tip = Convert.ToDouble(value); } catch (FormatException exception) { groomingDataGridView.Rows[index].ErrorText = "Tip must be numeric."; return false; } } return true; }
private void groomingDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (groomingDataGridView.IsCurrentCellDirty) { if (dirtyObjectsMap.Keys.Contains(e.RowIndex)) { dirtyObjectsMap.Remove(e.RowIndex); } Grooming grooming = new Grooming(); DateTime date = (DateTime)groomingDataGridView.Rows[e.RowIndex].Cells["DateColumn"].Value; grooming.Date = date; string dogId = (string)groomingDataGridView.Rows[e.RowIndex].Cells["DogNameColumn"].Value; DogRepository dogRepository = new DogRepository(); if (dogId != null) { Dog dog = dogRepository.GetById(dogId); grooming.Dog = dog; } GroomingTypeRepository groomingTypeRepository = new GroomingTypeRepository(); string groomingTypeId = (string)groomingDataGridView.Rows[e.RowIndex].Cells["GroomTypeColumn"].Value; if (groomingTypeId != null) { GroomingType groomingType = groomingTypeRepository.GetById(groomingTypeId); grooming.GroomingType = groomingType; } string costStr = (string)groomingDataGridView.Rows[e.RowIndex].Cells["CostColumn"].Value; if (costStr != null) { try { Double cost = Convert.ToDouble(costStr); grooming.Cost = cost; } catch (FormatException exception) { //Catch this exception quietly. } } string tipStr = (string)groomingDataGridView.Rows[e.RowIndex].Cells["TipColumn"].Value; if (tipStr != null) { try { Double tip = Convert.ToDouble(tipStr); grooming.Tip = tip; } catch (FormatException exception) { //Catch this exception quietly. } } grooming.User = user; string groomingId = (string)groomingDataGridView.Rows[e.RowIndex].Cells["GroomingIdColumn"].Value; grooming.GroomingId = groomingId; // Add object to dirty objects map. dirtyObjectsMap.Add(e.RowIndex, grooming); // Remove the entry from the delete map, if // an entry for the Daycare exists in the // delete map already. if (deleteObjectsMap.Keys.Contains(e.RowIndex)) { deleteObjectsMap.Remove(e.RowIndex); } var isSelected = groomingDataGridView.Rows[e.RowIndex].Cells["SelectColumn"].Value; if (isSelected != null && (bool)isSelected) { deleteObjectsMap.Add(e.RowIndex, grooming); } } }