public void Can_get_existing_costType_by_id() { ICostTypeRepository repository = new CostTypeRepository(); var fromDb = repository.GetById(_costTypes[1].CostTypeId); Assert.IsNotNull(fromDb); Assert.AreNotSame(_costTypes[1], fromDb); Assert.AreEqual(_costTypes[1].CostName, fromDb.CostName); }
private void DeleteInitialData() { ICostTypeRepository repository = new CostTypeRepository(); foreach (var costType in _costTypes) { CostType fromDb = repository.GetById(costType.CostTypeId); if (fromDb != null) { repository.Remove(costType); } } }
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.IsCurrentCellDirty) { if (dirtyObjectsMap.Keys.Contains(e.RowIndex)) { dirtyObjectsMap.Remove(e.RowIndex); } Training training = new Training(); DateTime date = (DateTime)dataGridView1.Rows[e.RowIndex].Cells["DateColumn"].Value; training.Date = date; string dogId = (string)dataGridView1.Rows[e.RowIndex].Cells["DogNameColumn"].Value; DogRepository dogRepository = new DogRepository(); if (dogId != null) { Dog dog = dogRepository.GetById(dogId); training.Dog = dog; } CostRepository costRepository = new CostRepository(); CostTypeRepository costTypeRepository = new CostTypeRepository(); string classTypeId = (string)dataGridView1.Rows[e.RowIndex].Cells["ClassColumn"].Value; if (classTypeId != null) { CostType costType = costTypeRepository.GetById(classTypeId); training.ClassType = costType; // If Class column value is Pre-K9, then enable Pre-K9 Daycare // Cost column. if (TRAINING_CLASS_PRE_K9.Equals(costType.CostName)) { DataGridViewComboBoxCell preK9DaycareComboBoxCell = (DataGridViewComboBoxCell)dataGridView1.Rows[e.RowIndex].Cells["PreK9DaycareCostColumn"]; preK9DaycareComboBoxCell.ReadOnly = false; } else { DataGridViewComboBoxCell preK9DaycareComboBoxCell = (DataGridViewComboBoxCell)dataGridView1.Rows[e.RowIndex].Cells["PreK9DaycareCostColumn"]; preK9DaycareComboBoxCell.ReadOnly = true; } // Has Class column combobox value changed? if (e.ColumnIndex == 3) { // Yes, Class column value has changed, so update // Class Cost column combobox with appropriate // values for new Class. // Sort the costs. IList<Cost> possibleCosts1 = costType.PossibleCosts; ArrayList.Adapter((IList)possibleCosts1).Sort(); DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)(dataGridView1.Rows[e.RowIndex].Cells["CostOfClassColumn"]); // Now that a class type has been selected, we can populate // the cost of class drop down box appropriately. cell.Value = null; cell.DataSource = null; if (cell.Items != null) { cell.Items.Clear(); } cell.DataSource = possibleCosts1; cell.DisplayMember = "CostValue"; cell.ValueMember = "CostId"; } } string classCostId = (string)dataGridView1.Rows[e.RowIndex].Cells["CostOfClassColumn"].Value; if (classCostId != null) { Cost cost = costRepository.GetById(classCostId); training.ClassCost = cost; } string preK9DaycareCostId = (string)dataGridView1.Rows[e.RowIndex].Cells["PreK9DaycareCostColumn"].Value; if (preK9DaycareCostId != null) { Cost cost = costRepository.GetById(preK9DaycareCostId); training.PreK9DaycareCost = cost; } training.User = user; string trainingId = (string)dataGridView1.Rows[e.RowIndex].Cells["TrainingIdColumn"].Value; training.TrainingId = trainingId; // Add object to dirty objects map. if (!dirtyObjectsMap.Keys.Contains(e.RowIndex)) { dirtyObjectsMap.Add(e.RowIndex, training); } // 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 = dataGridView1.Rows[e.RowIndex].Cells["SelectColumn"].Value; if (isSelected != null && (bool)isSelected) { deleteObjectsMap.Add(e.RowIndex, training); } } }