public void PayrollTracker_DeleteButtonClickedEventHandler(object sender, EventArgs e)
        {
            BoardingRepository boardingRepository = new BoardingRepository();
            foreach (KeyValuePair<int, Boarding> entry in deleteBoardingsMap)
            {
                Boarding boarding = entry.Value;

                if (boarding.BoardingId != null)
                {
                    boardingRepository.Remove(boarding);
                }
            }

            deleteBoardingsMap = new Dictionary<int, Boarding>();
            refreshDisplayFromDatabase();
        }
        public void PayrollTracker_SaveButtonClickedEventHandler(object sender, EventArgs e)
        {
            BoardingRepository boardingRepository = new BoardingRepository();
            foreach (KeyValuePair<int, Boarding> entry in dirtyBoardingsMap)
            {
                Boarding boarding = entry.Value;

                bool isValid = dataGridView1_RowValidating(entry.Key, boarding);

                if (isValid)
                {
                    if (boarding.BoardingId == null)
                    {
                        boardingRepository.Add(boarding);
                    }
                    else
                    {
                        boardingRepository.Update(boarding);
                    }

                    dirtyBoardingsMap = new Dictionary<int, Boarding>();
                    refreshDisplayFromDatabase();
                }
            }
        }
Ejemplo n.º 3
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);
        }
        private void refreshDisplayFromDatabase()
        {
            this.dataGridView1.Rows.Clear();

            BoardingRepository boardingRepository = new BoardingRepository();
            IList<Boarding> boardingsList = boardingRepository.GetRecentBoardings(user, payrollStartDate, payrollEndDate);

            foreach (Boarding boarding in boardingsList)
            {
                int index = this.dataGridView1.Rows.Add();

                dataGridView1.Rows[index].Cells["DateColumn"].Value = boarding.Date;
                dataGridView1.Rows[index].Cells["DogNameColumn"].Value = boarding.Dog.DogId;

                string daycareOrNonDaycare = "Non-daycare";
                if (boarding.IsDaycare)
                {
                    daycareOrNonDaycare = "Daycare";
                }
                dataGridView1.Rows[index].Cells["DaycareOrNonDaycareColumn"].Value = daycareOrNonDaycare;

                dataGridView1.Rows[index].Cells["BoardingRateColumn"].Value = boarding.BoardingCost.CostId;

                if (boarding.SundayDaycareCost != null)
                {
                    dataGridView1.Rows[index].Cells["SundayDaycareColumn"].Value = boarding.SundayDaycareCost.CostId;
                }

                dataGridView1.Rows[index].Cells["TipColumn"].Value = boarding.Tip.ToString();

                dataGridView1.Rows[index].Cells["BoardingIdColumn"].Value = boarding.BoardingId;
            }
        }
Ejemplo n.º 5
0
        private void DeleteInitialData()
        {
            IBoardingRepository boardingRepository = new BoardingRepository();
            foreach (var boarding in _boardings)
            {
                Boarding fromDb = boardingRepository.GetById(boarding.BoardingId);
                if (fromDb != null)
                {
                    boardingRepository.Remove(boarding);
                }
            }

            IUserRepository userRepository = new UserRepository();
            userRepository.Remove(_user1);
            userRepository.Remove(_user2);

            IDogRepository dogRepository = new DogRepository();
            dogRepository.Remove(_dog1);
            dogRepository.Remove(_dog2);

            ICostRepository costRepository = new CostRepository();
            costRepository.Remove(_boardingCost);
            costRepository.Remove(_sundayDaycareCost);
        }
Ejemplo n.º 6
0
        public void Can_update_existing_boarding()
        {
            var boarding = _boardings[1];
            boarding.Tip = 30.00;
            IBoardingRepository repository = new BoardingRepository();
            repository.Update(boarding);

            // use session to try to load the boarding
            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<Boarding>(boarding.BoardingId);
                Assert.AreEqual(boarding.Tip, fromDb.Tip);
            }
        }
Ejemplo n.º 7
0
        public void Can_remove_existing_boarding()
        {
            var boarding = _boardings[0];
            IBoardingRepository repository = new BoardingRepository();
            repository.Remove(boarding);

            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<Boarding>(boarding.BoardingId);
                Assert.IsNull(fromDb);
            }
        }
Ejemplo n.º 8
0
 public void Can_get_existing_boarding_by_id()
 {
     IBoardingRepository repository = new BoardingRepository();
     var fromDb = repository.GetById(_boardings[1].BoardingId);
     Assert.IsNotNull(fromDb);
     Assert.AreNotSame(_boardings[1], fromDb);
     Assert.AreEqual(_boardings[1].Date, fromDb.Date);
     Assert.AreEqual(_boardings[1].IsDaycare, fromDb.IsDaycare);
     Assert.AreEqual(_boardings[1].Dog, fromDb.Dog);
     Assert.AreEqual(_boardings[1].BoardingCost, fromDb.BoardingCost);
     Assert.AreEqual(_boardings[1].SundayDaycareCost, fromDb.SundayDaycareCost);
     Assert.AreEqual(_boardings[1].User, fromDb.User);
 }
Ejemplo n.º 9
0
        public void Can_get_existing_boardings_by_user_id()
        {
            IBoardingRepository repository = new BoardingRepository();
            var fromDb = repository.GetByUser(_boardings[1].User);

            Assert.AreEqual(2, fromDb.Count);
            Assert.IsTrue(IsInCollection(_boardings[1], fromDb));
        }