예제 #1
0
        public ActionResult GrantInstructorPermissions(string id)
        {
            var userProfileToEdit =
                RepositoryFactory.UserRepository.Queryable.SingleOrDefault(
                    x => x.Identifier == id);

            if (userProfileToEdit == null)
            {
                Message = "This user does not exist";
                return RedirectToAction("Index");
            }

            // See if they already have instructor permissions, if so then skip
            if (userProfileToEdit.Roles.Contains(RepositoryFactory.RoleRepository.GetById(RoleNames.Instructor)))
            {
                var failModel = new InstructorPermissionResultViewModel
                {
                    Header = "This user is already an instructor.",
                    Message = "Someone has previously granted instructor permissions to " + userProfileToEdit.Profile.DisplayName + "."
                };

                return View(failModel);
            }

            userProfileToEdit.Roles.Clear();
            userProfileToEdit.Roles.Add(RepositoryFactory.RoleRepository.GetById(RoleNames.Instructor));

            RepositoryFactory.UserRepository.EnsurePersistent(userProfileToEdit);

            // Notify the user that they are now an instructor
            _notificationService.Notify(userProfileToEdit, AuthenticatedUser,
                "You now have instructor privileges!",
                "Congratulations! You have been verified as an instructor and have been granted elevated instructor permissions.",
                null);

            var successModel = new InstructorPermissionResultViewModel
            {
                Header = "Success!",
                Message = userProfileToEdit.Profile.DisplayName + " has been granted Instructor permissions!"
            };

            return View(successModel);
        }
예제 #2
0
        public ActionResult GrantInstructorPermissions(string id)
        {
            var userProfileToEdit =
                RepositoryFactory.UserRepository.Queryable.SingleOrDefault(
                    x => x.Identifier == id);

            if (userProfileToEdit == null)
            {
                Message = "This user does not exist";
                return(RedirectToAction("Index"));
            }

            // See if they already have instructor permissions, if so then skip
            if (userProfileToEdit.Roles.Contains(RepositoryFactory.RoleRepository.GetById(RoleNames.Instructor)))
            {
                var failModel = new InstructorPermissionResultViewModel
                {
                    Header  = "This user is already an instructor.",
                    Message = "Someone has previously granted instructor permissions to " + userProfileToEdit.Profile.DisplayName + "."
                };

                return(View(failModel));
            }

            userProfileToEdit.Roles.Clear();
            userProfileToEdit.Roles.Add(RepositoryFactory.RoleRepository.GetById(RoleNames.Instructor));

            RepositoryFactory.UserRepository.EnsurePersistent(userProfileToEdit);

            // Notify the user that they are now an instructor
            _notificationService.Notify(userProfileToEdit, AuthenticatedUser,
                                        "You now have instructor privileges!",
                                        "Congratulations! You have been verified as an instructor and have been granted elevated instructor permissions.",
                                        null);

            var successModel = new InstructorPermissionResultViewModel
            {
                Header  = "Success!",
                Message = userProfileToEdit.Profile.DisplayName + " has been granted Instructor permissions!"
            };

            return(View(successModel));
        }