public void PayrollTracker_DeleteButtonClickedEventHandler(object sender, EventArgs e)
        {
            TrainingRepository repository = new TrainingRepository();
            foreach (KeyValuePair<int, Training> entry in deleteObjectsMap)
            {
                Training training = entry.Value;

                if (training.TrainingId != null)
                {
                    repository.Remove(training);
                }
            }

            deleteObjectsMap = new Dictionary<int, Training>();
            refreshDisplayFromDatabase();
        }
Exemplo n.º 2
0
        public void Can_add_new_training()
        {
            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 training = new Training(date, _classType, _classCost, _dog1, _user1);
            ITrainingRepository repository = new TrainingRepository();
            repository.Add(training);

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

            repository.Remove(training);
        }
Exemplo n.º 3
0
        private void DeleteInitialData()
        {
            ITrainingRepository trainingRepository = new TrainingRepository();
            foreach (var training in _trainings)
            {
                Training fromDb = trainingRepository.GetById(training.TrainingId);
                if (fromDb != null)
                {
                    trainingRepository.Remove(training);
                }
            }

            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(_classCost);
            costRepository.Remove(_preK9DaycareCost);
            costRepository.Remove(_newClassCost);

            ICostTypeRepository costTypeRepository = new CostTypeRepository();
            costTypeRepository.Remove(_classType);
        }
Exemplo n.º 4
0
        public void Can_update_existing_training()
        {
            var training = _trainings[1];
            training.ClassCost = _newClassCost;

            ITrainingRepository repository = new TrainingRepository();
            repository.Update(training);

            // use session to try to load the training
            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<Training>(training.TrainingId);
                Assert.AreEqual(training.ClassCost, fromDb.ClassCost);
            }
        }
Exemplo n.º 5
0
        public void Can_remove_existing_training()
        {
            var training = _trainings[0];
            ITrainingRepository repository = new TrainingRepository();
            repository.Remove(training);

            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<Training>(training.TrainingId);
                Assert.IsNull(fromDb);
            }
        }
Exemplo n.º 6
0
 public void Can_get_existing_training_by_id()
 {
     ITrainingRepository repository = new TrainingRepository();
     var fromDb = repository.GetById(_trainings[1].TrainingId);
     Assert.IsNotNull(fromDb);
     Assert.AreNotSame(_trainings[1], fromDb);
     Assert.AreEqual(_trainings[1].Date, fromDb.Date);
     Assert.AreEqual(_trainings[1].Dog, fromDb.Dog);
     Assert.AreEqual(_trainings[1].User, fromDb.User);
     Assert.AreEqual(_trainings[1].ClassType, fromDb.ClassType);
     Assert.AreEqual(_trainings[1].ClassCost, fromDb.ClassCost);
     Assert.AreEqual(_trainings[1].PreK9DaycareCost, fromDb.PreK9DaycareCost);
 }
Exemplo n.º 7
0
        public void Can_get_existing_trainings_by_user_id()
        {
            ITrainingRepository repository = new TrainingRepository();
            var fromDb = repository.GetByUser(_trainings[1].User);

            Assert.AreEqual(2, fromDb.Count);
            Assert.IsTrue(IsInCollection(_trainings[1], fromDb));
        }
        public void PayrollTracker_SaveButtonClickedEventHandler(object sender, EventArgs e)
        {
            TrainingRepository repository = new TrainingRepository();

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

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

                if (isValid)
                {
                    if (training.TrainingId == null)
                    {
                        repository.Add(training);
                    }
                    else
                    {
                        repository.Update(training);
                    }

                    dirtyObjectsMap = new Dictionary<int, Training>();
                    refreshDisplayFromDatabase();
                }
            }
        }
        private void refreshDisplayFromDatabase()
        {
            this.dataGridView1.Rows.Clear();

            TrainingRepository repository = new TrainingRepository();
            IList<Training> trainingsList = repository.GetRecentTrainings(user, payrollStartDate, payrollEndDate);

            foreach (Training training in trainingsList)
            {
                int index = this.dataGridView1.Rows.Add();

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

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

                dataGridView1.Rows[index].Cells["ClassColumn"].Value = training.ClassType.CostTypeId;

                DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)(dataGridView1.Rows[index].Cells["CostOfClassColumn"]);
                IList<Cost> possibleCosts1 = training.ClassType.PossibleCosts;
                ArrayList.Adapter((IList)possibleCosts1).Sort();
                cell.DataSource = possibleCosts1;
                cell.DisplayMember = "CostValue";
                cell.ValueMember = "CostId";
                cell.Value = training.ClassCost.CostId;

                if (TRAINING_CLASS_PRE_K9.Equals(training.ClassType.CostName))
                {
                    DataGridViewComboBoxCell preK9DaycareComboBoxCell = (DataGridViewComboBoxCell)dataGridView1.Rows[index].Cells["PreK9DaycareCostColumn"];
                    preK9DaycareComboBoxCell.ReadOnly = false;
                }
                else
                {
                    DataGridViewComboBoxCell preK9DaycareComboBoxCell = (DataGridViewComboBoxCell)dataGridView1.Rows[index].Cells["PreK9DaycareCostColumn"];
                    preK9DaycareComboBoxCell.ReadOnly = true;
                }

                if (training.PreK9DaycareCost != null)
                {
                    dataGridView1.Rows[index].Cells["PreK9DaycareCostColumn"].Value = training.PreK9DaycareCost.CostId;
                }

                dataGridView1.Rows[index].Cells["TrainingIdColumn"].Value = training.TrainingId;
            }
        }