//----------------------------------------------------------------------------------------------------------------------------------------------//

    private void RemoveUserFromCircle(string circleRef, string userRef)
    {
        DataRef.User(userRef).Child("Circles").Child(circleRef).RemoveValueAsync().ContinueWith(async(task) => {
            await new WaitForUpdate();
            if (task.IsFaulted || task.IsCanceled)
            {
                print(task.Exception);
                return;
            }
        });

        DataRef.Circles(circleRef).Child("Members").Child(userRef).RemoveValueAsync().ContinueWith(async(task) => {
            await new WaitForUpdate();
            if (task.IsFaulted || task.IsCanceled)
            {
                print(task.Exception);
                return;
            }
        });

        DataRef.Circles(circleRef).Child("TotalMembers").GetValueAsync().ContinueWith(async(task) => {
            await new WaitForUpdate();
            if (task.IsFaulted || task.IsCanceled)
            {
                print(task.Exception);
                return;
            }
            DataSnapshot snapshot = task.Result;

            int currentMembers = int.Parse(snapshot.Value.ToString());
            int newMembers     = currentMembers - 1;

            SetTotalMembers(circleRef, newMembers);
        });
    }
Exemple #2
0
    //----------------------------------------------------------------------------------------------------------------------------------------------//

    public void GetUser(string id)
    {
        userID = id;

        DataRef.User(id).Child("Username").GetValueAsync().ContinueWith(async(task) => {
            await new WaitForUpdate();
            DataSnapshot snapshot = task.Result;

            userName = snapshot.Child("Username").Value.ToString();
        });
    }
    //----------------------------------------------------------------------------------------------------------------------------------------------//

    // 0 = top message
    // 1 = type message
    // 2 = timestamp
    // 3 = picture
    // 4 = project link

    //----------------------------------------------------------------------------------------------------------------------------------------------//

    public void AssignDonation(DataSnapshot snap)
    {
        DataRef.User(snap.Child("UserID").Value.ToString()).GetValueAsync().ContinueWith(async(task) => {
            await new WaitForUpdate();
            if (task.IsFaulted || task.IsCanceled)
            {
                return;
            }
            DataSnapshot snapshot = task.Result;

            Sprite image = Resources.Load <Sprite> ("2D/Animals/" + snapshot.Child("PictureID").Value.ToString());
            this.transform.GetChild(3).GetChild(0).GetChild(0).GetComponent <Image> ().sprite = image;
        });

        DataRef.Projects(snap.Child("Reference").Value.ToString()).GetValueAsync().ContinueWith(async(task) => {
            await new WaitForUpdate();
            if (task.IsFaulted || task.IsCanceled)
            {
                return;
            }
            DataSnapshot snapshot = task.Result;

            this.transform.GetChild(0).GetComponent <Text> ().text = snap.Child("Donor").Value.ToString();
            this.transform.GetChild(1).GetComponent <Text> ().text = "Donated $" + snap.Child("Amount").Value.ToString() + " to " + snapshot.Child("ProjectName").Value.ToString();
            this.transform.GetChild(2).GetComponent <Text> ().text = snap.Child("Date").Value.ToString();

            string pName             = snapshot.Child("ProjectName").Value.ToString();
            string gName             = snapshot.Child("Group").Value.ToString();
            string pRef              = "(" + gName + ") " + pName;
            string description       = snapshot.Child("ProjectDescription").Value.ToString();
            string fundingGoal       = snapshot.Child("FundingGoal").Value.ToString();
            string fundingAmount     = snapshot.Child("FundingAmount").Value.ToString();
            string location          = snapshot.Child("Tags").Child("Location").Value.ToString();
            string pictureID         = snapshot.Child("PictureID").Value.ToString();
            List <string> categories = new List <string> ();
            foreach (DataSnapshot s1 in snapshot.Child("Tags").Child("Categories").Children)
            {
                categories.Add(s1.Value.ToString());
            }
            List <string> goalTitles = new List <string> ();
            foreach (DataSnapshot s2 in snapshot.Child("Measurements").Children)
            {
                goalTitles.Add(s2.Child("Title").Value.ToString());
            }
            List <string> goalValues = new List <string> ();
            foreach (DataSnapshot s3 in snapshot.Child("Measurements").Children)
            {
                goalValues.Add(s3.Child("Value").Value.ToString());
            }

            this.transform.GetChild(4).GetComponent <ProjectInformation> ().SetInformation(pRef, gName, pName, description, fundingGoal, fundingAmount, location, categories, goalTitles, goalValues, pictureID);
        });
    }
    //----------------------------------------------------------------------------------------------------------------------------------------------//

    public void AssignInfo(string userReference, string date, string comment)
    {
        DataRef.User(userReference).GetValueAsync().ContinueWith(async(task) => {
            await new WaitForUpdate();
            DataSnapshot snapshot = task.Result;

            usernameField.text    = snapshot.Child("Username").Value.ToString();
            Sprite image          = Resources.Load <Sprite> ("2D/Animals/" + snapshot.Child("PictureID").Value.ToString());
            pictureIDField.sprite = image;
            dateField.text        = date;
            commentField.text     = comment;
        });
    }
    //----------------------------------------------------------------------------------------------------------------------------------------------//

    public void AssignNewDonor(DataSnapshot snap)
    {
        DataRef.User(snap.Child("UserID").Value.ToString()).GetValueAsync().ContinueWith(async(task) => {
            await new WaitForUpdate();
            if (task.IsFaulted || task.IsCanceled)
            {
                return;
            }
            DataSnapshot snapshot = task.Result;

            Sprite image = Resources.Load <Sprite> ("2D/Animals/" + snapshot.Child("PictureID").Value.ToString());
            this.transform.GetChild(3).GetChild(0).GetChild(0).GetComponent <Image> ().sprite = image;
        });

        this.transform.GetChild(0).GetComponent <Text> ().text = snap.Child("Name").Value.ToString();
        this.transform.GetChild(2).GetComponent <Text> ().text = snap.Child("Date").Value.ToString();
    }
    //----------------------------------------------------------------------------------------------------------------------------------------------//

    public void RemoveFromAllCircles(string uid)
    {
        DataRef.User(uid).Child("Circles").GetValueAsync().ContinueWith(async(task) => {
            await new WaitForUpdate();
            if (task.IsFaulted || task.IsCanceled)
            {
                print(task.Exception);
                return;
            }
            DataSnapshot snapshot = task.Result;

            foreach (DataSnapshot snap in snapshot.Children)
            {
                string circleRef = snap.Value.ToString();
                RemoveUser(circleRef, uid);
            }
        });
    }
    //----------------------------------------------------------------------------------------------------------------------------------------------//

    public void ClearData(string uid)
    {
        DataRef.User(uid).RemoveValueAsync().ContinueWith(async(task) => {
            if (task.IsFaulted)
            {
                await new WaitForUpdate();
                //debug.message = "Process Faulted (Clearing Data)";
                messaging.SetMessage("Process Cancelled.", "Your data was not cleared due to the process being cancelled part way through.", true);
                return;
            }
            if (task.IsFaulted)
            {
                await new WaitForUpdate();
                //debug.message = "Process Canceled (Clearing Data)";
                messaging.SetMessage("An error has been encountered.", "Your data has not been cleared due to the following error: " + task.Exception.GetBaseException(), true);
                return;
            }
            await new WaitForUpdate();
            //debug.message = "Data Cleared";
        });
    }
    //----------------------------------------------------------------------------------------------------------------------------------------------//

    private void InstantiateMember(string userReference)
    {
        GameObject com = Instantiate(memberPrefab, Vector3.zero, Quaternion.identity) as GameObject;

        com.transform.SetParent(membersContent);
        com.transform.localScale = new Vector3(1, 1, 1);

        DataRef.User(userReference).GetValueAsync().ContinueWith(async(task) => {
            await new WaitForUpdate();
            DataSnapshot snapshot = task.Result;

            string username  = snapshot.Child("Username").Value.ToString();
            string balance   = snapshot.Child("Balance").Value.ToString();
            string pictureID = snapshot.Child("PictureID").Value.ToString();

            com.name = username;
            com.transform.GetChild(1).GetComponent <Text> ().text = username;
            com.transform.GetChild(2).GetComponent <Text> ().text = userReference;
            com.transform.GetChild(3).GetComponent <Text> ().text = balance;
            Sprite img = Resources.Load <Sprite> ("2D/Animals/" + pictureID);
            com.transform.GetChild(0).GetChild(0).GetComponent <Image> ().sprite = img;
        });
    }