/// <summary>
        /// Delete the given ApplicationSettingsCategory from the database
        /// </summary>
        public virtual void Delete(Model.ApplicationSettingsCategory delApplicationSettingsCategory)
        {
            try
            {
                Trace.WriteInformation("({0})", "Delete", CLASSNAME, delApplicationSettingsCategory);

                //Begin Checks
                if (!Exists(delApplicationSettingsCategory))
                {
                    throw new BusinessException(string.Format("There is no ApplicationSettingsCategory with this id. ({0})", delApplicationSettingsCategory));
                }

                DataAccess.ApplicationSettingsCategories applicationSettingsCategories = new DataAccess.ApplicationSettingsCategories();
                applicationSettingsCategories.Delete(delApplicationSettingsCategory);
            }
            catch (DalForeignKeyException ex_fk)
            {
                Trace.WriteError("({0})", "Delete", CLASSNAME, ex_fk, delApplicationSettingsCategory);
                throw new BusinessException(string.Format("The ApplicationSettingsCategory is still used by {0}", ex_fk.Table), ex_fk);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", "Delete", CLASSNAME, ex, delApplicationSettingsCategory);
                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Add a new ApplicationSettingsCategory to the database
        /// </summary>
        public virtual void Add(Model.ApplicationSettingsCategory newApplicationSettingsCategory)
        {
            try
            {
                Trace.WriteVerbose("({0})", "Add", CLASSNAME, newApplicationSettingsCategory.ToString());
                var helper = Database.GetDbHelper();


                int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Add,
                                                               helper.CreateInputParam("@ApplicationSettingsCategoryId", newApplicationSettingsCategory.ApplicationSettingsCategoryId),
                                                               helper.CreateInputParam("@Name", newApplicationSettingsCategory.Name),
                                                               helper.CreateInputParam("@Description", newApplicationSettingsCategory.Description));

                if (recordsAffected == 0)
                {
                    throw new DalNothingUpdatedException("Unable to add ApplicationSettingsCategory with ApplicationSettingsCategoryId={0}", newApplicationSettingsCategory);
                }

                return;
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", "Add", CLASSNAME, ex, newApplicationSettingsCategory.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Get a ApplicationSettingsCategory by id from the database
        /// </summary>
        public virtual Model.ApplicationSettingsCategory GetById(Int32 applicationSettingsCategoryId)
        {
            DbDataReader reader = null;

            try
            {
                var helper = Database.GetDbHelper();

                reader = helper.ExecuteSPReader(_storedProcedure_GetById,
                                                helper.CreateInputParam("@ApplicationSettingsCategoryId", applicationSettingsCategoryId));

                Model.ApplicationSettingsCategory result = null;

                if (reader.Read())
                {
                    result = CreateApplicationSettingsCategory(reader);
                }

                return(result);
            }
            catch (Exception ex)
            {
                Trace.WriteError("{0}", "GetById", CLASSNAME, ex, applicationSettingsCategoryId);
                throw DbHelper.TranslateException(ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
 /// <summary>
 /// Equals function to compare class
 /// </summary>
 public virtual bool Exists(Model.ApplicationSettingsCategory applicationSettingsCategory)
 {
     try
     {
         return(this.GetById(applicationSettingsCategory.ApplicationSettingsCategoryId) != null);
     }
     catch (Exception ex)
     {
         Trace.WriteError("({0})", "Exists", CLASSNAME, ex, applicationSettingsCategory);
         throw;
     }
 }
 /// <summary>
 /// Get a ApplicationSettingsCategory by id from the database
 /// </summary>
 public virtual Model.ApplicationSettingsCategory GetById(Int32 applicationSettingsCategoryId)
 {
     try
     {
         DataAccess.ApplicationSettingsCategories applicationSettingsCategories = new DataAccess.ApplicationSettingsCategories();
         Model.ApplicationSettingsCategory        result = applicationSettingsCategories.GetById(applicationSettingsCategoryId);
         return(result);
     }
     catch (Exception ex)
     {
         Trace.WriteError("{0}", "GetById", CLASSNAME, ex, applicationSettingsCategoryId);
         throw;
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Delete the given ApplicationSettingsCategory from the database
        /// </summary>
        public virtual void Delete(Model.ApplicationSettingsCategory applicationSettingsCategory)
        {
            try
            {
                Trace.WriteVerbose("({0})", "Delete", CLASSNAME, applicationSettingsCategory.ToString());

                var helper = Database.GetDbHelper();
                helper.ExecuteSPNonQuery(_storedProcedure_Delete,
                                         helper.CreateInputParam("@ApplicationSettingsCategoryId", applicationSettingsCategory.ApplicationSettingsCategoryId));
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", "Delete", CLASSNAME, ex, applicationSettingsCategory.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Create a Model.ApplicationSettingsCategory
 /// </summary>
 protected virtual Model.ApplicationSettingsCategory CreateApplicationSettingsCategory(DbDataReader reader)
 {
     try
     {
         Model.ApplicationSettingsCategory result = new Model.ApplicationSettingsCategory(
             (Int32)reader["ApplicationSettingsCategoryId"],
             (String)reader["Name"],
             (String)reader["Description"]
             );
         return(result);
     }
     catch (Exception ex)
     {
         Trace.WriteError("", "CreateApplicationSettingsCategory", CLASSNAME, ex);
         throw DbHelper.TranslateException(ex);
     }
 }
        /// <summary>
        /// Add a new ApplicationSettingsCategory to the database
        /// </summary>
        public virtual void Add(Model.ApplicationSettingsCategory newApplicationSettingsCategory)
        {
            try
            {
                Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, newApplicationSettingsCategory);

                CheckConstraints(newApplicationSettingsCategory);
                DataAccess.ApplicationSettingsCategories applicationSettingsCategories = new DataAccess.ApplicationSettingsCategories();

                applicationSettingsCategories.Add(newApplicationSettingsCategory);
            }
            catch (DalForeignKeyException ex_fk)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex_fk, newApplicationSettingsCategory);
                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, newApplicationSettingsCategory);
                throw;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Modify the given ApplicationSettingsCategory in the database
        /// </summary>
        public virtual void Modify(Model.ApplicationSettingsCategory modifiedApplicationSettingsCategory)
        {
            try
            {
                Trace.WriteVerbose("({0})", "Modify", CLASSNAME, modifiedApplicationSettingsCategory.ToString());

                var helper          = Database.GetDbHelper();
                int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Modify,
                                                               helper.CreateInputParam("@ApplicationSettingsCategoryId", modifiedApplicationSettingsCategory.ApplicationSettingsCategoryId),
                                                               helper.CreateInputParam("@Name", modifiedApplicationSettingsCategory.Name),
                                                               helper.CreateInputParam("@Description", modifiedApplicationSettingsCategory.Description));

                if (recordsAffected == 0)
                {
                    throw new DalNothingUpdatedException("No records were updated (Table: ApplicationSettingsCategories). ApplicationSettingsCategory=" + modifiedApplicationSettingsCategory.ToString());
                }
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", "Modify", CLASSNAME, ex, modifiedApplicationSettingsCategory.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }
        /// <summary>
        /// Check Datafield constraints
        /// </summary>
        protected virtual void CheckConstraints(Model.ApplicationSettingsCategory applicationSettingsCategory)
        {
            //Range checks, etc checks go here
            if (applicationSettingsCategory.Name == null)
            {
                throw new BusinessException(string.Format("Name may not be NULL. ({0})", applicationSettingsCategory.Name));
            }

            if (applicationSettingsCategory.Name.Length > 100)
            {
                throw new BusinessException(string.Format("Name may not be longer than 100 characters. ({0})", applicationSettingsCategory.Name));
            }

            if (applicationSettingsCategory.Description == null)
            {
                throw new BusinessException(string.Format("Description may not be NULL. ({0})", applicationSettingsCategory.Description));
            }

            if (applicationSettingsCategory.Description.Length > 100)
            {
                throw new BusinessException(string.Format("Description may not be longer than 100 characters. ({0})", applicationSettingsCategory.Description));
            }
        }
        /// <summary>
        /// Modify the given ApplicationSettingsCategory in the database
        /// </summary>
        public virtual void Modify(Model.ApplicationSettingsCategory modifiedApplicationSettingsCategory)
        {
            try
            {
                Trace.WriteInformation("({0})", "Modify", CLASSNAME, modifiedApplicationSettingsCategory);

                //Begin Checks
                CheckConstraints(modifiedApplicationSettingsCategory);

                if (!Exists(modifiedApplicationSettingsCategory))
                {
                    throw new BusinessException(string.Format("There is no ApplicationSettingsCategory with this id. ({0})", modifiedApplicationSettingsCategory));
                }

                DataAccess.ApplicationSettingsCategories applicationSettingsCategories = new DataAccess.ApplicationSettingsCategories();
                applicationSettingsCategories.Modify(modifiedApplicationSettingsCategory);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", "Modify", CLASSNAME, ex, modifiedApplicationSettingsCategory);
                throw;
            }
        }