/// <summary> /// Using the configured SQL connection string, opens a connection to the database /// </summary> /// <returns>BoolTO with true value if read was successful, FaultTO otherwise</returns> public BoolTO canConnect() { BoolTO result = new BoolTO(); SqlConnection conn = new SqlConnection(_connectionString); try { conn.Open(); result.trueOrFalse = true; } catch (Exception exc) { result.fault = new FaultTO(exc); } finally { conn.Close(); } return result; }
/// <summary> /// Delete a session by it's ID and all the corresponding saved requests /// </summary> /// <param name="sessionId">The session ID to be deleted</param> /// <returns> /// BoolTO.trueOrFalse = true if successful. /// BoolTO.trueOrFalse = false if session ID not found. /// BoolTO.fault will be != null on error /// </returns> public BoolTO deleteSession(string sessionId) { if (String.IsNullOrEmpty(sessionId) || sessionId.Length != 24) // valid session IDs are 24 characters { throw new ArgumentException("Need a valid session ID!"); } BoolTO result = new BoolTO(); SqlConnection conn = new SqlConnection(); SqlTransaction tx = null; try { conn = getConnection(); tx = conn.BeginTransaction(); SqlDataAdapter adapter = buildDeleteSessionAdapter(sessionId, conn, tx); int i = adapter.DeleteCommand.ExecuteNonQuery(); tx.Commit(); if (i == 0) { result.trueOrFalse = false; // query succeeded but no rows were affected } else { result.trueOrFalse = true; } return result; } catch (Exception exc) { if (tx != null && tx.Connection != null) // transaction connection should be null if completed { tx.Rollback(); } result.fault = new FaultTO(exc); return result; } finally { conn.Close(); if (tx != null) { tx.Dispose(); } } }
/// <summary> /// Save a ApplicationSession object and it's requests /// </summary> /// <param name="session">The session object to save</param> /// <returns> /// BoolTO.trueOrFalse = true on success /// BoolTO.fault will be != null on error /// </returns> public BoolTO saveSession(ApplicationSession session) { BoolTO result = new BoolTO(); SqlConnection conn = new SqlConnection(); SqlTransaction tx = null; try { conn = getConnection(); tx = conn.BeginTransaction(); SqlDataAdapter adapter = buildInsertSessionAdapter(session, conn, tx); adapter.InsertCommand.ExecuteNonQuery(); foreach (ApplicationRequest request in session.Requests) { adapter = buildInsertRequestAdapter(request, conn, tx); adapter.InsertCommand.ExecuteNonQuery(); } tx.Commit(); result.trueOrFalse = true; return result; } catch (Exception exc) { if (tx != null && tx.Connection != null) // transaction connection should be null if completed { tx.Rollback(); } result.fault = new FaultTO(exc); return result; } finally { conn.Close(); if (tx != null) { tx.Dispose(); } } }
public BoolTO isValidStopCode(string stopCodeId) { BoolTO result = new BoolTO(); try { MdwsUtils.checkNullArgs(MdwsUtils.getArgsDictionary( System.Reflection.MethodInfo.GetCurrentMethod().GetParameters(), new List<object>() { stopCodeId })); result.trueOrFalse = new EncounterApi().isValidStopCode(_mySession.ConnectionSet.BaseConnection, stopCodeId); } catch (Exception exc) { result.fault = new FaultTO(exc); } return result; }
public BoolTO hasPermission(string uid, string permissionName) { BoolTO result = new BoolTO(); if (!(MdwsUtils.isAuthorizedConnection(mySession) == "OK")) { result.fault = new FaultTO("Connections not ready for operation", "Need to login?"); } else if (String.IsNullOrEmpty(uid)) { result.fault = new FaultTO("Empty UID"); } else if (String.IsNullOrEmpty(permissionName)) { result.fault = new FaultTO("Empty permission name"); } if (result.fault != null) { return result; } try { AbstractPermission p = new gov.va.medora.mdo.dao.vista.MenuOption(permissionName); bool f = User.hasPermission(mySession.ConnectionSet.BaseConnection, uid, p); result = new BoolTO(f); } catch (Exception exc) { result.fault = new FaultTO(exc); } return result; }