/// <summary> /// Add a new Material to the database /// </summary> public virtual Int32 Add(Model.Material newMaterial) { try { Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, newMaterial.ToString()); var helper = Database.GetDbHelper(); DbParameter IdParam = helper.CreateOutputParam("@Id", DbType.Int32); int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Add, IdParam, helper.CreateInputParam("@MaterialGroupId", newMaterial.MaterialGroupId), helper.CreateInputParam("@Code", newMaterial.Code), helper.CreateInputParam("@Description", newMaterial.Description)); if (recordsAffected == 0) { throw new DalNothingUpdatedException("Unable to add Material with Id={0}", newMaterial); } return((Int32)IdParam.Value); } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, newMaterial.ToString()); throw DbHelper.TranslateException(ex); } }
/// <summary> /// Delete the given Material from the database /// </summary> public virtual void Delete(Model.Material material) { try { Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, material.ToString()); var helper = Database.GetDbHelper(); helper.ExecuteSPNonQuery(_storedProcedure_Delete, helper.CreateInputParam("@Id", material.Id)); } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, material.ToString()); throw DbHelper.TranslateException(ex); } }
/// <summary> /// Modify the given Material in the database /// </summary> public virtual void Modify(Model.Material modifiedMaterial) { try { Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, modifiedMaterial.ToString()); var helper = Database.GetDbHelper(); int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Modify, helper.CreateInputParam("@Id", modifiedMaterial.Id), helper.CreateInputParam("@MaterialGroupId", modifiedMaterial.MaterialGroupId), helper.CreateInputParam("@Code", modifiedMaterial.Code), helper.CreateInputParam("@Description", modifiedMaterial.Description)); if (recordsAffected == 0) { throw new DalNothingUpdatedException("No records were updated (Table: Materials). Material=" + modifiedMaterial.ToString()); } } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, modifiedMaterial.ToString()); throw DbHelper.TranslateException(ex); } }