예제 #1
0
        //------------------------------------------
        #endregion

        #region --------------GetObject--------------
        public static MailListGroupsEntity GetObject(int groupID)
        {
            MailListGroupsEntity mailListGroups = MailListGroupsSqlDataPrvider.Instance.GetObject(groupID);

            //return the object
            return(mailListGroups);
        }
        public MailListGroupsEntity GetObject(int groupID)
        {
            MailListGroupsEntity mailListGroups = null;

            using (SqlConnection myConnection = GetSqlConnection())
            {
                SqlCommand myCommand = new SqlCommand("MailListGroups_GetOneByID", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                // Set the parameters
                myCommand.Parameters.Add("@GroupID", SqlDbType.Int, 4).Value = groupID;
                //----------------------------------------------------------------------------------------------
                //OwnerID
                myCommand.Parameters.Add("@OwnerID", SqlDbType.UniqueIdentifier).Value = SitesHandler.GetOwnerIDAsGuid();
                //----------------------------------------------------------------------------------------------
                // Execute the command
                myConnection.Open();
                using (SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    if (dr.Read())
                    {
                        mailListGroups = PopulateEntity(dr);
                    }
                    dr.Close();
                }
                myConnection.Close();
                return(mailListGroups);
            }
        }
        //------------------------------------------
        #endregion

        #region --------------PopulateEntity--------------
        private MailListGroupsEntity PopulateEntity(IDataReader reader)
        {
            //Create a new MailListGroups object
            MailListGroupsEntity mailListGroups = new MailListGroupsEntity();

            //Fill the object with data
            //GroupID
            if (reader["GroupID"] != DBNull.Value)
            {
                mailListGroups.GroupID = (int)reader["GroupID"];
            }
            //Name
            if (reader["Name"] != DBNull.Value)
            {
                mailListGroups.Name = (string)reader["Name"];
            }
            //Return the populated object
            return(mailListGroups);
        }
        //------------------------------------------
        #endregion

        #region --------------Save--------------

        public ExecuteCommandStatus Save(MailListGroupsEntity mailListGroups, SPOperation operation)
        {
            using (SqlConnection myConnection = GetSqlConnection())
            {
                SqlCommand myCommand = new SqlCommand("MailListGroups_Save", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                // Set the parameters
                //GroupID
                if (operation == SPOperation.Insert)
                {
                    myCommand.Parameters.Add("@GroupID", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
                }
                else
                {
                    myCommand.Parameters.Add("@GroupID", SqlDbType.Int, 4).Value = mailListGroups.GroupID;
                }
                //SPOperation
                myCommand.Parameters.Add("@SPOperation", SqlDbType.Int, 4).Value = (int)operation;
                //Name
                myCommand.Parameters.Add("@Name", SqlDbType.NVarChar, 64).Value = mailListGroups.Name;
                //----------------------------------------------------------------------------------------------
                //OwnerID
                myCommand.Parameters.Add("@OwnerID", SqlDbType.UniqueIdentifier).Value = SitesHandler.GetOwnerIDAsGuid();
                //----------------------------------------------------------------------------------------------
                // Execute the command
                myConnection.Open();
                ExecuteCommandStatus status = (ExecuteCommandStatus)myCommand.ExecuteScalar();
                if (status == ExecuteCommandStatus.Done)
                {
                    //Get ID value from database and set it in object
                    mailListGroups.GroupID = (int)myCommand.Parameters["@GroupID"].Value;
                }
                myConnection.Close();
                return(status);
            }
        }
예제 #5
0
 public static ExecuteCommandStatus Save(MailListGroupsEntity mailListGroups, SPOperation operation)
 {
     return(MailListGroupsSqlDataPrvider.Instance.Save(mailListGroups, operation));
 }