/// <summary> /// Add a new MaterialParameterValue to the database /// </summary> public virtual Int32 Add(Model.MaterialParameterValue newMaterialParameterValue) { try { Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, newMaterialParameterValue.ToString()); var helper = Database.GetDbHelper(); DbParameter IdParam = helper.CreateOutputParam("@Id", DbType.Int32); int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Add, IdParam, helper.CreateInputParam("@MaterialId", newMaterialParameterValue.MaterialId), helper.CreateInputParam("@MaterialParameterId", newMaterialParameterValue.MaterialParameterId), helper.CreateInputParam("@Value", newMaterialParameterValue.Value)); if (recordsAffected == 0) { throw new DalNothingUpdatedException("Unable to add MaterialParameterValue with Id={0}", newMaterialParameterValue); } return((Int32)IdParam.Value); } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, newMaterialParameterValue.ToString()); throw DbHelper.TranslateException(ex); } }
/// <summary> /// Delete the given MaterialParameterValue from the database /// </summary> public virtual void Delete(Model.MaterialParameterValue delMaterialParameterValue) { try { Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, delMaterialParameterValue); //Begin Checks if (!Exists(delMaterialParameterValue)) { throw new BusinessException(string.Format("There is no MaterialParameterValue with this id. ({0})", delMaterialParameterValue)); } DataAccess.MaterialParameterValues materialParameterValues = new DataAccess.MaterialParameterValues(); materialParameterValues.Delete(delMaterialParameterValue); } catch (DalForeignKeyException ex_fk) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex_fk, delMaterialParameterValue); throw new BusinessException(string.Format("The MaterialParameterValue is still used by {0}", ex_fk.Table), ex_fk); } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, delMaterialParameterValue); throw; } }
/// <summary> /// Get a MaterialParameterValue by id from the database /// </summary> public virtual Model.MaterialParameterValue GetById(Int32 id) { DbDataReader reader = null; try { var helper = Database.GetDbHelper(); reader = helper.ExecuteSPReader(_storedProcedure_GetById, helper.CreateInputParam("@Id", id)); Model.MaterialParameterValue result = null; if (reader.Read()) { result = CreateMaterialParameterValue(reader); } return(result); } catch (Exception ex) { Trace.WriteError("{0}", Trace.GetMethodName(), CLASSNAME, ex, id); throw DbHelper.TranslateException(ex); } finally { if (reader != null) { reader.Close(); } } }
/// <summary> /// Equals function to compare class /// </summary> public virtual bool Exists(Model.MaterialParameterValue materialParameterValue) { try { return(this.GetById(materialParameterValue.Id) != null); } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, materialParameterValue); throw; } }
/// <summary> /// Check Datafield constraints /// </summary> protected virtual void CheckConstraints(Model.MaterialParameterValue materialParameterValue) { //Range checks, etc checks go here if (materialParameterValue.Value == null) { throw new BusinessException(string.Format("Value may not be NULL. ({0})", materialParameterValue.Value)); } if (materialParameterValue.Value.Length > 50) { throw new BusinessException(string.Format("Value may not be longer than 50 characters. ({0})", materialParameterValue.Value)); } }
/// <summary> /// Get a MaterialParameterValue by id from the database /// </summary> public virtual Model.MaterialParameterValue GetById(Int32 id) { try { DataAccess.MaterialParameterValues materialParameterValues = new DataAccess.MaterialParameterValues(); Model.MaterialParameterValue result = materialParameterValues.GetById(id); return(result); } catch (Exception ex) { Trace.WriteError("{0}", Trace.GetMethodName(), CLASSNAME, ex, id); throw; } }
/// <summary> /// Delete the given MaterialParameterValue from the database /// </summary> public virtual void Delete(Model.MaterialParameterValue materialParameterValue) { try { Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, materialParameterValue.ToString()); var helper = Database.GetDbHelper(); helper.ExecuteSPNonQuery(_storedProcedure_Delete, helper.CreateInputParam("@Id", materialParameterValue.Id)); } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, materialParameterValue.ToString()); throw DbHelper.TranslateException(ex); } }
/// <summary> /// Create a Model.MaterialParameterValue /// </summary> protected virtual Model.MaterialParameterValue CreateMaterialParameterValue(DbDataReader reader) { try { Model.MaterialParameterValue result = new Model.MaterialParameterValue( (Int32)reader["Id"], (Int32)reader["MaterialId"], (Int32)reader["MaterialParameterId"], (String)reader["Value"] ); return(result); } catch (Exception ex) { Trace.WriteError("", Trace.GetMethodName(), CLASSNAME, ex); throw DbHelper.TranslateException(ex); } }
/// <summary> /// Add a new MaterialParameterValue to the database /// </summary> public virtual Int32 Add(Model.MaterialParameterValue newMaterialParameterValue) { try { Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, newMaterialParameterValue); CheckConstraints(newMaterialParameterValue); DataAccess.MaterialParameterValues materialParameterValues = new DataAccess.MaterialParameterValues(); return(materialParameterValues.Add(newMaterialParameterValue)); } catch (DalForeignKeyException ex_fk) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex_fk, newMaterialParameterValue); throw new BusinessException(string.Format("No related object found in {0}", ex_fk.Table), ex_fk); } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, newMaterialParameterValue); throw; } }
/// <summary> /// Modify the given MaterialParameterValue in the database /// </summary> public virtual void Modify(Model.MaterialParameterValue modifiedMaterialParameterValue) { try { Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, modifiedMaterialParameterValue); //Begin Checks CheckConstraints(modifiedMaterialParameterValue); if (!Exists(modifiedMaterialParameterValue)) { throw new BusinessException(string.Format("There is no MaterialParameterValue with this id. ({0})", modifiedMaterialParameterValue)); } DataAccess.MaterialParameterValues materialParameterValues = new DataAccess.MaterialParameterValues(); materialParameterValues.Modify(modifiedMaterialParameterValue); } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, modifiedMaterialParameterValue); throw; } }
/// <summary> /// Modify the given MaterialParameterValue in the database /// </summary> public virtual void Modify(Model.MaterialParameterValue modifiedMaterialParameterValue) { try { Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, modifiedMaterialParameterValue.ToString()); var helper = Database.GetDbHelper(); int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Modify, helper.CreateInputParam("@Id", modifiedMaterialParameterValue.Id), helper.CreateInputParam("@MaterialId", modifiedMaterialParameterValue.MaterialId), helper.CreateInputParam("@MaterialParameterId", modifiedMaterialParameterValue.MaterialParameterId), helper.CreateInputParam("@Value", modifiedMaterialParameterValue.Value)); if (recordsAffected == 0) { throw new DalNothingUpdatedException("No records were updated (Table: MaterialParameterValues). MaterialParameterValue=" + modifiedMaterialParameterValue.ToString()); } } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, modifiedMaterialParameterValue.ToString()); throw DbHelper.TranslateException(ex); } }