コード例 #1
0
        } //End Add method

        /// <summary>
        ///  Updates an existing DB record with provided information.
        /// </summary>
        /// <param name="info"> The configuration record that needs updating. </param>
        /// <param name="transaction"> The SQL transaction object. </param>
        public void Update(Cont.Configuration info, SqlTransaction transaction = null)
        {
            SqlService sql = null;

            try
            {
                sql = new SqlService(transaction);
                sql.AddParameter("@ID", SqlDbType.Int, info.ID, ParameterDirection.Input, true);
                sql.AddParameter("@Name", SqlDbType.VarChar, info.Name, 50, ParameterDirection.Input, true);
                sql.AddParameter("@Type", SqlDbType.VarChar, info.Type, 3, ParameterDirection.Input, true);

                sql.ExecuteSP("UpdateConfiguration");

                // Update cached values
                Cont.Configuration cacheItemToRemove = CachedValues.Value.FirstOrDefault(x => x.ID == info.ID && !x.Equals(info));
                if (cacheItemToRemove != null)
                {
                    CachedValues.Value.Remove(cacheItemToRemove); //Remove item
                    CachedValues.Value.Add(info);                 //Add item
                }//end if
            }//end try
            catch (Exception exc)
            {
                throw exc;
            }//end catch
            finally
            {
                if (sql != null)
                {
                    sql.Disconnect();
                }
            } //end finally
        }     //End update method
コード例 #2
0
        /// <summary>
        ///  Adds a configuration record to the database.
        /// </summary>
        /// <param name="info"> The configuration record that needs adding. </param>
        /// <param name="transaction"> The SQL transaction object. </param>
        /// <returns> The DB record ID. </returns>
        public int Add(Cont.Configuration info, SqlTransaction transaction = null)
        {
            SqlService sql = null;

            try
            {
                sql = new SqlService(transaction);
                sql.AddParameter("@ID", SqlDbType.Int, info.ID, ParameterDirection.InputOutput, true);
                sql.AddParameter("@Name", SqlDbType.VarChar, info.Name, 50, ParameterDirection.Input, true);
                sql.AddParameter("@Type", SqlDbType.VarChar, info.Type, 3, ParameterDirection.Input, true);

                sql.ExecuteSP("AddConfiguration");
                SqlParameter param = sql.ResultParameters["@ID"];
                info.ID = Convert.ToInt32(param.Value);

                // Update cached values
                CachedValues.Value.Add(info);
            }//end try
            catch (Exception exc)
            {
                throw exc;
            }//end catch
            finally
            {
                if (sql != null)
                {
                    sql.Disconnect();
                }
            }//end finally

            return(info.ID);
        } //End Add method
コード例 #3
0
        }         //End method getByID

        /// <summary>
        ///  This method gets all Configuration records from DB.
        /// </summary>
        /// <returns> A list of Configuration records in Object-Oriented form. </returns>
        public Cont.Configuration[] GetAll()
        {
            Cont.Configuration[] toReturn = new Cont.Configuration[0];
            SqlService           sql      = null;
            SqlDataReader        reader   = null;

            try
            {
                sql      = new SqlService();
                reader   = sql.ExecuteSPReader("GetConfigurationAll");
                toReturn = ConvertToContainer(reader); //MARK: Make sure row IDs corresponds to Database fields
            }//end try
            catch (Exception exc)
            {
                throw exc;
            }//end catch
            finally
            {
                if (reader != null && !reader.IsClosed)
                {
                    reader.Close();
                }
                if (sql != null)
                {
                    sql.Disconnect();
                }
            }//end finally

            return(toReturn);
        } //End method getAll
コード例 #4
0
        }     //End update method

        /// <summary>
        ///  This method deletes a Configuration DB record.
        /// </summary>
        /// <param name="ID"> The record ID you want removed. </param>
        /// <param name="transaction"> The SQL Transaction object. </param>
        public void Delete(int ID, SqlTransaction transaction = null)
        {
            SqlService sql = null;

            try
            {
                sql = new SqlService(transaction);
                sql.AddParameter("@ID", SqlDbType.Int, ID, ParameterDirection.Input, true);
                sql.ExecuteSP("DeleteConfiguration");

                // Update cached values
                Cont.Configuration cacheItemToRemove = CachedValues.Value.FirstOrDefault(x => x.ID == ID);
                if (cacheItemToRemove != null)
                {
                    CachedValues.Value.Remove(cacheItemToRemove);  //Remove item
                }//end if
            }//end try
            catch (Exception exc)
            {
                throw exc;
            }//end catch
            finally
            {
                if (sql != null)
                {
                    sql.Disconnect();
                }
            } //end finally
        }     //End Delete method.
コード例 #5
0
        }     //End Delete method.

        /// <summary>
        ///  This method gets a Configuration Record by ID.
        /// </summary>
        /// <param name="ID"> The DB ID of the record you want to retrieve. </param>
        /// <returns> The configuration record in Object-Oriented form. </returns>
        public Cont.Configuration GetByID(int ID)
        {
            Cont.Configuration toReturn = CachedValues.Value.FirstOrDefault(x => x.ID == ID);
            if (toReturn == null)
            {
                SqlService    sql    = null;
                SqlDataReader reader = null;
                try
                {
                    sql = new SqlService();
                    sql.AddParameter("@ID", SqlDbType.Int, ID, ParameterDirection.Input, true);

                    reader   = sql.ExecuteSPReader("GetConfiguration");     //TODO: Pass in the Stored Procedure Name
                    toReturn = ConvertToContainer(reader).FirstOrDefault(); //MARK: Make sure row IDs corresponds to Database fields

                    //Append to cached values
                    if (toReturn != null)
                    {
                        CachedValues.Value.Add(toReturn);
                    } //endif
                }     //end try
                catch (Exception exc)
                {
                    throw exc;
                }//end catch
                finally
                {
                    if (reader != null && !reader.IsClosed)
                    {
                        reader.Close();
                    }
                    if (sql != null)
                    {
                        sql.Disconnect();
                    }
                } //end finally
            }     //end if
            return(toReturn);
        }         //End method getByID