Beispiel #1
0
 protected void grdTutors_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "Message")
     {
         int    index         = Convert.ToInt32(e.CommandArgument);
         string TheirObjectId = (string)grdTutors.DataKeys[index]["ObjectId"];
         Session["ConversationUserId"] = TheirObjectId;
         Response.Redirect("Messages");
     }
     else if (e.CommandName == "SeeProfile")
     {
         int    index         = Convert.ToInt32(e.CommandArgument);
         string TheirObjectId = (string)grdTutors.DataKeys[index]["ObjectId"];
         Response.Redirect("Profile.aspx?tutorId=" + TheirObjectId);
     }
     else if (e.CommandName == "ToggleModerator")
     {
         string         TheirObjectId = e.CommandArgument.ToString();
         PublicUserData pud           = AsyncHelpers.RunSync(() => PublicUserData.GetById(TheirObjectId));
         if (pud.UserType == Constants.UserType.TUTOR)
         {
             pud.UserType = Constants.UserType.MODERATOR;
         }
         else if (pud.UserType == Constants.UserType.MODERATOR)
         {
             pud.UserType = Constants.UserType.TUTOR;
         }
         AsyncHelpers.RunSync(() => pud.SaveAsync());
     }
     AsyncHelpers.RunSync(LoadEverything);
 }
        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();
        }
        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();
        }