/// <summary> /// Load a <see cref="SqlDataReader"/> into a <see cref="Friend"/> object. /// </summary> /// <param name="aFriend">A <see cref="Fanatic"/> argument.</param> /// <param name="aSqlDataReader">A <see cref="SqlDataReader"/> argument.</param> public static void DataToObject(Friend aFriend, SqlDataReader aSqlDataReader, bool aIncludeAvatar) { aFriend.Fan1Key = Convert.ToInt32(aSqlDataReader["Friend1_Key"]); aFriend.Fan1Name = Convert.ToString(aSqlDataReader["Friend1_Name"]); aFriend.Fan1Surname = Convert.ToString(aSqlDataReader["Friend1_Surname"]); aFriend.Fan2Key = Convert.ToInt32(aSqlDataReader["Friend2_Key"]); aFriend.Fan2Name = Convert.ToString(aSqlDataReader["Friend2_Name"]); aFriend.Fan2Surname = Convert.ToString(aSqlDataReader["Friend2_Surname"]); aFriend.FriendDateEstablished = (Convert.ToDateTime(aSqlDataReader["FRD_DateEstablished"])).ToLongDateString(); aFriend.Relationship = Convert.ToInt32(aSqlDataReader["Relationship_Key"]); aFriend.RelationshipType = Convert.ToString(aSqlDataReader["Relationship_Type"]); }
/// <summary> /// The overloaded Load method that will return a specific <see cref="Friend"/> object, with keys in <c>aFriend</c>. /// </summary> /// <param name="aFanKey">A <see cref="FanKey"/> object.</param> /// <param name="aFriend">A <see cref="Friend"/>.</param> /// <exception cref="ArgumentNullException">If <c>aFriend</c> is <c>null</c>.</exception> public static void Load(FanKey aFanKey, Friend aFriend) { if (aFriend == null) { throw new ArgumentNullException("Load Friend Business"); } //if (!FanFunctionAccessData.HasModeAccess(aFanKey, "Friend", AccessMode.Read)) //{ // throw new ZpAccessException("Access Denied", String.Format("{0}", aFanKey.FannKey), AccessMode.Read, "Friend"); //} FriendData.Load(aFriend); }
/// <summary> /// Assigns all <c>aSource</c> object's values to this instance of <see cref="FriendCollection"/>. /// </summary> /// <param name="aSource">A source object.</param> public override void AssignFromSource(object aSource) { if (!(aSource is FriendCollection)) { throw new ArgumentException("Invalid assignment source", "FriendCollection"); } _isFiltered = (aSource as FriendCollection)._isFiltered; _friendFilter = (aSource as FriendCollection)._friendFilter; _friendList.Clear(); foreach (Friend vFriendSource in (aSource as FriendCollection)._friendList) { Friend vFriendTarget = new Friend(); vFriendTarget.AssignFromSource(vFriendSource); _friendList.Add(vFriendTarget); } }
/// <summary> /// Delete a <see cref="Friend"/> object passed as an argument. /// </summary> /// <param name="aFriend">The <see cref="Friend"/> object to be deleted.</param> /// <exception cref="ArgumentNullException">If <c>aFriend</c> argument is <c>null</c>.</exception> public static void Delete(Friend aFriend) { if (aFriend == null) { throw new ArgumentNullException("aFriend"); } using (var vSqlCommand = new SqlCommand() { CommandType = CommandType.Text, Connection = new SqlConnection(Connection.Instance.SqlConnectionString) }) { var vStringBuilder = new StringBuilder(); vStringBuilder.AppendLine("delete FRD_Friend"); vStringBuilder.AppendLine("where FAN_Key1 = @FAN1Key"); vStringBuilder.AppendLine("or FAN_Key2 = @FAN1Key"); vSqlCommand.Parameters.AddWithValue("@FAN1Key", aFriend.Fan1Key); vSqlCommand.CommandText = vStringBuilder.ToString(); vSqlCommand.Connection.Open(); vSqlCommand.ExecuteNonQuery(); vSqlCommand.Connection.Close(); } }
/// <summary> /// Gets the <see cref="Friend"/> by Key. /// </summary> /// <param name="aXmlArgument">XML Argument <see cref="string"/>.</param> /// <returns>Friend as XML <see cref="string"/>.</returns> /// <exception cref="ArgumentNullException">If <c>aXmlArgument</c> is <c>null</c>.</exception> public static string GetFriend(FanKey aFanKey, string aXmlArgument) { if (aXmlArgument == null) { throw new ArgumentNullException("aXmlArgument of GetFriend"); } Friend vFriend = new Friend(); vFriend = XmlUtils.Deserialize<Friend>(aXmlArgument); FriendBusiness.Load(aFanKey, vFriend); return XmlUtils.Serialize<Friend>(vFriend, true); }
/// <summary> /// Update a <see cref="Friend"/> passed as an argument . /// </summary> /// <param name="aFriend">A <see cref="Friend"/>.</param> public static void Update(Friend aFriend) { if (aFriend == null) { throw new ArgumentNullException("aFriend"); } using (var vSqlCommand = new SqlCommand() { CommandType = CommandType.Text, Connection = new SqlConnection(Connection.Instance.SqlConnectionString) }) { var vStringBuilder = new StringBuilder(); vStringBuilder.AppendLine("update FRD_Friend"); vStringBuilder.AppendLine("set REL_Key = @RELKey,"); vStringBuilder.AppendLine("where FAN_Key = @FAN1Key"); vStringBuilder.AppendLine("and FAN_Key = @FAN2Key"); vSqlCommand.Parameters.AddWithValue("@RELKey", aFriend.Relationship); vSqlCommand.CommandText = vStringBuilder.ToString(); vSqlCommand.Connection.Open(); vSqlCommand.ExecuteNonQuery(); vSqlCommand.Connection.Close(); } }
/// <summary> /// Loads the <see cref="SqlCommand"/> parameters with values from an <see cref="Friend"/>. /// </summary> /// <param name="aSqlCommand">A <see cref="SqlDataReader"/> argument.</param> /// <param name="aFanatic">A <see cref="Friend"/> argument.</param> public static void ObjectToData(SqlCommand aSqlCommand, Friend aFriend) { aSqlCommand.Parameters.AddWithValue("@FAN1Key", aFriend.Fan1Key); aSqlCommand.Parameters.AddWithValue("@FAN2Key", aFriend.Fan2Key); aSqlCommand.Parameters.AddWithValue("@FRDDateEstablished", DateTime.Parse(aFriend.FriendDateEstablished)); aSqlCommand.Parameters.AddWithValue("@RELKey", aFriend.RelationshipType); }
/// <summary> /// The overloaded Load method that will return a specific <see cref="Friend"/>, with keys in the <c>aFriend</c> argument. /// </summary> /// <param name="aFriend">A <see cref="Friend"/>.</param> /// <exception cref="ArgumentNullException">If <c>aFriend</c> argument is <c>null</c>.</exception> /// <exception cref="Exception">If no record is found.</exception> public static void Load(Friend aFriend) { if (aFriend == null) { throw new ArgumentNullException("aFriend"); } using (var vSqlCommand = new SqlCommand() { CommandType = CommandType.Text, Connection = new SqlConnection(Connection.Instance.SqlConnectionString) }) { var vStringBuilder = BuildSQL(); vStringBuilder.AppendLine("and t1.FAN_Key = @FAN1Key"); vStringBuilder.AppendLine("and t2.FAN_Key = @FAN2Key"); vSqlCommand.Parameters.AddWithValue("@FAN1Key", aFriend.Fan1Key); vSqlCommand.Parameters.AddWithValue("@FAN2Key", aFriend.Fan2Key); vSqlCommand.CommandText = vStringBuilder.ToString(); vSqlCommand.Connection.Open(); using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader()) { if (!vSqlDataReader.HasRows) { throw new Exception(String.Format("Expected Friendship not found: FAN_Key1 = {0}, FAN_Key2 = {1}", aFriend.Fan1Key, aFriend.Fan2Key)); } vSqlDataReader.Read(); DataToObject(aFriend, vSqlDataReader, true); vSqlDataReader.Close(); } vSqlCommand.Connection.Close(); } }
/// <summary> /// The overloaded Load method that will fill the <c>FriendList</c> property a <see cref="FriendCollection"/> object as an /// ordered <c>List</c> of <see cref="Friend"/>, filtered by the filter properties of the passed <see cref="FriendCollection"/>. /// </summary> /// <param name="aFriendCollection">The <see cref="FriendCollection"/> object that must be filled.</param> /// <remarks> /// The filter properties of the <see cref="FriendCollection"/> must be correctly completed by the calling application. /// </remarks> /// <exception cref="ArgumentNullException">If <c>aFriendCollection</c> argument is <c>null</c>.</exception> public static void Load(FriendCollection aFriendCollection) { if (aFriendCollection == null) { throw new ArgumentNullException("aFriendCollection"); } using (var vSqlCommand = new SqlCommand() { CommandType = CommandType.Text, Connection = new SqlConnection(Connection.Instance.SqlConnectionString) }) { var vStringBuilder = BuildSQL(); if (aFriendCollection.IsFiltered) { if (aFriendCollection.FriendFilter.FriendshipFilter.Fan1Key > 0) { vStringBuilder.AppendLine("and (t1.FAN_Key = @FAN1Key or t2.FAN_Key = @FAN1Key)"); vSqlCommand.Parameters.AddWithValue("@FAN1Key", aFriendCollection.FriendFilter.FriendshipFilter.Fan1Key); } if (aFriendCollection.FriendFilter.FriendshipFilter.Fan2Key > 0) { vStringBuilder.AppendLine("and (t2.FAN_Key = @FAN2Key or t2.FAN_Key = @FAN2Key)"); vSqlCommand.Parameters.AddWithValue("@FAN2Key", aFriendCollection.FriendFilter.FriendshipFilter.Fan2Key); } if (aFriendCollection.FriendFilter.FriendshipFilter.Fan1Name != null) { vStringBuilder.AppendFormat("and (t1.FAN_Name like '%{0}%' or t2.FAN_Name like '%{0}%')", aFriendCollection.FriendFilter.FriendshipFilter.Fan1Name); } if (aFriendCollection.FriendFilter.FriendshipFilter.Fan2Name != null) { vStringBuilder.AppendFormat("and (t1.FAN_Name like '%{0}%' or t2.FAN_Name like '%{0}%')", aFriendCollection.FriendFilter.FriendshipFilter.Fan2Name); } } vStringBuilder.AppendLine("order by t3.FRD_DateEstablished"); vSqlCommand.CommandText = vStringBuilder.ToString(); vSqlCommand.Connection.Open(); using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader()) { while (vSqlDataReader.Read()) { var vFriend = new Friend(); DataToObject(vFriend, vSqlDataReader, false); aFriendCollection.FriendList.Add(vFriend); } vSqlDataReader.Close(); } vSqlCommand.Connection.Close(); } }
/// <summary> /// Gets a specified <see cref="Friend"/> by key. /// </summary> /// <param name="aFanToken">A <see cref="FanToken"/> object used for Access Control.</param> /// <param name="aFriend"><see cref="Friend"/> object.</param> public static void GetFriend(FanToken aFanToken, Friend aFriend) { FanCallHandler.ServiceCall<Friend>(aFanToken, "GetFriend", aFriend); }