Exemple #1
0
 /// <summary>
 ///   Insert a <see cref="Role"/> passed as an argument via Stored Procedure that returns the newly inserted Role Key 
 /// </summary>
 /// <param name="aRole">A <see cref="Role"/>.</param>
 /// <exception cref="ArgumentNullException">If <c>aRole</c> argument is <c>null</c>.</exception>
 public static void Insert(Role aRole)
 {
     if (aRole == null)
     {
         throw new ArgumentNullException("aRole");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("insert into ROL_Role");
         vStringBuilder.AppendLine("       (ROL_Name)");
         vStringBuilder.AppendLine("values");
         vStringBuilder.AppendLine("       (@ROLName)");
         vStringBuilder.AppendLine(";");
         vStringBuilder.AppendLine("select SCOPE_IDENTITY()");
         ObjectToData(vSqlCommand, aRole);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         aRole.RolKey = Convert.ToInt32(vSqlCommand.ExecuteScalar());
         vSqlCommand.Connection.Close();
     }
 }
Exemple #2
0
        /// <summary>
        ///   The overloaded Load method that will return a specific <see cref="Role"/> object, with keys in <c>aRole</c>.
        /// </summary>
        /// <param name="aUserKey">A <see cref="UserKey"/> object.</param>
        /// <param name="aRole">A <see cref="Role"/>.</param>
        /// <exception cref="ArgumentNullException">If <c>aRole</c> is <c>null</c>.</exception>
        public static void Load(UserKey aUserKey, Role aRole)
        {
            if (aRole == null)
            {
                throw new ArgumentNullException("Load Role Business");
            }

            if (!UserFunctionAccessData.HasModeAccess(aUserKey, "Role", AccessMode.Read))
            {
                throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Read, "Role");
            }

            RoleData.Load(aRole);
        }
Exemple #3
0
        /// <summary>
        ///    Assigns all <c>aSource</c> object's values to this instance of <see cref="RoleCollection"/>.
        /// </summary>
        /// <param name="aSource">A source object.</param>
        public override void AssignFromSource(object aSource)
        {
            if (!(aSource is RoleCollection))
            {
                throw new ArgumentException("Invalid assignment source", "RoleCollection");
            }

            _isFiltered = (aSource as RoleCollection)._isFiltered;

            _roleList.Clear();
            foreach (Role vRoleSource in (aSource as RoleCollection)._roleList)
            {
                Role vRoleTarget = new Role();
                vRoleTarget.AssignFromSource(vRoleSource);
                _roleList.Add(vRoleTarget);
            }
        }
Exemple #4
0
 /// <summary>
 ///   Delete a <see cref="Role"/> object passed as an argument.
 /// </summary>
 /// <param name="aRole">The <see cref="Role"/> object to be deleted.</param>
 /// <exception cref="ArgumentNullException">If <c>aRole</c> argument is <c>null</c>.</exception>
 public static void Delete(Role aRole)
 {
     if (aRole == null)
     {
         throw new ArgumentNullException("aRole");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("delete ROL_Role");
         vStringBuilder.AppendLine("where  ROL_Key = @ROLKey");
         vSqlCommand.Parameters.AddWithValue("@ROLKey", aRole.RolKey);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         vSqlCommand.ExecuteNonQuery();
         vSqlCommand.Connection.Close();
     }
 }
 /// <summary>
 ///   Add a <see cref="Role"/>.
 /// </summary>
 /// <param name="aRole"><see cref="Role"/> object.</param>
 /// <param name="aUserToken">A user token.</param>
 public static void AddRole(UserToken aUserToken, Role aRole)
 {
     UserCallHandler.ServiceCall<Role>(aUserToken, "AddRole", aRole);
 }
 /// <summary>
 ///   The <c>EditRole</c> implementation method deserializes an incoming XML Argument <see cref="string"/> as a new <see cref="Role"/> object.
 ///   It invokes the <c>Update</c> method of <see cref="RoleBusiness"/> with the newly deserialized <see cref="Role"/> object.
 ///   Finally, it returns the updated object unchanged as a serialized <see cref="string"/> of XML.
 /// </summary>
 /// <param name="aXmlArgument">XML Argument <see cref="string"/>.</param>
 /// <returns><see cref="Role"/> as XML <see cref="string"/>.</returns>
 /// <exception cref="ArgumentNullException">If <c>aXmlArgument</c> is <c>null</c>.</exception>
 public static string EditRole(UserKey aUserKey, string aXmlArgument)
 {
     if (aXmlArgument == null)
     {
         throw new ArgumentNullException("aXmlArgument of EditRole");
     }
     Role vRole = new Role();
     vRole = XmlUtils.Deserialize<Role>(aXmlArgument);
     RoleBusiness.Update(aUserKey, vRole);
     return XmlUtils.Serialize<Role>(vRole, true);
 }
Exemple #7
0
        /// <summary>
        ///   The overloaded Load method that will fill the <c>RoleList</c> property a <see cref="RoleCollection"/> object as an
        ///   ordered <c>List</c> of <see cref="Role"/>, filtered by the filter properties of the passed <see cref="RoleCollection"/>.
        /// </summary>
        /// <param name="aRoleCollection">The <see cref="RoleCollection"/> object that must be filled.</param>
        /// <remarks>
        ///   The filter properties of the <see cref="RoleCollection"/> must be correctly completed by the calling application.
        /// </remarks>
        /// <exception cref="ArgumentNullException">If <c>aRoleCollection</c> argument is <c>null</c>.</exception>
        public static void Load(RoleCollection aRoleCollection)
        {
            if (aRoleCollection == null)
            {
                throw new ArgumentNullException("aRoleCollection");
            }
            using (var vSqlCommand = new SqlCommand()
            {
                CommandType = CommandType.Text,
                Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
            })
            {
                var vStringBuilder = BuildSQL();
                if (aRoleCollection.IsFiltered)
                {

                }
                vStringBuilder.AppendLine("order by t1.ROL_Name");
                vSqlCommand.CommandText = vStringBuilder.ToString();
                vSqlCommand.Connection.Open();
                using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader())
                {
                    while (vSqlDataReader.Read())
                    {
                        var vRole = new Role();
                        DataToObject(vRole, vSqlDataReader);
                        aRoleCollection.RoleList.Add(vRole);
                    }
                    vSqlDataReader.Close();
                }
                vSqlCommand.Connection.Close();
            }
        }
Exemple #8
0
 /// <summary>
 ///   Load a <see cref="SqlDataReader"/> into a <see cref="Role"/> object.
 /// </summary>
 /// <param name="aRole">A <see cref="Role"/> argument.</param>
 /// <param name="aSqlDataReader">A <see cref="SqlDataReader"/> argument.</param>
 public static void DataToObject(Role aRole, SqlDataReader aSqlDataReader)
 {
     aRole.RolKey = Convert.ToInt32(aSqlDataReader["ROL_Key"]);
     aRole.RolName = Convert.ToString(aSqlDataReader["ROL_Name"]);
 }
Exemple #9
0
 /// <summary>
 ///   Loads the <see cref="SqlCommand"/> parameters with values from an <see cref="Role"/>.
 /// </summary>
 /// <param name="aSqlCommand">A <see cref="SqlDataReader"/> argument.</param>
 /// <param name="aRole">A <see cref="Role"/> argument.</param>
 public static void ObjectToData(SqlCommand aSqlCommand, Role aRole)
 {
     aSqlCommand.Parameters.AddWithValue("@ROLName", aRole.RolName);
 }
Exemple #10
0
 /// <summary>
 ///   The overloaded Load method that will return a specific <see cref="Role"/>, with keys in the <c>aRole</c> argument.
 /// </summary>
 /// <param name="aRole">A <see cref="Role"/>.</param>
 /// <exception cref="ArgumentNullException">If <c>aRole</c> argument is <c>null</c>.</exception>
 /// <exception cref="Exception">If no record is found.</exception>
 public static void Load(Role aRole)
 {
     if (aRole == null)
     {
         throw new ArgumentNullException("aRole");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = BuildSQL();
         vStringBuilder.AppendLine("and    t1.ROL_Key = @ROLKey");
         vSqlCommand.Parameters.AddWithValue("@ROLKey", aRole.RolKey);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader())
         {
             if (!vSqlDataReader.HasRows)
             {
                 throw new Exception(String.Format("Expected Role not found: ROL_Key = {0}", aRole.RolKey));
             }
             vSqlDataReader.Read();
             DataToObject(aRole, vSqlDataReader);
             vSqlDataReader.Close();
         }
         vSqlCommand.Connection.Close();
     }
 }