コード例 #1
0
 public void Update(Boarding boarding)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     using (ITransaction transaction = session.BeginTransaction())
     {
         session.Update(boarding);
         transaction.Commit();
     }
 }
コード例 #2
0
        public void Can_add_multiple_new_boardings()
        {
            ISession session = _sessionFactory.OpenSession();

            int countBefore = getBoardingTableSize(session);

            ITransaction tx = session.BeginTransaction();
            Boarding boarding1 = new Boarding();
            boarding1.Date = DateTime.Now;
            boarding1.IsDaycare = true;
            boarding1.Dog = _dog1;
            boarding1.BoardingCost = _boardingCost;
            boarding1.SundayDaycareCost = _sundayDaycareCost;
            boarding1.User = _user1;
            boarding1.Tip = 10.0;
            session.Save(boarding1);

            Boarding boarding2 = new Boarding();
            boarding2.Date = DateTime.Now;
            boarding2.IsDaycare = true;
            boarding2.Dog = _dog2;
            boarding2.BoardingCost = _boardingCost;
            boarding2.SundayDaycareCost = _sundayDaycareCost;
            boarding2.User = _user2;
            session.Save(boarding2);

            Boarding boarding3 = new Boarding();
            boarding3.Date = DateTime.Now;
            boarding3.IsDaycare = true;
            boarding3.Dog = _dog1;
            boarding3.BoardingCost = _boardingCost;
            boarding3.SundayDaycareCost = _sundayDaycareCost;
            boarding3.User = _user1;
            session.Save(boarding3);

            tx.Commit();

            Assert.AreEqual(countBefore + 3, getBoardingTableSize(session));

            tx = session.BeginTransaction();

            session.Delete(boarding1);
            session.Delete(boarding2);
            session.Delete(boarding3);

            tx.Commit();

            session.Close();
        }
コード例 #3
0
        private bool dataGridView1_RowValidating(int index, Boarding boarding)
        {
            if (boarding.Date < payrollStartDate || boarding.Date > payrollEndDate)
            {
                dataGridView1.Rows[index].ErrorText = "Boarding Date must be for current payroll period (" + payrollStartDate + " - " + payrollEndDate + ").";
                return false;
            }

            if (boarding.Dog == null)
            {
                dataGridView1.Rows[index].ErrorText = "Dog's Name must not be empty.";
                return false;
            }
            else if (dataGridView1.Rows[index].Cells["DaycareOrNonDaycareColumn"].Value == null)
            {
                dataGridView1.Rows[index].ErrorText = "Daycare/Non-daycare must not be empty.";
                return false;
            }
            else if (boarding.BoardingCost == null)
            {
                dataGridView1.Rows[index].ErrorText = "Boarding Rate must not be empty.";
                return false;
            }

            if (dataGridView1.Rows[index].Cells["TipColumn"].Value != null)
            {
                string value = dataGridView1.Rows[index].Cells["TipColumn"].Value.ToString();

                try
                {
                    Double tip = Convert.ToDouble(value);
                }
                catch (FormatException exception)
                {
                    dataGridView1.Rows[index].ErrorText = "Tip must be numeric.";
                    return false;
                }
            }

            return true;
        }
コード例 #4
0
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.IsCurrentCellDirty)
            {
                if (dirtyBoardingsMap.Keys.Contains(e.RowIndex))
                {
                    dirtyBoardingsMap.Remove(e.RowIndex);
                }

                Boarding boarding = new Boarding();

                DateTime date = (DateTime)dataGridView1.Rows[e.RowIndex].Cells["DateColumn"].Value;
                boarding.Date = date;

                string daycareNonDaycare = (string)dataGridView1.Rows[e.RowIndex].Cells["DaycareOrNonDaycareColumn"].Value;
                bool isDaycare = "Daycare".Equals(daycareNonDaycare) ? true : false;
                boarding.IsDaycare = isDaycare;

                string dogId = (string)dataGridView1.Rows[e.RowIndex].Cells["DogNameColumn"].Value;
                DogRepository dogRepository = new DogRepository();
                if (dogId != null)
                {
                    Dog dog = dogRepository.GetById(dogId);
                    boarding.Dog = dog;
                }

                CostRepository costRepository = new CostRepository();
                string boardingCostId = (string)dataGridView1.Rows[e.RowIndex].Cells["BoardingRateColumn"].Value;
                if (boardingCostId != null)
                {
                    Cost boardingCost = costRepository.GetById(boardingCostId);
                    boarding.BoardingCost = boardingCost;
                }

                string sundayDaycareCostId = (string)dataGridView1.Rows[e.RowIndex].Cells["SundayDaycareColumn"].Value;
                if (sundayDaycareCostId != null)
                {
                    Cost sundayDaycareCost = costRepository.GetById(sundayDaycareCostId);
                    boarding.SundayDaycareCost = sundayDaycareCost;
                }

                string tipStr = (string)dataGridView1.Rows[e.RowIndex].Cells["TipColumn"].Value;
                try
                {
                    Double tip = Convert.ToDouble(tipStr);
                    boarding.Tip = tip;
                }
                catch (FormatException exception)
                {
                    //Catch this exception quietly for now.
                }

                boarding.User = user;

                string boardingId = (string)dataGridView1.Rows[e.RowIndex].Cells["BoardingIdColumn"].Value;

                boarding.BoardingId = boardingId;

                dirtyBoardingsMap.Add(e.RowIndex, boarding);

                // Remove the entry from the delete map, if
                // an entry for the Boarding exists in the
                // delete map already.
                if (deleteBoardingsMap.Keys.Contains(e.RowIndex))
                {
                    deleteBoardingsMap.Remove(e.RowIndex);
                }

                var isSelected = dataGridView1.Rows[e.RowIndex].Cells["SelectColumn"].Value;

                if (isSelected != null && (bool)isSelected)
                {
                    deleteBoardingsMap.Add(e.RowIndex, boarding);
                }
            }
        }
コード例 #5
0
        public void Can_add_new_boarding()
        {
            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 boarding = new Boarding(date, true, _dog1, _boardingCost, _user1);
            IBoardingRepository repository = new BoardingRepository();
            repository.Add(boarding);

            // use session to try to load the boarding
            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<Boarding>(boarding.BoardingId);
                // Test that the boarding was successfully inserted
                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(boarding, fromDb);
                Assert.AreEqual(boarding.Date, fromDb.Date);
                Assert.AreEqual(boarding.IsDaycare, fromDb.IsDaycare);
                Assert.AreEqual(boarding.Dog, fromDb.Dog);
                Assert.AreEqual(boarding.BoardingCost, fromDb.BoardingCost);
                Assert.AreEqual(boarding.SundayDaycareCost, fromDb.SundayDaycareCost);
                Assert.AreEqual(boarding.User, fromDb.User);
            }

            repository.Remove(boarding);
        }
コード例 #6
0
        private bool IsInCollection(Boarding boarding, ICollection<Boarding> fromDb)
        {
            bool result = false;

            foreach (var item in fromDb)
            {
                if (boarding.BoardingId == item.BoardingId)
                {
                    result = true;
                    break;
                }
            }
            return result;
        }
コード例 #7
0
        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(_boardingCost);
                session.Save(_sundayDaycareCost);

                // Get rid of milliseconds to make comparisons work, since MySQL
                // DateTime does not support milliseconds.
                DateTime date = DateTime.ParseExact(DateTime.Now.ToString(), "M/d/yyyy h:mm:ss tt", null);

                _boardings = new Boarding [4];
                _boardings[0] = new Boarding(date, true, _dog1, _boardingCost, _user1);
                _boardings[1] = new Boarding(date, true, _dog1, _boardingCost, _user2);
                _boardings[2] = new Boarding(date, false, _dog2, _boardingCost, _user1);
                _boardings[3] = new Boarding(date, false, _dog2, _boardingCost, _user2);

                foreach (var boarding in _boardings)
                {
                    session.Save(boarding);
                }

                transaction.Commit();
            }
        }