/// <summary> /// Creator: Ethan Murphy /// Created: 4/25/2020 /// Approver: Chuck Baxter 4/27/2020 /// /// Changes the active status of an animal prescription record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalPrescription">Record to be updated</param> /// <param name="active">Active status</param> /// <returns>Update successful</returns> public int ChangeAnimalPrescriptionRecordActive(AnimalPrescription animalPrescription, bool active) { int rows = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_activate_prescription_record", conn); if (!active) { cmd = new SqlCommand("sp_deactivate_prescription_record", conn); } cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@AnimalPrescriptionsID", animalPrescription.AnimalPrescriptionID); try { conn.Open(); rows = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(rows); }
/// <summary> /// Creator: Ethan Murphy /// Created: 4/25/2020 /// Approver: Chuck Baxter 4/27/2020 /// /// Activates an inactive animal prescription record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalPrescription">Record to be activated</param> /// <returns>Activate successful</returns> public bool ActivateAnimalPrescriptionRecord(AnimalPrescription animalPrescription) { try { return(_animalPrescriptionsAccessor.ChangeAnimalPrescriptionRecordActive(animalPrescription, true) == 1); } catch (Exception ex) { throw new ApplicationException("Record not activated", ex); } }
/// <summary> /// Creator: Ethan Murphy /// Created: 4/25/2020 /// Approver: Chuck Baxter 4/27/2020 /// /// Changes the active status of an animal prescription record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalPrescription">Record to be updated</param> /// <param name="active">Active status</param> /// <returns>Update successful</returns> public int ChangeAnimalPrescriptionRecordActive(AnimalPrescription animalPrescription, bool active) { int rows = 0; var foundRecord = AnimalPrescriptionVMs.Where( p => p.AnimalPrescriptionID == animalPrescription.AnimalPrescriptionID).FirstOrDefault(); if (foundRecord != null) { int foundIndex = AnimalPrescriptionVMs.IndexOf(foundRecord); foundRecord.Active = animalPrescription.Active; AnimalPrescriptionVMs[foundIndex] = foundRecord; if (AnimalPrescriptionVMs[foundIndex].Active == animalPrescription.Active) { rows = 1; } } return(rows); }
public void TestChangeAnimalPrescriptionActiveStatus() { // Arrange bool deactivateResult = false; bool activateResult = false; IAnimalPrescriptionManager manager = new AnimalPrescriptionsManager(_animalPrescriptionsAccessor); AnimalPrescription activeRecord = new AnimalPrescription() { AnimalPrescriptionID = 1 }; AnimalPrescription inActiveRecord = new AnimalPrescription() { AnimalPrescriptionID = 2 }; // Act deactivateResult = manager.DeactivateAnimalPrescriptionRecord(activeRecord); activateResult = manager.ActivateAnimalPrescriptionRecord(inActiveRecord); // Assert Assert.IsTrue(deactivateResult); Assert.IsTrue(activateResult); }