/// <summary> /// Delete the given Resource from the database /// </summary> public virtual void Delete(Model.Resource delResource) { try { Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, delResource); //Begin Checks if (!Exists(delResource)) { throw new BusinessException(string.Format("There is no Resource with this id. ({0})", delResource)); } DataAccess.Resources resources = new DataAccess.Resources(); resources.Delete(delResource); } catch (DalForeignKeyException ex_fk) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex_fk, delResource); throw new BusinessException(string.Format("The Resource is still used by {0}", ex_fk.Table), ex_fk); } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, delResource); throw; } }
/// <summary> /// Equals function to compare class /// </summary> public virtual bool Exists(Int32 id) { try { DataAccess.Resources resources = new DataAccess.Resources(); return(resources.GetById(id) != null); } catch (Exception ex) { Trace.WriteError("{0}", Trace.GetMethodName(), CLASSNAME, ex, id); throw; } }
/// <summary> /// Get a Resource by id from the database /// </summary> public virtual Model.Resource GetById(Int32 id) { try { DataAccess.Resources resources = new DataAccess.Resources(); Model.Resource result = resources.GetById(id); return(result); } catch (Exception ex) { Trace.WriteError("{0}", Trace.GetMethodName(), CLASSNAME, ex, id); throw; } }
public List <Model.Resource> GetByCode(string code) { try { DataAccess.Resources resources = new DataAccess.Resources(); List <Model.Resource> result = resources.GetByCode(code); return(result); } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, code); throw; } }
/// <summary> /// Get all Resource records from the database /// </summary> public virtual List <Model.Resource> GetAll() { try { DataAccess.Resources resources = new DataAccess.Resources(); List <Model.Resource> result = resources.GetAll(); return(result); } catch (Exception ex) { Trace.WriteError("()", Trace.GetMethodName(), CLASSNAME, ex); throw; } }
/// <summary> /// Modify only the specified properties of the Resource /// specified by: /// </summary> /// <param name="id">PK</param> /// <param name="propValues">Properties to change</param> public virtual void Modify(Int32 id, params KeyValuePair <string, object>[] propValues) { try { Trace.WriteInformation("({0}, {1})", Trace.GetMethodName(), CLASSNAME, id, string.Join(",", propValues)); DataAccess.Resources resources = new DataAccess.Resources(); resources.Modify( id, propValues); return; } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, id); throw; } }
/// <summary> /// Add a new Resource to the database /// </summary> public virtual Int32 Add(Model.Resource newResource) { try { Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, newResource); CheckConstraints(newResource); DataAccess.Resources resources = new DataAccess.Resources(); return(resources.Add(newResource)); } catch (DalForeignKeyException ex_fk) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex_fk, newResource); 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, newResource); throw; } }
/// <summary> /// Modify the given Resource in the database /// </summary> public virtual void Modify(Model.Resource modifiedResource) { try { Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, modifiedResource); //Begin Checks CheckConstraints(modifiedResource); if (!Exists(modifiedResource)) { throw new BusinessException(string.Format("There is no Resource with this id. ({0})", modifiedResource)); } DataAccess.Resources resources = new DataAccess.Resources(); resources.Modify(modifiedResource); } catch (Exception ex) { Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, modifiedResource); throw; } }