/// <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(); } }
/// <summary> /// The <c>AddRole</c> implementation method deserializes an incoming XML Argument <see cref="string"/> as a new <see cref="Role"/> object. /// It invokes the <c>Insert</c> method of <see cref="RoleBusiness"/> with the newly deserialized <see cref="Role"/> object. /// Finally, it returns the inserted object (now with an assigned Role Key) 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 AddRole(UserKey aUserKey, string aXmlArgument) { if (aXmlArgument == null) { throw new ArgumentNullException("aXmlArgument of AddRole"); } Role vRole = new Role(); vRole = XmlUtils.Deserialize<Role>(aXmlArgument); RoleBusiness.Insert(aUserKey, vRole); return XmlUtils.Serialize<Role>(vRole, true); }
/// <summary> /// Insert a <see cref="Role"/> object passed as an argument via Stored Procedure that returns the newly inserted <i>Role Key</i>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aRole">A <see cref="Role"/> object.</param> /// <exception cref="ArgumentNullException">If <c>aRole</c> argument is <c>null</c>.</exception> public static void Insert(UserKey aUserKey, Role aRole) { if (aRole == null) { throw new ArgumentNullException("Insert Role Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "Role", AccessMode.Create)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Create, "Role"); } RoleData.Insert(aRole); }
/// <summary> /// Delete a <see cref="Role"/> object passed as an argument. /// </summary> /// <param name="aFanKey">A <see cref="FanKey"/> object.</param> /// <param name="aRole">A <see cref="Role"/> object.</param> /// <exception cref="ArgumentNullException">If <c>aRole</c> argument is <c>null</c>.</exception> public static void Delete(FanKey aFanKey, Role aRole) { if (aRole == null) { throw new ArgumentNullException("Delete Role Business"); } if (!FanFunctionAccessData.HasModeAccess(aFanKey, "Role", AccessMode.Delete)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aFanKey.FannKey), AccessMode.Delete, "Role"); } RoleData.Delete(aRole); }
/// <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); } }
/// <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> /// Gets a specified <see cref="Role"/> by key. /// </summary> /// <param name="aRole"><see cref="Role"/> object.</param> /// <param name="aUserToken">A user token.</param> public static void GetRole(UserToken aUserToken, Role aRole) { UserCallHandler.ServiceCall<Role>(aUserToken, "GetRole", aRole); }
/// <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(); } }
/// <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"]); }
/// <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); }
/// <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(); } }
/// <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(FanKey aFanKey, string aXmlArgument) { if (aXmlArgument == null) { throw new ArgumentNullException("aXmlArgument of EditRole"); } Role vRole = new Role(); vRole = XmlUtils.Deserialize<Role>(aXmlArgument); RoleBusiness.Update(aFanKey, vRole); return XmlUtils.Serialize<Role>(vRole, true); }
/// <summary> /// Add a <see cref="Role"/>. /// </summary> /// <param name="aRole"><see cref="Role"/> object.</param> /// <param name="aFanToken">A fantoken.</param> public static void AddRole(FanToken aFanToken, Role aRole) { FanCallHandler.ServiceCall<Role>(aFanToken, "AddRole", aRole); }