Ejemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Edit friend. </summary>
        ///
        /// <remarks>   , 16/08/2018. </remarks>
        ///
        /// <param name="friends">      The friends. </param>
        /// <param name="friend">       The friend. </param>
        /// <param name="comparison">   The comparison. </param>
        ///
        /// <returns>   A List&lt;Friend&gt; </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static List <Friend> EditFriend(List <Friend> friends, Friend friend, string comparison)
        {
            //first do a date check to see if it is valid
            if (DateCheck(friend.BirthDay, friend.BirthMonth))
            {
                foreach (Friend f in friends)
                {
                    //ToUpper is used so capitalization isn't an issue when comparing
                    if (f.Name.ToUpper() == comparison.ToUpper())
                    {
                        f.Name       = friend.Name;
                        f.Likes      = friend.Likes;
                        f.Dislikes   = friend.Dislikes;
                        f.BirthDay   = friend.BirthDay;
                        f.BirthMonth = friend.BirthMonth;

                        //update the csv file
                        CsvHandler write = new CsvHandler();
                        write.AlterCsv(friends);
                        break;
                    }
                }
            }
            else
            {
                //show a message if the friend try to be edited does not exist
                MessageBox.Show("The Birthday you have entered is invalid, please try again", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            return(friends);
        }
Ejemplo n.º 2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Deletes the friend. </summary>
        ///
        /// <remarks>   , 16/08/2018. </remarks>
        ///
        /// <param name="friends">  The friends. </param>
        /// <param name="name">     The name. </param>
        ///
        /// <returns>   A List&lt;Friend&gt; </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static List <Friend> DeleteFriend(List <Friend> friends, string name)
        {
            //Get all the data from the text boxes and update the list
            foreach (Friend f in friends)
            {
                if (f.Name == name)
                {
                    //remove the friend from the list
                    friends.Remove(f);

                    //update the csv file using the updated list
                    CsvHandler write = new CsvHandler();
                    write.AlterCsv(friends);

                    //break out of the for loop because the friend has been deleted
                    break;
                }
            }
            return(friends);
        }