예제 #1
0
        /// <summary>
        /// Add a new ApplicationSetting to the database
        /// </summary>
        public virtual void Add(Model.ApplicationSetting newApplicationSetting)
        {
            try
            {
                Trace.WriteVerbose("({0})", "Add", CLASSNAME, newApplicationSetting.ToString());
                var helper = Database.GetDbHelper();


                int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Add,
                                                               helper.CreateInputParam("@ApplicationSettingId", newApplicationSetting.ApplicationSettingId),
                                                               helper.CreateInputParam("@ApplicationSettingsCategoryId", newApplicationSetting.ApplicationSettingsCategoryId),
                                                               helper.CreateInputParam("@Name", newApplicationSetting.Name),
                                                               helper.CreateInputParam("@Description", newApplicationSetting.Description),
                                                               helper.CreateInputParam("@DataTypeId", newApplicationSetting.DataTypeId),
                                                               helper.CreateInputParam("@Value", newApplicationSetting.Value),
                                                               helper.CreateInputParam("@ListId", newApplicationSetting.ListId.HasValue ? (object)newApplicationSetting.ListId : DBNull.Value));

                if (recordsAffected == 0)
                {
                    throw new DalNothingUpdatedException("Unable to add ApplicationSetting with ApplicationSettingId={0}", newApplicationSetting);
                }

                return;
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", "Add", CLASSNAME, ex, newApplicationSetting.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }
예제 #2
0
        /// <summary>
        /// Modify the given ApplicationSetting in the database
        /// </summary>
        public virtual void Modify(Model.ApplicationSetting modifiedApplicationSetting)
        {
            try
            {
                Trace.WriteVerbose("({0})", "Modify", CLASSNAME, modifiedApplicationSetting.ToString());

                var helper          = Database.GetDbHelper();
                int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Modify,
                                                               helper.CreateInputParam("@ApplicationSettingId", modifiedApplicationSetting.ApplicationSettingId),
                                                               helper.CreateInputParam("@ApplicationSettingsCategoryId", modifiedApplicationSetting.ApplicationSettingsCategoryId),
                                                               helper.CreateInputParam("@Name", modifiedApplicationSetting.Name),
                                                               helper.CreateInputParam("@Description", modifiedApplicationSetting.Description),
                                                               helper.CreateInputParam("@DataTypeId", modifiedApplicationSetting.DataTypeId),
                                                               helper.CreateInputParam("@Value", modifiedApplicationSetting.Value),
                                                               helper.CreateInputParam("@ListId", modifiedApplicationSetting.ListId.HasValue ? (object)modifiedApplicationSetting.ListId : DBNull.Value));

                if (recordsAffected == 0)
                {
                    throw new DalNothingUpdatedException("No records were updated (Table: ApplicationSettings). ApplicationSetting=" + modifiedApplicationSetting.ToString());
                }
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", "Modify", CLASSNAME, ex, modifiedApplicationSetting.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }
        /// <summary>
        /// Delete the given ApplicationSetting from the database
        /// </summary>
        public virtual void Delete(Model.ApplicationSetting delApplicationSetting)
        {
            try
            {
                Trace.WriteInformation("({0})", "Delete", CLASSNAME, delApplicationSetting);

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

                DataAccess.ApplicationSettings applicationSettings = new DataAccess.ApplicationSettings();
                applicationSettings.Delete(delApplicationSetting);
            }
            catch (DalForeignKeyException ex_fk)
            {
                Trace.WriteError("({0})", "Delete", CLASSNAME, ex_fk, delApplicationSetting);
                throw new BusinessException(string.Format("The ApplicationSetting is still used by {0}", ex_fk.Table), ex_fk);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", "Delete", CLASSNAME, ex, delApplicationSetting);
                throw;
            }
        }
예제 #4
0
        /// <summary>
        /// Get a ApplicationSetting by id from the database
        /// </summary>
        public virtual Model.ApplicationSetting GetById(Int32 applicationSettingId)
        {
            DbDataReader reader = null;

            try
            {
                var helper = Database.GetDbHelper();

                reader = helper.ExecuteSPReader(_storedProcedure_GetById,
                                                helper.CreateInputParam("@ApplicationSettingId", applicationSettingId));

                Model.ApplicationSetting result = null;

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

                return(result);
            }
            catch (Exception ex)
            {
                Trace.WriteError("{0}", "GetById", CLASSNAME, ex, applicationSettingId);
                throw DbHelper.TranslateException(ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
 /// <summary>
 /// Equals function to compare class
 /// </summary>
 public virtual bool Exists(Model.ApplicationSetting applicationSetting)
 {
     try
     {
         return(this.GetById(applicationSetting.ApplicationSettingId) != null);
     }
     catch (Exception ex)
     {
         Trace.WriteError("({0})", "Exists", CLASSNAME, ex, applicationSetting);
         throw;
     }
 }
 /// <summary>
 /// Get a ApplicationSetting by id from the database
 /// </summary>
 public virtual Model.ApplicationSetting GetById(Int32 applicationSettingId)
 {
     try
     {
         DataAccess.ApplicationSettings applicationSettings = new DataAccess.ApplicationSettings();
         Model.ApplicationSetting       result = applicationSettings.GetById(applicationSettingId);
         return(result);
     }
     catch (Exception ex)
     {
         Trace.WriteError("{0}", "GetById", CLASSNAME, ex, applicationSettingId);
         throw;
     }
 }
예제 #7
0
        /// <summary>
        /// Delete the given ApplicationSetting from the database
        /// </summary>
        public virtual void Delete(Model.ApplicationSetting applicationSetting)
        {
            try
            {
                Trace.WriteVerbose("({0})", "Delete", CLASSNAME, applicationSetting.ToString());

                var helper = Database.GetDbHelper();
                helper.ExecuteSPNonQuery(_storedProcedure_Delete,
                                         helper.CreateInputParam("@ApplicationSettingId", applicationSetting.ApplicationSettingId));
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", "Delete", CLASSNAME, ex, applicationSetting.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }
예제 #8
0
 /// <summary>
 /// Create a Model.ApplicationSetting
 /// </summary>
 protected virtual Model.ApplicationSetting CreateApplicationSetting(DbDataReader reader)
 {
     try
     {
         Model.ApplicationSetting result = new Model.ApplicationSetting(
             (Int32)reader["ApplicationSettingId"],
             (Int32)reader["ApplicationSettingsCategoryId"],
             (String)reader["Name"],
             (String)reader["Description"],
             (Int32)reader["DataTypeId"],
             (String)reader["Value"],
             reader["ListId"] != DBNull.Value ? (Int32?)reader["ListId"] : null
             );
         return(result);
     }
     catch (Exception ex)
     {
         Trace.WriteError("", "CreateApplicationSetting", CLASSNAME, ex);
         throw DbHelper.TranslateException(ex);
     }
 }
        /// <summary>
        /// Add a new ApplicationSetting to the database
        /// </summary>
        public virtual void Add(Model.ApplicationSetting newApplicationSetting)
        {
            try
            {
                Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, newApplicationSetting);

                CheckConstraints(newApplicationSetting);
                DataAccess.ApplicationSettings applicationSettings = new DataAccess.ApplicationSettings();

                applicationSettings.Add(newApplicationSetting);
            }
            catch (DalForeignKeyException ex_fk)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex_fk, newApplicationSetting);
                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, newApplicationSetting);
                throw;
            }
        }
        /// <summary>
        /// Check Datafield constraints
        /// </summary>
        protected virtual void CheckConstraints(Model.ApplicationSetting applicationSetting)
        {
            //Range checks, etc checks go here
            if (applicationSetting.Name == null)
            {
                throw new BusinessException(string.Format("Name may not be NULL. ({0})", applicationSetting.Name));
            }

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

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

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

                //Begin Checks
                CheckConstraints(modifiedApplicationSetting);

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

                DataAccess.ApplicationSettings applicationSettings = new DataAccess.ApplicationSettings();
                applicationSettings.Modify(modifiedApplicationSetting);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", "Modify", CLASSNAME, ex, modifiedApplicationSetting);
                throw;
            }
        }