Ejemplo n.º 1
0
    IEnumerator CreateTeamCoroutine(string name)
    {
        LoadAlert.Instance.StartLoad("Creating " + name + "...", null, -1);

        ParseACL acl = new ParseACL(ParseUser.CurrentUser);

        ParseRole role = new ParseRole(name, acl);

        role.Users.Add(ParseUser.CurrentUser);

        User.CurrentUser.CompanyName = name;

        Task task = role.SaveAsync();

        while (!task.IsCompleted)
        {
            yield return(null);
        }

        if (task.IsFaulted || task.Exception != null)
        {
            Debug.Log("error:\n" + task.Exception.ToString());
        }
        else
        {
            task = ParseUser.CurrentUser.SaveAsync();

            while (!task.IsCompleted)
            {
                yield return(null);
            }

            if (task.IsFaulted || task.Exception != null)
            {
                Debug.Log("error:\n" + task.Exception.ToString());
            }
            else
            {
                TeamUpdated(role);
            }
        }
    }
        private async Task SignUp(int registrationTestScore)
        {
            ParseRole adminRole = await Constants.Role.Admin();

            var user = new ParseUser()
            {
                Username = MyRegistrationInfo.Email.ToLower(),
                Password = MyRegistrationInfo.Password,
                Email    = MyRegistrationInfo.Email.ToLower(),
            };
            await user.SignUpAsync();

            ParseRole tutorRole = await Constants.Role.Tutor();

            tutorRole.Users.Add(user);
            await tutorRole.SaveAsync();

            PrivateTutorData privateTutorData = new PrivateTutorData();

            privateTutorData.BaseUserId           = user.ObjectId;
            privateTutorData.Students             = new List <PublicUserData>();
            privateTutorData.RequestsFromStudents = new List <PublicUserData>();
            privateTutorData.Blocked = new List <ParseUser>();
            privateTutorData.ACL     = new ParseACL(user);
            privateTutorData.ACL.SetRoleReadAccess(adminRole, true);
            privateTutorData.ACL.SetRoleWriteAccess(adminRole, true);
            await privateTutorData.SaveAsync();

            Tutor tutor = new Tutor();

            tutor.NumQuestionsCreated  = 0;
            tutor.NumQuestionsReviewed = 0;
            tutor.BaseUserId           = user.ObjectId;
            tutor.Biography            = "";
            tutor.PrivateTutorData     = privateTutorData;
            tutor.ACL = new ParseACL();
            tutor.ACL.PublicReadAccess  = true;
            tutor.ACL.PublicWriteAccess = false;
            tutor.ACL.SetWriteAccess(user, true);
            tutor.ACL.SetRoleReadAccess(adminRole, true);
            tutor.ACL.SetRoleWriteAccess(adminRole, true);
            await tutor.SaveAsync();

            PublicUserData publicUserData = new PublicUserData();

            publicUserData.UserType              = Constants.UserType.TUTOR;
            publicUserData.DisplayName           = MyRegistrationInfo.FirstName.Trim() + " " + MyRegistrationInfo.LastName.Trim();
            publicUserData.SearchableDisplayName = MyRegistrationInfo.FirstName.Trim().ToLower() + MyRegistrationInfo.LastName.Trim().ToLower();
            publicUserData.BaseUserId            = user.ObjectId;
            publicUserData.Tutor = tutor;
            string path = HttpContext.Current.Server.MapPath("~/Images/default_prof_pic.png");

            byte[] pic = File.ReadAllBytes(path);
            publicUserData.ProfilePic            = new ParseFile("default-profile-pic", pic);
            publicUserData.ACL                   = new ParseACL();
            publicUserData.ACL.PublicReadAccess  = true;
            publicUserData.ACL.PublicWriteAccess = false;
            publicUserData.ACL.SetWriteAccess(user, true);
            publicUserData.ACL.SetRoleReadAccess(adminRole, true);
            publicUserData.ACL.SetRoleWriteAccess(adminRole, true);
            await publicUserData.SaveAsync();

            user["registrationTestScore"] = registrationTestScore;
            user.ACL = new ParseACL(user);
            user.ACL.SetRoleReadAccess(adminRole, true);
            user["publicUserData"] = publicUserData;
            //user.phoneNumber = tbPhoneNumber.Text;
            //user.zipCode = tbZipCode.Text;
            //user.address = tbStreetAddress.Text;
            //user.address2 = tbAddress2.Text;
            //user.city = tbCity.Text;
            //user.state = ddState.SelectedValue;
            await user.SaveAsync();
        }