/// <summary> /// Creator: Chuck Baxter /// Created: 4/16/2020 /// Approver: Ethan Murphy, 4/16/2020 /// /// Saving a new animal activity type /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="sender"></param> /// <param name="e"></param> private void btnCreateActivtyTypeSave_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrEmpty(txtActivityName.Text)) { MessageBox.Show("Please enter the name of the new activity type."); return; } if (String.IsNullOrEmpty(txtActivityNotes.Text)) { MessageBox.Show("Please enter the description of the new activity type."); return; } AnimalActivityType animalActivityType = new AnimalActivityType(); animalActivityType.ActivityTypeId = txtActivityName.Text; animalActivityType.Description = txtActivityNotes.Text; try { if (_activityManager.AddAnimalActivityType(animalActivityType)) { WPFErrorHandler.SuccessMessage("Activity Type Successfully Added"); cmbActivityType.ItemsSource = _activityManager.RetrieveAllAnimalActivityTypes().Select(a => a.ActivityTypeId); cmbActivityType.SelectedIndex = 0; canActivityTypes.Visibility = Visibility.Hidden; } } catch (Exception ex) { WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + ex.InnerException.Message); canActivityTypes.Visibility = Visibility.Hidden; } }
/// <summary> /// Creator: Chuck Baxter /// Created: 4/16/2020 /// Approver: Ethan Murphy, 4/16/2020 /// /// Inserts an animal activity type into the existing list /// of fake animal activity type records /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalActivityType"></param> /// <returns></returns> public int InsertAnimalActivityType(AnimalActivityType animalActivityType) { int startingLength = activityTypes.Count; activityTypes.Add(animalActivityType); return(activityTypes.Count - startingLength); }
/// <summary> /// Creator: Chuck Baxter /// Created: 4/16/2020 /// Approver: Ethan Murphy, 4/16/2020 /// /// Deletes an existing animal activity type record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalActivityType"></param> /// <returns></returns> public int DeleteAnimalActivityType(AnimalActivityType animalActivityType) { int rows = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_delete_animal_activity_type", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@AnimalActivityTypeID", animalActivityType.ActivityTypeId); try { conn.Open(); rows = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(rows); }
/// <summary> /// Creator: Chuck Baxter /// Created: 4/16/2020 /// Approver: Ethan Murphy, 4/16/2020 /// /// looks for a matching activity type id from the params in the collection to delete /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> public int DeleteAnimalActivityType(AnimalActivityType animalActivityType) { int recordsUpdated = 0; if (animalActivityType.ActivityTypeId == "Feeding") { recordsUpdated = 1; } return(recordsUpdated); }
/// <summary> /// Creator: Chuck Baxter /// Created: 4/16/2020 /// Approver: Ethan Murphy, 4/16/2020 /// /// looks for a matching activity type id from the params in the collection to update /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="oldAnimalActivityType"></param> /// <param name="newAnimalActivityType"></param> /// <returns></returns> public int UpdateAnimalActivityType(AnimalActivityType oldAnimalActivityType, AnimalActivityType newAnimalActivityType) { int recordsUpdated = 0; if (oldAnimalActivityType.ActivityTypeId == "Feeding") { recordsUpdated = 1; } return(recordsUpdated); }
/// <summary> /// Creator: Chuck Baxter /// Created: 4/16/2020 /// Approver: Ethan Murphy, 4/16/2020 /// /// deletes an animal activity type record in the DB /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalActivityType"></param> /// <returns></returns> public bool DeleteAnimalActivityType(AnimalActivityType animalActivityType) { try { return(_activityAccessor.DeleteAnimalActivityType(animalActivityType) == 1); } catch (Exception ex) { throw new ApplicationException("Failed to delete record", ex); } }
/// <summary> /// Creator: Chuck Baxter /// Created: 4/16/2020 /// Approver: Ethan Murphy, 4/16/2020 /// /// updates an animal activity type record in the DB /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="oldAnimalActivityType"></param> /// <param name="newAnimalActivityType"></param> /// <returns></returns> public bool EditAnimalActivityType(AnimalActivityType oldAnimalActivityType, AnimalActivityType newAnimalActivityType) { try { return(_activityAccessor.UpdateAnimalActivityType(oldAnimalActivityType, newAnimalActivityType) == 1); } catch (Exception ex) { throw new ApplicationException("Failed to update record", ex); } }
/// <summary> /// Creator: Chuck Baxter /// Created: 4/16/2020 /// Approver: Ethan Murphy, 4/16/2020 /// /// Adds an animal activity type record to the DB /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalActivityType"></param> /// <returns></returns> public bool AddAnimalActivityType(AnimalActivityType animalActivityType) { try { return(_activityAccessor.InsertAnimalActivityType(animalActivityType) == 1); } catch (Exception ex) { throw new ApplicationException("Failed to add record", ex); } }
public void TestDeletingAnimalActivityTypeRecord() { // Arrange IAnimalActivityManager manager = new AnimalActivityManager(_fakeActivityAccessor); bool result = false; AnimalActivityType activityType = new AnimalActivityType() { ActivityTypeId = "Feeding", Description = "This is a description" }; // Act result = manager.AddAnimalActivityType(activityType); // Assert Assert.IsTrue(result); }
/// <summary> /// Creator: Chuck Baxter /// Created: 4/16/2020 /// Approver: Ethan Murphy, 4/16/2020 /// /// Deleting animal activity type /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks /// <param name="sender"></param> /// <param name="e"></param> private void btnDeleteActivtyTypeSave_Click(object sender, RoutedEventArgs e) { AnimalActivityType animalActivityType = new AnimalActivityType(); animalActivityType.ActivityTypeId = (string)cmbSelectActivityType.SelectedItem; try { if (_activityManager.DeleteAnimalActivityType(animalActivityType)) { WPFErrorHandler.SuccessMessage("Activity Type Successfully Deleted"); cmbActivityType.ItemsSource = _activityManager.RetrieveAllAnimalActivityTypes().Select(a => a.ActivityTypeId); cmbActivityType.SelectedIndex = 0; canActivityTypes.Visibility = Visibility.Hidden; } } catch (Exception ex) { WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + "Make sure you are not attempting to delete an activity type that has records." + "\n\n" + ex.InnerException.Message); canActivityTypes.Visibility = Visibility.Hidden; } }