/// <summary> /// Justin Pennington /// Created: 2015/02/14 /// Archives an event type record /// </summary> /// <param name="eventTypeToArchive">The EventType object to be archived</param> /// <returns>returns number of rows affected</returns> public static int DeleteEventType(EventType eventTypeToArchive) { var conn = DatabaseConnection.GetDatabaseConnection(); var cmdText = "spArchiveEventType"; var cmd = new SqlCommand(cmdText, conn); var rowsAffected = 0; cmd.CommandType = CommandType.StoredProcedure; //Set up parameters for EventType cmd.Parameters.AddWithValue("@EventTypeID", eventTypeToArchive.EventTypeID); try { conn.Open(); rowsAffected = cmd.ExecuteNonQuery(); if (rowsAffected == 0) { throw new ApplicationException("Concurrency Violation"); } } catch (Exception) { throw; } finally { conn.Close(); } return rowsAffected; }
/// <summary> /// Bryan Hurst /// Created: 2015/05/02 /// /// Deletes the test EventType object from the database /// </summary> /// <param name="TestEventType">The test EventType object added to the database previously</param> /// <returns>An int reflecting the number of rows affected</returns> public static int DeleteEventTypeTest(EventType TestEventType) { var conn = DatabaseConnection.GetDatabaseConnection(); var cmdText = "spDeleteTestEventType"; var cmd = new SqlCommand(cmdText, conn); var rowsAffected = 0; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@EventName", TestEventType.EventName); try { conn.Open(); rowsAffected = cmd.ExecuteNonQuery(); if (rowsAffected == 0) { throw new ApplicationException("Concurrency Violation"); } } catch (Exception) { throw; } finally { conn.Close(); } return rowsAffected; // needs to be rows affected }
public void DeleteEventType_Valid() { setup(); EventTypeAccessor.AddEventType("Test"); eventTypeToTest = getEventTypeID(list); Assert.AreEqual(1, EventTypeAccessor.DeleteEventType(eventTypeToTest)); TestCleanupAccessor.DeleteEventTypeTest(eventTypeToTest); }
public void RetrieveEventType_Test() { string eventTypeID = "100"; EventType expected = new EventType { EventTypeID = 100, EventName = "Boat Ride" }; EventManager myManager = new EventManager(); var result = myManager.RetrieveEventType(eventTypeID); Assert.AreEqual(expected.EventName, result.EventName, "EventName do not match"); Assert.AreEqual(expected.EventTypeID, result.EventTypeID, "EventTypeID does not match"); }
/// <summary> /// Justin Pennington /// Created: 2015/02/14 /// Gets an eventTypeID, retrieves data from databases /// </summary> /// <param name="eventTypeID">String containing the EventTypeID matching a specific EventType record/object</param> /// <returns>Returns an EventType object</returns> public static EventType GetEventType(string eventTypeID) { EventType theEventType = new EventType(); // set up the database call var conn = DatabaseConnection.GetDatabaseConnection(); string cmdText = "spSelectEventType"; var cmd = new SqlCommand(cmdText, conn); cmd.Parameters.AddWithValue("@EventTypeID", eventTypeID); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows == true) { theEventType.EventTypeID = reader.GetInt32(0); theEventType.EventName = reader.GetString(1); } else { var ax = new ApplicationException("Data not found!"); throw ax; } } catch (Exception) { throw; } finally { conn.Close(); } return theEventType; }
/// <summary> /// Justin Pennington /// Created: 2015/02/14 /// /// Updates an EventType object and database record /// </summary> /// </summary> /// <param name="oldEventType">The EventType object to be updated</param> /// <param name="newEventType">The EventType object with the updated changes</param> /// <returns>Returns the number of rows affected (should be 1)</returns> public static int UpdateEventType(EventType oldEventType, EventType newEventType) { var conn = DatabaseConnection.GetDatabaseConnection(); var cmdText = "spUpdateEventType"; var cmd = new SqlCommand(cmdText, conn); cmd.CommandType = CommandType.StoredProcedure; var rowsAffected = 0; // set command type to stored procedure and add parameters cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@EventName", newEventType.EventName); cmd.Parameters.AddWithValue("@originalEventTypeID",oldEventType.EventTypeID); cmd.Parameters.AddWithValue("@originalEventName", oldEventType.EventName); try { conn.Open(); rowsAffected = cmd.ExecuteNonQuery(); if (rowsAffected == 0) { throw new ApplicationException("Concurrency Violation"); } } catch (Exception) { throw; } finally { conn.Close(); } return rowsAffected; }
/// <summary> /// Justin Pennington /// Created: 2015/02/14 /// /// Retrieves all EventTypes. /// Makes a List of EventTypes, /// </summary> /// <returns> Returns the List of EventTypes</returns> public static List<EventType> GetEventTypeList() { var EventTypeList = new List<EventType>(); // set up the database call var conn = DatabaseConnection.GetDatabaseConnection(); string query = "spSelectAllEventTypes"; var cmd = new SqlCommand(query, conn); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { var currentEvent = new EventType(); currentEvent.EventTypeID = (int)reader.GetValue(0); currentEvent.EventName = reader.GetString(1); EventTypeList.Add(currentEvent); } } else { var ax = new ApplicationException("Event Types not found!"); throw ax; } } catch (Exception) { throw; } finally { conn.Close(); } return EventTypeList; }
/// <summary> /// Matt Lapka /// Created: 2015/02/08 /// Edit an EventType object ///</summary> ///<returns>result of adding the eventtype</returns> public EventResult EditEventType(EventType oldEventType, EventType newEventType) { try { if (EventTypeAccessor.UpdateEventType(oldEventType, newEventType) == 1) { //update cache DataCache._currentEventTypeList = EventTypeAccessor.GetEventTypeList(); DataCache._EventTypeListTime = DateTime.Now; DataCache._currentEventList = EventAccessor.GetEventList(); DataCache._EventListTime = DateTime.Now; return EventResult.Success; } return EventResult.NotChanged; } catch (ApplicationException ex) { return ex.Message == "Concurrency Violation" ? EventResult.ChangedByOtherUser : EventResult.DatabaseError; } catch (Exception) { return EventResult.DatabaseError; } }