Exemple #1
0
        public void AssignRole()
        {
            UserManagementService ums    = new UserManagementService();
            Result <object>       result = ums.AssignRole("*****@*****.**", 1);

            Console.WriteLine(result.message);
        }
Exemple #2
0
        protected void btnSaveRoles_Click(object sender, EventArgs e)
        {
            if (IsLoggedIn)
            {
                String message                = string.Empty;
                IUserManagementService um     = new UserManagementService();
                Result <OlescUser>     result = um.GetUser(hfUserEmail.Value);
                if (result.isSuccess)
                {
                    if (chkrole.Items[0].Selected && !AccessManagementValidator.UserHasRole(result.resultObject, Roles.Admin))
                    {
                        // selected student box AND he is not a student already
                        Result <object> AssignRole = um.AssignRole(hfUserEmail.Value, (int)Roles.Admin);

                        if (AssignRole.isSuccess)
                        {
                            message += "\nAdmin role added";
                        }

                        else
                        {
                            message += "\nFailed to add Admin role";
                        }
                    }

                    if (!chkrole.Items[0].Selected && AccessManagementValidator.UserHasRole(result.resultObject, Roles.Admin))
                    {
                        // UNselected student box AND he IS a student then remove this role
                        Result <object> DeAssignRole = um.DeAssignRole(hfUserEmail.Value, (int)Roles.Admin);

                        if (DeAssignRole.isSuccess)
                        {
                            message += "\nAdmin role deassigned successfuly";
                        }

                        else
                        {
                            message += "\nFailed to deassign Admin role";
                        }
                    }

                    if (chkrole.Items[1].Selected && !AccessManagementValidator.UserHasRole(result.resultObject, Roles.Student))
                    {
                        // selected student box AND he is not a student already
                        Result <object> AssignRole = um.AssignRole(hfUserEmail.Value, (int)Roles.Student);

                        if (AssignRole.isSuccess)
                        {
                            message += "\nStudent role added";
                        }

                        else
                        {
                            message += "\nFailed to add student role";
                        }
                    }

                    if (!chkrole.Items[1].Selected && AccessManagementValidator.UserHasRole(result.resultObject, Roles.Student))
                    {
                        // UNselected student box AND he IS a student then remove this role
                        Result <object> DeAssignRole = um.DeAssignRole(hfUserEmail.Value, (int)Roles.Student);

                        if (DeAssignRole.isSuccess)
                        {
                            message += "\nStudent role deassigned successfuly";
                        }

                        else
                        {
                            message += "\nFailed to deassign student role";
                        }
                    }

                    if (chkrole.Items[2].Selected && !AccessManagementValidator.UserHasRole(result.resultObject, Roles.Tutor))
                    {
                        //selected tutor box AND he is not a tutor already
                        Result <object> AssignRole = um.AssignRole(hfUserEmail.Value, (int)Roles.Tutor);

                        if (AssignRole.isSuccess)
                        {
                            message += "\nTutor role added";
                        }

                        else
                        {
                            message += "\nFailed to add tutor role";
                        }
                    }

                    if (!chkrole.Items[2].Selected && AccessManagementValidator.UserHasRole(result.resultObject, Roles.Tutor))
                    {
                        // UNselected tutor box AND he IS a Tutor then remove this role
                        Result <object> DeAssignRole = um.DeAssignRole(hfUserEmail.Value, (int)Roles.Tutor);

                        if (DeAssignRole.isSuccess)
                        {
                            message += "\nTutor role deassigned successfuly";
                        }

                        else
                        {
                            message += "\nFailed to deassign Tutor role";
                        }
                    }
                }
                else
                {
                    message = result.message;
                }
                ShowMessage(message);
            }
        }
Exemple #3
0
        protected void submit_Click(object sender, EventArgs e)
        {
            if (IsLoggedIn)
            {
                //Validate Selections for student
                if (chkrole.Items[0].Selected)
                {
                    if (string.IsNullOrEmpty(ddlMajors.SelectedValue))
                    {
                        rfvMajor.IsValid = false;
                    }
                    else
                    {
                        rfvMajor.IsValid = true;
                    }

                    if (string.IsNullOrEmpty(ddlCollege.SelectedValue))
                    {
                        rfvCollege.IsValid = false;
                    }
                    else
                    {
                        rfvCollege.IsValid = true;
                    }
                }
                else
                {
                    rfvMajor.IsValid   = true;
                    rfvCollege.IsValid = true;
                }

                if (rfvMajor.IsValid && rfvCollege.IsValid)
                {
                    String message = String.Empty;
                    CurrentUser.UserProfile.FirstName = txtFirstName.Text;
                    CurrentUser.UserProfile.LastName  = txtLastName.Text;
                    CurrentUser.UserProfile.College   = ddlCollege.SelectedValue;
                    CurrentUser.UserProfile.Major     = ddlMajors.SelectedValue;
                    CurrentUser.UserProfile.UpdatedBy = CurrentUser.Email;
                    Result <UserProfile> userProfileResult = ups.UpdateUserProfile(CurrentUser.UserProfile);
                    message = userProfileResult.message;
                    if (userProfileResult.isSuccess)
                    {
                        CurrentUser.UserProfile = userProfileResult.resultObject;

                        IUserManagementService um = new UserManagementService();

                        if (chkrole.Items[0].Selected && !AccessManagementValidator.UserHasRole(CurrentUser, Roles.Student))
                        {
                            // selected student box AND he is not a student already
                            Result <object> AssignRole = um.AssignRole(CurrentUser.Email, (int)Roles.Student);

                            if (AssignRole.isSuccess)
                            {
                                message += "\nStudent role added";
                            }

                            else
                            {
                                message += "\nFailed to add student role";
                            }
                        }

                        if (!chkrole.Items[0].Selected && AccessManagementValidator.UserHasRole(CurrentUser, Roles.Student))
                        {
                            // UNselected student box AND he IS a student then remove this role
                            Result <object> DeAssignRole = um.DeAssignRole(CurrentUser.Email, (int)Roles.Student);

                            if (DeAssignRole.isSuccess)
                            {
                                message += "\nStudent role deassigned successfuly";
                            }

                            else
                            {
                                message += "\nFailed to deassign student role";
                            }
                        }

                        if (chkrole.Items[1].Selected && !AccessManagementValidator.UserHasRole(CurrentUser, Roles.Tutor))
                        {
                            //selected tutor box AND he is not a tutor already
                            Result <object> AssignRole = um.AssignRole(CurrentUser.Email, (int)Roles.Tutor);

                            if (AssignRole.isSuccess)
                            {
                                AssignRole.message += "\nTutor role added";
                            }

                            else
                            {
                                AssignRole.message += "\nFailed to add tutor role";
                            }
                        }

                        if (!chkrole.Items[1].Selected && AccessManagementValidator.UserHasRole(CurrentUser, Roles.Tutor))
                        {
                            // UNselected tutor box AND he IS a Tutor then remove this role
                            Result <object> DeAssignRole = um.DeAssignRole(CurrentUser.Email, (int)Roles.Tutor);

                            if (DeAssignRole.isSuccess)
                            {
                                message += "\nTutor role deassigned successfuly";
                            }

                            else
                            {
                                message += "\nFailed to deassign Tutor role";
                            }
                        }
                        CurrentUser = um.GetUser(CurrentUser.Email).resultObject;
                    }

                    ShowMessage(message);
                }
            }
        }