예제 #1
0
        /// <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
            });
        }
예제 #2
0
        /// <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");
            }
        }