public Ma_AddAgreementManager(ref Dictionary <int, AddAgreement> p_all_agreements, CreateFormalMessageRequest p_send_formal_messages_to_user
                                      , DB_IsThereUser p_is_there_user, DB_AddToFriends p_add_to_friends, DB_AreFriends p_are_friends, DB_CreateAddAgreement p_create_add_agreement
                                      , DB_RemoveAgreement p_remove_agreement, IsLoggedIn p_is_logged_in, StartClientFriendListChangedInformDialog p_start_client_friend_list_changed_inform_dialog
                                      , ReloadFriendList p_reload_friend_list, GetOnlineUserFriendList p_get_online_user_friend_list, GetUserStatus p_get_user_status, AddAgreementDone p_add_agreement_done
                                      , GetAllAdAgreements p_get_all_agreements, StartClientInvitedAgreementInform p_start_client_invited_agreement_inform)
        {
            base.BaseConstruct(TypeOfAgreement.Add, 1, p_send_formal_messages_to_user, p_is_there_user, p_start_client_invited_agreement_inform, p_is_logged_in);

            add_to_friends       = p_add_to_friends;
            are_friends          = p_are_friends;
            create_add_agreement = p_create_add_agreement;
            remove_agreement     = p_remove_agreement;
            start_client_friend_list_changed_inform_dialog = p_start_client_friend_list_changed_inform_dialog;
            reload_friend_list          = p_reload_friend_list;
            get_online_user_friend_list = p_get_online_user_friend_list;
            get_user_status             = p_get_user_status;
            add_agreement_done          = p_add_agreement_done;
            get_all_agreements          = p_get_all_agreements;

            all_agreements = p_all_agreements;

            List <Agreement> all_db_agreements = new List <Agreement>();
            int h = 0;

            while (h < 4)
            {
                try
                {
                    all_db_agreements = get_all_agreements();
                    h = 0;
                    break;
                }
                catch
                {
                    h++;
                    continue;
                }
            }
            if (h > 3)
            {
                Console.WriteLine("could not get all agreements from DB");
                try
                {
                    Environment.Exit(4);
                }
                catch
                {
                }
                Thread.CurrentThread.Abort();
            }
            foreach (Agreement t_agreement in all_db_agreements)
            {
                AddAgreement temp_add_agreement = new AddAgreement(t_agreement.Get_agreement_id, t_agreement.Get_inviting_user_name, t_agreement.Get_invited_user_name, new RemoveAgr(AgreementRemoveItselfRequest)
                                                                   , new DB_AddToFriends(add_to_friends), new DB_AreFriends(are_friends), new DB_CreateAddAgreement(create_add_agreement), new DB_RemoveAgreement(remove_agreement)
                                                                   , new CreateFormalMessageRequest(Ma_SendFormalMessageToUser), new DB_IsThereUser(is_there_user), new GetUserStatus(Ma_GetUserStatus), new IsLoggedIn(Ma_IsLoggedIn), new StartClientFriendListChangedInformDialog(Ma_StartClientFriendListChangedInformDialog)
                                                                   , new ReloadFriendList(Ma_ReloadFriendList), new GetOnlineUserFriendList(Ma_GetOnlineUserFriendList), new AddAgreementDone(add_agreement_done));
                all_agreements.Add(t_agreement.Get_agreement_id, temp_add_agreement);
            }
        }
 public override bool Equals(object obj)
 {
     try
     {
         AddAgreement add_agreement = (AddAgreement)obj;
         if ((add_agreement.starter_user_name == starter_user_name && add_agreement.all_users_invited.ElementAt(0).Key == all_users_invited.ElementAt(0).Key) ||
             (add_agreement.all_users_invited.ElementAt(0).Key == starter_user_name && add_agreement.starter_user_name == all_users_invited.ElementAt(0).Key))
         {
             return(true);
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public Se_BaseBooleanFunctionResult Create(string p_starter_user_name, string p_invited_user_name)
        {
            bool is_there_user_answer = false;
            int  i = 0;

            while (i < 3)
            {
                try
                {
                    is_there_user_answer = is_there_user(p_invited_user_name);
                    i = 0;
                    break;
                }
                catch
                {
                    i++;
                    continue;
                }
            }
            if (i > 2)
            {
                return(new Se_BooleanFunctionRejResult("a problem occured. please try again."));
            }
            if (!is_there_user_answer)
            {
                return(new Se_BooleanFunctionRejResult("user with username: '******' doesnt exist"));
            }

            if (p_starter_user_name == p_invited_user_name)
            {
                return(new Se_BooleanFunctionRejResult("your request for adding '" + p_invited_user_name + "' was not valid"));
            }

            bool are_friends_answer = false;

            i = 0;
            while (i < 3)
            {
                try
                {
                    are_friends_answer = are_friends(p_starter_user_name, p_invited_user_name);
                    i = 0;
                    break;
                }
                catch
                {
                    i++;
                    continue;
                }
            }
            if (i > 2)
            {
                return(new Se_BooleanFunctionRejResult("a problem occured. please try again."));
            }
            if (are_friends_answer)
            {
                return(new Se_BooleanFunctionRejResult("your request for adding '" + p_invited_user_name + "' was not valid because he/she is in your friends list"));
            }

            int          random_agreement_id = HelperFunctions.GetGUID();
            AddAgreement temp_add_agreement  = new AddAgreement(random_agreement_id, p_starter_user_name, p_invited_user_name, new RemoveAgr(AgreementRemoveItselfRequest)
                                                                , new DB_AddToFriends(add_to_friends), new DB_AreFriends(are_friends), new DB_CreateAddAgreement(create_add_agreement), new DB_RemoveAgreement(remove_agreement)
                                                                , new CreateFormalMessageRequest(Ma_SendFormalMessageToUser), new DB_IsThereUser(is_there_user), new GetUserStatus(Ma_GetUserStatus), new IsLoggedIn(Ma_IsLoggedIn), new StartClientFriendListChangedInformDialog(Ma_StartClientFriendListChangedInformDialog)
                                                                , new ReloadFriendList(Ma_ReloadFriendList), new GetOnlineUserFriendList(Ma_GetOnlineUserFriendList), new AddAgreementDone(add_agreement_done));

            if (all_agreements.ContainsValue(temp_add_agreement))
            {
                return(new Se_BooleanFunctionRejResult("This agreement already exist"));
            }

            i = 0;
            while (i < 3)
            {
                try
                {
                    create_add_agreement(p_starter_user_name, p_invited_user_name, random_agreement_id);
                    i = 0;
                    break;
                }
                catch
                {
                    i++;
                    continue;
                }
            }
            if (i > 2)
            {
                return(new Se_BooleanFunctionRejResult("a problem occured. please try again."));
            }

            all_agreements.Add(random_agreement_id, temp_add_agreement);

            if (is_logged_in(p_invited_user_name))
            {
                start_client_invited_agreement_inform(p_invited_user_name, random_agreement_id);
            }

            return(new Se_BooleanFunctionAccResult());
        }