/// <summary> /// Add a new HistoryKey to the database /// </summary> public virtual void Add(Model.HistoryKey newHistoryKey) { try { Trace.WriteVerbose("({0})", "Add", CLASSNAME, newHistoryKey.ToString()); var helper = Database.GetDbHelper(); int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Add, helper.CreateInputParam("@HistoryKey", newHistoryKey.HistoryKey), helper.CreateInputParam("@ShowInClient", newHistoryKey.ShowInClient), helper.CreateInputParam("@SaveInDatabase", newHistoryKey.SaveInDatabase), helper.CreateInputParam("@TraceLevel", newHistoryKey.TraceLevel)); if (recordsAffected == 0) { throw new DalNothingUpdatedException("Unable to add HistoryKey with HistoryKey={0}", newHistoryKey); } return; } catch (Exception ex) { Trace.WriteError("({0})", "Add", CLASSNAME, ex, newHistoryKey.ToString()); throw DbHelper.TranslateException(ex); } }
/// <summary> /// Delete the given HistoryKey from the database /// </summary> public virtual void Delete(Model.HistoryKey delHistoryKey) { try { Trace.WriteInformation("({0})", "Delete", CLASSNAME, delHistoryKey); //Begin Checks if (!Exists(delHistoryKey)) { throw new BusinessException(string.Format("There is no HistoryKey with this id. ({0})", delHistoryKey)); } DataAccess.HistoryKeys historyKeys = new DataAccess.HistoryKeys(); historyKeys.Delete(delHistoryKey); } catch (DalForeignKeyException ex_fk) { Trace.WriteError("({0})", "Delete", CLASSNAME, ex_fk, delHistoryKey); throw new BusinessException(string.Format("The HistoryKey is still used by {0}", ex_fk.Table), ex_fk); } catch (Exception ex) { Trace.WriteError("({0})", "Delete", CLASSNAME, ex, delHistoryKey); throw; } }
/// <summary> /// Get a HistoryKey by id from the database /// </summary> public virtual Model.HistoryKey GetById(String historyKey) { DbDataReader reader = null; try { var helper = Database.GetDbHelper(); reader = helper.ExecuteSPReader(_storedProcedure_GetById, helper.CreateInputParam("@HistoryKey", historyKey)); Model.HistoryKey result = null; if (reader.Read()) { result = CreateHistoryKey(reader); } return(result); } catch (Exception ex) { Trace.WriteError("{0}", "GetById", CLASSNAME, ex, historyKey); throw DbHelper.TranslateException(ex); } finally { reader?.Close(); } }
/// <summary> /// Equals function to compare class /// </summary> public virtual bool Exists(Model.HistoryKey historyKey) { try { return(this.GetById(historyKey.HistoryKey) != null); } catch (Exception ex) { Trace.WriteError("({0})", "Exists", CLASSNAME, ex, historyKey); throw; } }
/// <summary> /// Get a HistoryKey by id from the database /// </summary> public virtual Model.HistoryKey GetById(String historyKey) { try { DataAccess.HistoryKeys historyKeys = new DataAccess.HistoryKeys(); Model.HistoryKey result = historyKeys.GetById(historyKey); return(result); } catch (Exception ex) { Trace.WriteError("{0}", "GetById", CLASSNAME, ex, historyKey); throw; } }
/// <summary> /// Delete the given HistoryKey from the database /// </summary> public virtual void Delete(Model.HistoryKey historyKey) { try { Trace.WriteVerbose("({0})", "Delete", CLASSNAME, historyKey.ToString()); var helper = Database.GetDbHelper(); helper.ExecuteSPNonQuery(_storedProcedure_Delete, helper.CreateInputParam("@HistoryKey", historyKey.HistoryKey)); } catch (Exception ex) { Trace.WriteError("({0})", "Delete", CLASSNAME, ex, historyKey.ToString()); throw DbHelper.TranslateException(ex); } }
/// <summary> /// Create a Model.HistoryKey /// </summary> protected virtual Model.HistoryKey CreateHistoryKey(DbDataReader reader) { try { Model.HistoryKey result = new Model.HistoryKey( (String)reader["HistoryKey"], (Boolean)reader["ShowInClient"], (Boolean)reader["SaveInDatabase"], (String)reader["TraceLevel"] ); return(result); } catch (Exception ex) { Trace.WriteError("", "CreateHistoryKey", CLASSNAME, ex); throw DbHelper.TranslateException(ex); } }
/// <summary> /// Add a new HistoryKey to the database /// </summary> public virtual void Add(Model.HistoryKey newHistoryKey) { try { Trace.WriteInformation("({0})", "Add", CLASSNAME, newHistoryKey); CheckConstraints(newHistoryKey); DataAccess.HistoryKeys historyKeys = new DataAccess.HistoryKeys(); historyKeys.Add(newHistoryKey); } catch (DalForeignKeyException ex_fk) { Trace.WriteError("({0})", "Add", CLASSNAME, ex_fk, newHistoryKey); 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, newHistoryKey); throw; } }
/// <summary> /// Check Datafield constraints /// </summary> protected virtual void CheckConstraints(Model.HistoryKey historyKey) { //Range checks, etc checks go here if (historyKey.HistoryKey == null) { throw new BusinessException(string.Format("HistoryKey may not be NULL. ({0})", historyKey.HistoryKey)); } if (historyKey.HistoryKey.Length > 100) { throw new BusinessException(string.Format("HistoryKey may not be longer than 100 characters. ({0})", historyKey.HistoryKey)); } if (historyKey.TraceLevel == null) { throw new BusinessException(string.Format("TraceLevel may not be NULL. ({0})", historyKey.TraceLevel)); } if (historyKey.TraceLevel.Length > 100) { throw new BusinessException(string.Format("TraceLevel may not be longer than 100 characters. ({0})", historyKey.TraceLevel)); } }
/// <summary> /// Modify the given HistoryKey in the database /// </summary> public virtual void Modify(Model.HistoryKey modifiedHistoryKey) { try { Trace.WriteInformation("({0})", "Modify", CLASSNAME, modifiedHistoryKey); //Begin Checks CheckConstraints(modifiedHistoryKey); if (!Exists(modifiedHistoryKey)) { throw new BusinessException(string.Format("There is no HistoryKey with this id. ({0})", modifiedHistoryKey)); } DataAccess.HistoryKeys historyKeys = new DataAccess.HistoryKeys(); historyKeys.Modify(modifiedHistoryKey); } catch (Exception ex) { Trace.WriteError("({0})", "Modify", CLASSNAME, ex, modifiedHistoryKey); throw; } }
/// <summary> /// Modify the given HistoryKey in the database /// </summary> public virtual void Modify(Model.HistoryKey modifiedHistoryKey) { try { Trace.WriteVerbose("({0})", "Modify", CLASSNAME, modifiedHistoryKey.ToString()); var helper = Database.GetDbHelper(); int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Modify, helper.CreateInputParam("@HistoryKey", modifiedHistoryKey.HistoryKey), helper.CreateInputParam("@ShowInClient", modifiedHistoryKey.ShowInClient), helper.CreateInputParam("@SaveInDatabase", modifiedHistoryKey.SaveInDatabase), helper.CreateInputParam("@TraceLevel", modifiedHistoryKey.TraceLevel)); if (recordsAffected == 0) { throw new DalNothingUpdatedException("No records were updated (Table: HistoryKeys). HistoryKey=" + modifiedHistoryKey.ToString()); } } catch (Exception ex) { Trace.WriteError("({0})", "Modify", CLASSNAME, ex, modifiedHistoryKey.ToString()); throw DbHelper.TranslateException(ex); } }