public void Can_get_existing_cost_by_id() { ICostRepository repository = new CostRepository(); var fromDb = repository.GetById(_costs[1].CostId); Assert.IsNotNull(fromDb); Assert.AreNotSame(_costs[1], fromDb); Assert.AreEqual(_costs[1].CostValue, fromDb.CostValue); }
private void DeleteInitialData() { ICostRepository repository = new CostRepository(); foreach (var cost in _costs) { Cost fromDb = repository.GetById(cost.CostId); if (fromDb != null) { repository.Remove(cost); } } }
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); } } }
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); } } }
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.IsCurrentCellDirty) { if (dirtyObjectsMap.Keys.Contains(e.RowIndex)) { dirtyObjectsMap.Remove(e.RowIndex); } PickupDropoff pickupDropoff = new PickupDropoff(); DateTime date = (DateTime)dataGridView1.Rows[e.RowIndex].Cells["DateColumn"].Value; pickupDropoff.Date = date; string dogId = (string)dataGridView1.Rows[e.RowIndex].Cells["DogNameColumn"].Value; DogRepository dogRepository = new DogRepository(); if (dogId != null) { Dog dog = dogRepository.GetById(dogId); pickupDropoff.Dog = dog; } CostRepository costRepository = new CostRepository(); string pickupCostId = (string)dataGridView1.Rows[e.RowIndex].Cells["PickupCostColumn"].Value; if (pickupCostId != null) { Cost cost = costRepository.GetById(pickupCostId); pickupDropoff.PickupCost = cost; } string dropoffCostId = (string)dataGridView1.Rows[e.RowIndex].Cells["DropoffCostColumn"].Value; if (dropoffCostId != null) { Cost cost = costRepository.GetById(dropoffCostId); pickupDropoff.DropoffCost = cost; } pickupDropoff.User = user; string pickupDropoffId = (string)dataGridView1.Rows[e.RowIndex].Cells["PickupDropoffIdColumn"].Value; pickupDropoff.PickupDropoffId = pickupDropoffId; // Add object to dirty objects map. dirtyObjectsMap.Add(e.RowIndex, pickupDropoff); // 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, pickupDropoff); } } }