Exemple #1
0
    void PrefsResult(Dictionary <string, string> result)
    {
        if (result.ContainsKey("Error"))           // means that this id is not within the userprefs dataBase.

        {
            Debug.Log("User need to be insert into UsersPrefs " + result["Error"]);
            SetSexAndAgePanelOn();
        }
        else if (result.ContainsKey("ID"))
        {
            AppManeger.SetUsersPrefsVariables(result); // set the results into the global variables.

            GoToCheersPanel();                         // Means the user has everyting setted;
        }
        else                                           // For safety in the case of conection failure;

        {
            Debug.Log("Conection error trying to get UserPrefsData");
        }
    }
        /// <summary>
        ///  Verify and updates the users prefs database and AppManeger data if necessary. Enter with the user id for identification.
        /// </summary>
        /// <param name="id">Identifier.</param>
        /// <param name="smoke">Smoke.</param>
        /// <param name="minAge">Minimum age.</param>
        /// <param name="maxAge">Max age.</param>
        /// <param name="habit">Habit.</param>
        /// <param name="wantToMeetMan">true/false.</param>
        /// <param name="wantToMeetWoman">true/false.</param>
        /// <param name="callback">Callback.</param>
        public static void UpdateUsersPrefsDatabase(string id, string updateSmoke, string updateMinAge, string updateMaxAge,
                                                    string updateHabit, string updateWantToMeetMan, string updateWantToMeetWoman, System.Action <string> callback)
        {
            bool update = false;

            bool smokeNotUp  = string.Equals(updateSmoke, AppManeger.instance.isSmoke.ToString(), StringComparison.OrdinalIgnoreCase);
            bool minAgeNotUp = string.Equals(updateMinAge, AppManeger.instance.wantAge[0].ToString(), StringComparison.OrdinalIgnoreCase);
            bool maxAgeNotUp = string.Equals(updateMaxAge, AppManeger.instance.wantAge[1].ToString(), StringComparison.OrdinalIgnoreCase);
            bool habitNotUp  = string.Equals(updateHabit, AppManeger.instance.yourHabit.ToString(), StringComparison.OrdinalIgnoreCase);
            bool manNotUp    = true;                                               // Assume that there was no change in this status
            bool womanNotUp  = true;                                               // Assume that there was no change in this status

            if (AppManeger.instance.wantToMeet.Contains(AppManeger.Gender.Female)) //The list contains woman
            {
                if (!Convert.ToBoolean(updateWantToMeetWoman))
                {
                    womanNotUp = false;
                }
            }
            else
            {
                if (Convert.ToBoolean(updateWantToMeetWoman))
                {
                    womanNotUp = false;
                }
            }

            if (AppManeger.instance.wantToMeet.Contains(AppManeger.Gender.Male))               //The list contains man
            {
                if (!Convert.ToBoolean(updateWantToMeetMan))
                {
                    manNotUp = false;
                }
            }
            else
            {
                if (Convert.ToBoolean(updateWantToMeetMan))
                {
                    manNotUp = false;
                }
            }

            if (!smokeNotUp || !minAgeNotUp || !maxAgeNotUp || !habitNotUp || !manNotUp || !womanNotUp)
            {
                update = true;
            }

            if (update)
            {
                WWWForm form = new WWWForm();
                form.AddField("idPost", id);
                form.AddField("smokePost", updateSmoke);
                form.AddField("minAgePost", updateMinAge);
                form.AddField("maxAgePost", updateMaxAge);
                form.AddField("habitPost", updateHabit);
                form.AddField("wantManPost", updateWantToMeetMan);
                form.AddField("wantWomanPost", updateWantToMeetWoman);
                form.AddField("functionName", "UpdateToUsersPrefsDatabase");

                WWW www = new WWW(Urls.updatedataUrl, form);
                UtilMethods.util.GetData(www, (data) => {
                    if (data == "Success")
                    {
                        Dictionary <string, string> dic = new Dictionary <string, string>();
                        //keys: {Smoke, MinAge, MaxAge, Habit, WantToMeetMan, WantToMeetWoman}
                        dic.Add("Smoke", updateSmoke);
                        dic.Add("MinAge", updateMinAge);
                        dic.Add("MaxAge", updateMaxAge);
                        dic.Add("Habit", updateHabit);
                        dic.Add("WantToMeetMan", updateWantToMeetMan);
                        dic.Add("WantToMeetWoman", updateWantToMeetWoman);

                        AppManeger.SetUsersPrefsVariables(dic);
                    }

                    callback(data);
                });
            }
            else
            {
                callback("not necessary");
            }
        }