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