Beispiel #1
0
        /// <summary>
        ///   The overloaded Load method that will return a specific <see cref="UserRole"/> object, with keys in <c>aUserRole</c>.
        /// </summary>
        /// <param name="aUserKey">A <see cref="UserKey"/> object.</param>
        /// <param name="aUserRole">A <see cref="UserRole"/>.</param>
        /// <exception cref="ArgumentNullException">If <c>aUserRole</c> is <c>null</c>.</exception>
        public static void Load(UserKey aUserKey, UserRole aUserRole)
        {
            if (aUserRole == null)
            {
                throw new ArgumentNullException("Load UserRole Business");
            }

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

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

            _isFiltered = (aSource as UserRoleCollection)._isFiltered;
            _userKeyFilter = (aSource as UserRoleCollection)._userKeyFilter;
            _userRoleList.Clear();
            foreach (UserRole vUserRoleSource in (aSource as UserRoleCollection)._userRoleList)
            {
                UserRole vUserRoleTarget = new UserRole();
                vUserRoleTarget.AssignFromSource(vUserRoleSource);
                _userRoleList.Add(vUserRoleTarget);
            }
        }
Beispiel #3
0
 /// <summary>
 ///   Insert a <see cref="UserRole"/> passed as an argument via Stored Procedure that returns the newly inserted UserRole Key 
 /// </summary>
 /// <param name="aUserRole">A <see cref="UserRole"/>.</param>
 /// <exception cref="ArgumentNullException">If <c>aUserRole</c> argument is <c>null</c>.</exception>
 public static void Insert(UserRole aUserRole)
 {
     if (aUserRole == null)
     {
         throw new ArgumentNullException("aUserRole");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("insert into URL_UserRole");
         vStringBuilder.AppendLine("       (USR_Key, ROL_key)");
         vStringBuilder.AppendLine("values");
         vStringBuilder.AppendLine("       (@USRKey, @ROLkey)");
         ObjectToData(vSqlCommand, aUserRole);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         vSqlCommand.ExecuteNonQuery();
         vSqlCommand.Connection.Close();
     }
 }
Beispiel #4
0
 /// <summary>
 ///   Delete a <see cref="UserRole"/> object passed as an argument.
 /// </summary>
 /// <param name="aUserRole">The <see cref="UserRole"/> object to be deleted.</param>
 /// <exception cref="ArgumentNullException">If <c>aUserRole</c> argument is <c>null</c>.</exception>
 public static void Delete(UserRole aUserRole)
 {
     if (aUserRole == null)
     {
         throw new ArgumentNullException("aUserRole");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("delete URL_UserRole");
         vStringBuilder.AppendLine("where  USR_Key = @USRKey");
         vSqlCommand.Parameters.AddWithValue("@USRKey", aUserRole.UsrKey);
         vStringBuilder.AppendLine("and    ROL_key = @ROLkey");
         vSqlCommand.Parameters.AddWithValue("@ROLkey", aUserRole.Rolkey);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         vSqlCommand.ExecuteNonQuery();
         vSqlCommand.Connection.Close();
     }
 }
Beispiel #5
0
 /// <summary>
 ///   The <c>EditUserRole</c> implementation method deserializes an incoming XML Argument <see cref="string"/> as a new <see cref="UserRole"/> object.
 ///   It invokes the <c>Update</c> method of <see cref="UserRoleBusiness"/> with the newly deserialized <see cref="UserRole"/> 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="UserRole"/> as XML <see cref="string"/>.</returns>
 /// <exception cref="ArgumentNullException">If <c>aXmlArgument</c> is <c>null</c>.</exception>
 public static string EditUserRole(UserKey aUserKey, string aXmlArgument)
 {
     if (aXmlArgument == null)
     {
         throw new ArgumentNullException("aXmlArgument of EditUserRole");
     }
     UserRole vUserRole = new UserRole();
     vUserRole = XmlUtils.Deserialize<UserRole>(aXmlArgument);
     UserRoleBusiness.Update(aUserKey, vUserRole);
     return XmlUtils.Serialize<UserRole>(vUserRole, true);
 }
Beispiel #6
0
 /// <summary>
 ///   The overloaded Load method that will fill the <c>UserRoleList</c> property a <see cref="UserRoleCollection"/> object as an
 ///   ordered <c>List</c> of <see cref="UserRole"/>, filtered by the filter properties of the passed <see cref="UserRoleCollection"/>.
 /// </summary>
 /// <param name="aUserRoleCollection">The <see cref="UserRoleCollection"/> object that must be filled.</param>
 /// <remarks>
 ///   The filter properties of the <see cref="UserRoleCollection"/> must be correctly completed by the calling application.
 /// </remarks>
 /// <exception cref="ArgumentNullException">If <c>aUserRoleCollection</c> argument is <c>null</c>.</exception>
 public static void Load(UserRoleCollection aUserRoleCollection)
 {
     if (aUserRoleCollection == null)
     {
         throw new ArgumentNullException("aUserRoleCollection");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = BuildSQL();
         if (aUserRoleCollection.IsFiltered)
         {
             if (aUserRoleCollection.UserKeyFilter > 0)
             {
                 vStringBuilder.AppendLine("and    t1.USR_Key = @USRKey");
                 vSqlCommand.Parameters.AddWithValue("@USRKey", aUserRoleCollection.UserKeyFilter);
             }
         }
         vStringBuilder.AppendLine("order by t2.URL_Key");
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader())
         {
             while (vSqlDataReader.Read())
             {
                 var vUserRole = new UserRole();
                 DataToObject(vUserRole, vSqlDataReader);
                 aUserRoleCollection.UserRoleList.Add(vUserRole);
             }
             vSqlDataReader.Close();
         }
         vSqlCommand.Connection.Close();
     }
 }
Beispiel #7
0
 /// <summary>
 ///   Load a <see cref="SqlDataReader"/> into a <see cref="UserRole"/> object.
 /// </summary>
 /// <param name="aUserRole">A <see cref="UserRole"/> argument.</param>
 /// <param name="aSqlDataReader">A <see cref="SqlDataReader"/> argument.</param>
 public static void DataToObject(UserRole aUserRole, SqlDataReader aSqlDataReader)
 {
     aUserRole.UsrKey = Convert.ToInt32(aSqlDataReader["USR_Key"]);
     aUserRole.UsrDisplayName = Convert.ToString(aSqlDataReader["USR_DisplayName"]);
     aUserRole.Rolkey = Convert.ToInt32(aSqlDataReader["ROL_key"]);
 }
Beispiel #8
0
 /// <summary>
 ///   Update a <see cref="UserRole"/> passed as an argument .
 /// </summary>
 /// <param name="aUserRole">A <see cref="UserRole"/>.</param>
 public static void Update(UserRole aUserRole)
 {
     //            if (aUserRole == null)
     //            {
     //                throw new ArgumentNullException("aUserRole");
     //            }
     //            using (var vSqlCommand = new SqlCommand()
     //            {
     //                CommandType = CommandType.Text,
     //                Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     //            })
     //            {
     //                var vStringBuilder = new StringBuilder();
     //                vStringBuilder.AppendLine("update URL_UserRole");
     //");
     //                vStringBuilder.AppendLine("where  USR_Key = @USRKey");
     //                vStringBuilder.AppendLine("and    ROL_key = @ROLkey");
     //                ObjectToData(vSqlCommand, aUserRole);
     //                vSqlCommand.CommandText = vStringBuilder.ToString();
     //                vSqlCommand.Connection.Open();
     //                vSqlCommand.ExecuteNonQuery();
     //                vSqlCommand.Connection.Close();
     //            }
 }
Beispiel #9
0
 /// <summary>
 ///   Loads the <see cref="SqlCommand"/> parameters with values from an <see cref="UserRole"/>.
 /// </summary>
 /// <param name="aSqlCommand">A <see cref="SqlDataReader"/> argument.</param>
 /// <param name="aUserRole">A <see cref="UserRole"/> argument.</param>
 public static void ObjectToData(SqlCommand aSqlCommand, UserRole aUserRole)
 {
     aSqlCommand.Parameters.AddWithValue("@USRKey", aUserRole.UsrKey);
     aSqlCommand.Parameters.AddWithValue("@ROLkey", aUserRole.Rolkey);
 }
Beispiel #10
0
 /// <summary>
 ///   The overloaded Load method that will return a specific <see cref="UserRole"/>, with keys in the <c>aUserRole</c> argument.
 /// </summary>
 /// <param name="aUserRole">A <see cref="UserRole"/>.</param>
 /// <exception cref="ArgumentNullException">If <c>aUserRole</c> argument is <c>null</c>.</exception>
 /// <exception cref="Exception">If no record is found.</exception>
 public static void Load(UserRole aUserRole)
 {
     if (aUserRole == null)
     {
         throw new ArgumentNullException("aUserRole");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = BuildSQL();
         vStringBuilder.AppendLine("and    t1.USR_Key = @USRKey");
         vSqlCommand.Parameters.AddWithValue("@USRKey", aUserRole.UsrKey);
         vStringBuilder.AppendLine("and    t0.ROL_key = @ROLkey");
         vSqlCommand.Parameters.AddWithValue("@ROLkey", aUserRole.Rolkey);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader())
         {
             if (!vSqlDataReader.HasRows)
             {
                 throw new Exception(String.Format("Expected UserRole not found: USR_Key = {0}, ROL_key = {1}", aUserRole.UsrKey, aUserRole.Rolkey));
             }
             vSqlDataReader.Read();
             DataToObject(aUserRole, vSqlDataReader);
             vSqlDataReader.Close();
         }
         vSqlCommand.Connection.Close();
     }
 }