/// <summary> /// Add a new HistoryAction to the database /// </summary> public virtual Int64 Add(Model.HistoryAction newHistoryAction) { try { Trace.WriteVerbose("({0})", "Add", CLASSNAME, newHistoryAction.ToString()); var helper = Database.GetDbHelper(); DbParameter HistoryActionIdParam = helper.CreateOutputParam("@HistoryActionId", DbType.Int64); int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Add, HistoryActionIdParam, helper.CreateInputParam("@HistoryKey", newHistoryAction.HistoryKey), helper.CreateInputParam("@TimeStampUTC", newHistoryAction.TimeStampUTC), helper.CreateInputParam("@UserId", newHistoryAction.UserId.HasValue ? (object)newHistoryAction.UserId : DBNull.Value), helper.CreateInputParam("@ComputerId", newHistoryAction.ComputerId.HasValue ? (object)newHistoryAction.ComputerId : DBNull.Value), helper.CreateInputParam("@Parameters", newHistoryAction.Parameters != null ? (object)newHistoryAction.Parameters : DBNull.Value)); if (recordsAffected == 0) { throw new DalNothingUpdatedException("Unable to add HistoryAction with HistoryActionId={0}", newHistoryAction); } return((Int64)HistoryActionIdParam.Value); } catch (Exception ex) { Trace.WriteError("({0})", "Add", CLASSNAME, ex, newHistoryAction.ToString()); throw DbHelper.TranslateException(ex); } }
/// <summary> /// Modify the given HistoryAction in the database /// </summary> public virtual void Modify(Model.HistoryAction modifiedHistoryAction) { try { Trace.WriteVerbose("({0})", "Modify", CLASSNAME, modifiedHistoryAction.ToString()); var helper = Database.GetDbHelper(); int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Modify, helper.CreateInputParam("@HistoryActionId", modifiedHistoryAction.HistoryActionId), helper.CreateInputParam("@HistoryKey", modifiedHistoryAction.HistoryKey), helper.CreateInputParam("@TimeStampUTC", modifiedHistoryAction.TimeStampUTC), helper.CreateInputParam("@UserId", modifiedHistoryAction.UserId.HasValue ? (object)modifiedHistoryAction.UserId : DBNull.Value), helper.CreateInputParam("@ComputerId", modifiedHistoryAction.ComputerId.HasValue ? (object)modifiedHistoryAction.ComputerId : DBNull.Value), helper.CreateInputParam("@Parameters", modifiedHistoryAction.Parameters != null ? (object)modifiedHistoryAction.Parameters : DBNull.Value)); if (recordsAffected == 0) { throw new DalNothingUpdatedException("No records were updated (Table: HistoryActions). HistoryAction=" + modifiedHistoryAction.ToString()); } } catch (Exception ex) { Trace.WriteError("({0})", "Modify", CLASSNAME, ex, modifiedHistoryAction.ToString()); throw DbHelper.TranslateException(ex); } }
/// <summary> /// Delete the given HistoryAction from the database /// </summary> public virtual void Delete(Model.HistoryAction delHistoryAction) { try { Trace.WriteInformation("({0})", "Delete", CLASSNAME, delHistoryAction); //Begin Checks if (!Exists(delHistoryAction)) { throw new BusinessException(string.Format("There is no HistoryAction with this id. ({0})", delHistoryAction)); } DataAccess.HistoryActions historyActions = new DataAccess.HistoryActions(); historyActions.Delete(delHistoryAction); } catch (DalForeignKeyException ex_fk) { Trace.WriteError("({0})", "Delete", CLASSNAME, ex_fk, delHistoryAction); throw new BusinessException(string.Format("The HistoryAction is still used by {0}", ex_fk.Table), ex_fk); } catch (Exception ex) { Trace.WriteError("({0})", "Delete", CLASSNAME, ex, delHistoryAction); throw; } }
/// <summary> /// Get a HistoryAction by id from the database /// </summary> public virtual Model.HistoryAction GetById(Int64 historyActionId) { DbDataReader reader = null; try { var helper = Database.GetDbHelper(); reader = helper.ExecuteSPReader(_storedProcedure_GetById, helper.CreateInputParam("@HistoryActionId", historyActionId)); Model.HistoryAction result = null; if (reader.Read()) { result = CreateHistoryAction(reader); } return(result); } catch (Exception ex) { Trace.WriteError("{0}", "GetById", CLASSNAME, ex, historyActionId); throw DbHelper.TranslateException(ex); } finally { reader?.Close(); } }
/// <summary> /// Equals function to compare class /// </summary> public virtual bool Exists(Model.HistoryAction historyAction) { try { return(this.GetById(historyAction.HistoryActionId) != null); } catch (Exception ex) { Trace.WriteError("({0})", "Exists", CLASSNAME, ex, historyAction); throw; } }
/// <summary> /// Check Datafield constraints /// </summary> protected virtual void CheckConstraints(Model.HistoryAction historyAction) { //Range checks, etc checks go here if (historyAction.HistoryKey == null) { throw new BusinessException(string.Format("HistoryKey may not be NULL. ({0})", historyAction.HistoryKey)); } if (historyAction.HistoryKey.Length > 100) { throw new BusinessException(string.Format("HistoryKey may not be longer than 100 characters. ({0})", historyAction.HistoryKey)); } }
/// <summary> /// Get a HistoryAction by id from the database /// </summary> public virtual Model.HistoryAction GetById(Int64 historyActionId) { try { DataAccess.HistoryActions historyActions = new DataAccess.HistoryActions(); Model.HistoryAction result = historyActions.GetById(historyActionId); return(result); } catch (Exception ex) { Trace.WriteError("{0}", "GetById", CLASSNAME, ex, historyActionId); throw; } }
/// <summary> /// Delete the given HistoryAction from the database /// </summary> public virtual void Delete(Model.HistoryAction historyAction) { try { Trace.WriteVerbose("({0})", "Delete", CLASSNAME, historyAction.ToString()); var helper = Database.GetDbHelper(); helper.ExecuteSPNonQuery(_storedProcedure_Delete, helper.CreateInputParam("@HistoryActionId", historyAction.HistoryActionId)); } catch (Exception ex) { Trace.WriteError("({0})", "Delete", CLASSNAME, ex, historyAction.ToString()); throw DbHelper.TranslateException(ex); } }
/// <summary> /// Create a Model.HistoryAction /// </summary> protected virtual Model.HistoryAction CreateHistoryAction(DbDataReader reader) { try { Model.HistoryAction result = new Model.HistoryAction( (Int64)reader["HistoryActionId"], (String)reader["HistoryKey"], (DateTime)reader["TimeStampUTC"], reader["UserId"] != DBNull.Value ? (Int32?)reader["UserId"] : null, reader["ComputerId"] != DBNull.Value ? (Int32?)reader["ComputerId"] : null, reader["Parameters"] != DBNull.Value ? (String)reader["Parameters"] : null ); return(result); } catch (Exception ex) { Trace.WriteError("", "CreateHistoryAction", CLASSNAME, ex); throw DbHelper.TranslateException(ex); } }
/// <summary> /// Add a new HistoryAction to the database /// </summary> public virtual Int64 Add(Model.HistoryAction newHistoryAction) { try { Trace.WriteInformation("({0})", "Add", CLASSNAME, newHistoryAction); CheckConstraints(newHistoryAction); DataAccess.HistoryActions historyActions = new DataAccess.HistoryActions(); return(historyActions.Add(newHistoryAction)); } catch (DalForeignKeyException ex_fk) { Trace.WriteError("({0})", "Add", CLASSNAME, ex_fk, newHistoryAction); throw new BusinessException(string.Format("No related object found in {0}", ex_fk.Table), ex_fk); } catch (Exception ex) { Trace.WriteError("({0})", "Add", CLASSNAME, ex, newHistoryAction); throw; } }
/// <summary> /// Modify the given HistoryAction in the database /// </summary> public virtual void Modify(Model.HistoryAction modifiedHistoryAction) { try { Trace.WriteInformation("({0})", "Modify", CLASSNAME, modifiedHistoryAction); //Begin Checks CheckConstraints(modifiedHistoryAction); if (!Exists(modifiedHistoryAction)) { throw new BusinessException(string.Format("There is no HistoryAction with this id. ({0})", modifiedHistoryAction)); } DataAccess.HistoryActions historyActions = new DataAccess.HistoryActions(); historyActions.Modify(modifiedHistoryAction); } catch (Exception ex) { Trace.WriteError("({0})", "Modify", CLASSNAME, ex, modifiedHistoryAction); throw; } }