/// <summary>
        /// Gets the user's id and return it. Also, set all the user's data into
        /// AppManeger, if, the user exist in the database. Otherwise, only returns id = 0.
        /// </summary>
        /// <param name="email">Email.</param>
        /// <param name="callback">Callback.</param>
        public static void GetUserId(string email, System.Action <string> callback)
        {
            AppManeger.isLoadingData = true;             // processing data
            WWWForm form = new WWWForm();

            form.AddField("emailPost", email);
            form.AddField("functionName", "GetUserId");
            WWW www = new WWW(Urls.getMethodsUrl, form);

            UtilMethods.util.GetData(www, (myvalue) => {
                string[] dicIndex = DataStructure.userDataStructure;
                List <Dictionary <string, string> > dic = new List <Dictionary <string, string> >();
                dic = ConstructListOfDictionary(myvalue, dicIndex);                // This list contains only one row

                //===== Find and get the id if exist =====
                string id = "0";                 //default valeu

                if (dic[0].ContainsKey("ID"))
                {
                    dic[0].TryGetValue("ID", out id);
                    AppManeger.SetUserVariables(dic[0]);                     // Send the dic to set on the User variables.
                }

                //=========================================
                AppManeger.isLoadingData = false; //finish processing data
                callback(id);                     // Return only the id
            });
        }
Example #2
0
    private float waitForCheckDatabase = 300f;     // 5 mins

    void Awake()
    {
        if (instance == null)
        {
            DontDestroyOnLoad(gameObject);
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }
    }
        /// <summary>
        /// Verify and updates the users database and AppManeger data if necessary. Enter with the user id for identification.
        /// </summary>
        /// <param name="id">Identifier.</param>
        /// <param name="updateName">Update name.</param>
        /// <param name="updateAge">Update age.</param>
        /// <param name="updateGender">Update gender.</param>
        /// <param name="callback">Callback.</param>
        public static void UpdateUsersDatabase(string id, string updateName, string updateAge, string updateGender,
                                               System.Action <string> callback)
        {
            bool update   = false;
            bool nameUp   = string.Equals(updateName, AppManeger.instance.userName, StringComparison.OrdinalIgnoreCase);
            bool ageUp    = string.Equals(updateAge, AppManeger.instance.userAge.ToString(), StringComparison.OrdinalIgnoreCase);
            bool genderUp = string.Equals(updateGender, AppManeger.instance.userGender.ToString(), StringComparison.OrdinalIgnoreCase);

            if (!nameUp || !ageUp || !genderUp)
            {
                update = true;
            }

            if (update)
            {
                WWWForm form = new WWWForm();
                form.AddField("idPost", id);
                form.AddField("namePost", updateName);
                form.AddField("agePost", updateAge);
                form.AddField("genderPost", updateGender);
                form.AddField("functionName", "UpdateToUsersDatabase");

                WWW www = new WWW(Urls.updatedataUrl, form);
                UtilMethods.util.GetData(www, (data) => {
                    if (data == "Success")
                    {
                        // Converts the first letter to Captal, to avoid errors
                        updateGender = char.ToUpper(updateGender[0]) + updateGender.Substring(1);
                        Dictionary <string, string> dic = new Dictionary <string, string>();
                        //keys: {Name, Age, Gender}
                        dic.Add("Name", updateName);
                        dic.Add("Age", updateAge);
                        dic.Add("Gender", updateGender);

                        AppManeger.SetUserVariables(dic);
                    }

                    callback(data);
                });
            }
            else
            {
                callback("not necessary");
            }
        }
Example #4
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");
            }
        }