public void PayrollTracker_SaveButtonClickedEventHandler(object sender, EventArgs e)
        {
            PickupDropoffRepository repository = new PickupDropoffRepository();

            foreach (KeyValuePair<int, PickupDropoff> entry in dirtyObjectsMap)
            {
                PickupDropoff pickupDropoff = entry.Value;

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

                if (isValid)
                {
                    if (pickupDropoff.PickupDropoffId == null)
                    {
                        repository.Add(pickupDropoff);
                    }
                    else
                    {
                        repository.Update(pickupDropoff);
                    }

                    dirtyObjectsMap = new Dictionary<int, PickupDropoff>();
                    refreshDisplayFromDatabase();
                }
            }
        }
        public void PayrollTracker_DeleteButtonClickedEventHandler(object sender, EventArgs e)
        {
            PickupDropoffRepository repository = new PickupDropoffRepository();
            foreach (KeyValuePair<int, PickupDropoff> entry in deleteObjectsMap)
            {
                PickupDropoff pickupDropoff = entry.Value;

                if (pickupDropoff.PickupDropoffId != null)
                {
                    repository.Remove(pickupDropoff);
                }
            }

            deleteObjectsMap = new Dictionary<int, PickupDropoff>();
            refreshDisplayFromDatabase();
        }
        public void Can_add_new_pickupDropoff()
        {
            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 pickupDropoff = new PickupDropoff(date, _dog1, _user1);
            IPickupDropoffRepository repository = new PickupDropoffRepository();
            repository.Add(pickupDropoff);

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

            repository.Remove(pickupDropoff);
        }
        private void DeleteInitialData()
        {
            IPickupDropoffRepository pickupDropoffRepository = new PickupDropoffRepository();
            foreach (var pickupDropoff in _pickupDropoffs)
            {
                PickupDropoff fromDb = pickupDropoffRepository.GetById(pickupDropoff.PickupDropoffId);
                if (fromDb != null)
                {
                    pickupDropoffRepository.Remove(pickupDropoff);
                }
            }

            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(_pickupCost);
            costRepository.Remove(_dropoffCost);
            costRepository.Remove(_newPickupCost);
        }
        public void Can_update_existing_pickupDropoff()
        {
            var pickupDropoff = _pickupDropoffs[1];
            pickupDropoff.PickupCost = _newPickupCost;

            IPickupDropoffRepository repository = new PickupDropoffRepository();
            repository.Update(pickupDropoff);

            // use session to try to load the pickupDropoff
            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<PickupDropoff>(pickupDropoff.PickupDropoffId);
                Assert.AreEqual(pickupDropoff.PickupCost, fromDb.PickupCost);
            }
        }
        public void Can_remove_existing_pickupDropoff()
        {
            var pickupDropoff = _pickupDropoffs[0];
            IPickupDropoffRepository repository = new PickupDropoffRepository();
            repository.Remove(pickupDropoff);

            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<PickupDropoff>(pickupDropoff.PickupDropoffId);
                Assert.IsNull(fromDb);
            }
        }
 public void Can_get_existing_pickupDropoff_by_id()
 {
     IPickupDropoffRepository repository = new PickupDropoffRepository();
     var fromDb = repository.GetById(_pickupDropoffs[1].PickupDropoffId);
     Assert.IsNotNull(fromDb);
     Assert.AreNotSame(_pickupDropoffs[1], fromDb);
     Assert.AreEqual(_pickupDropoffs[1].Date, fromDb.Date);
     Assert.AreEqual(_pickupDropoffs[1].Dog, fromDb.Dog);
     Assert.AreEqual(_pickupDropoffs[1].PickupCost, fromDb.PickupCost);
     Assert.AreEqual(_pickupDropoffs[1].DropoffCost, fromDb.DropoffCost);
     Assert.AreEqual(_pickupDropoffs[1].User, fromDb.User);
 }
        public void Can_get_existing_pickupDropoffs_by_user_id()
        {
            IPickupDropoffRepository repository = new PickupDropoffRepository();
            var fromDb = repository.GetByUser(_pickupDropoffs[1].User);

            Assert.AreEqual(2, fromDb.Count);
            Assert.IsTrue(IsInCollection(_pickupDropoffs[1], fromDb));
        }
        private void refreshDisplayFromDatabase()
        {
            this.dataGridView1.Rows.Clear();

            PickupDropoffRepository repository = new PickupDropoffRepository();
            IList<PickupDropoff> pickupsAndDropoffsList = repository.GetRecentPickupsAndDropoffs(user, payrollStartDate, payrollEndDate);

            foreach (PickupDropoff pickupDropoff in pickupsAndDropoffsList)
            {
                int index = this.dataGridView1.Rows.Add();

                dataGridView1.Rows[index].Cells["DateColumn"].Value = pickupDropoff.Date;

                dataGridView1.Rows[index].Cells["DogNameColumn"].Value = pickupDropoff.Dog.DogId;

                if (pickupDropoff.PickupCost != null)
                {
                    dataGridView1.Rows[index].Cells["PickupCostColumn"].Value = pickupDropoff.PickupCost.CostId;
                }

                if (pickupDropoff.DropoffCost != null)
                {
                    dataGridView1.Rows[index].Cells["DropoffCostColumn"].Value = pickupDropoff.DropoffCost.CostId;
                }

                dataGridView1.Rows[index].Cells["PickupDropoffIdColumn"].Value = pickupDropoff.PickupDropoffId;
            }
        }