public ActionResult AddUserToRole(AddToRoleModel model)
        {
            var user = UserManager.FindByName(model.UserName);

            UserManager.AddToRole(user.Id, model.SelectedRole);
            return(RedirectToAction("Index", "Home"));
        }
Example #2
0
        public async Task <IActionResult> AddToRole([FromBody] AddToRoleModel model)
        {
            var user = await userManager.FindByNameAsync(model.UserName);

            if (user == null)
            {
                return(Ok(new ServiceResult {
                    Status = "Error", Message = "User is not exists"
                }));
            }

            var roleExists = await roleManager.RoleExistsAsync(model.RoleName);

            if (!roleExists)
            {
                return(Ok(new ServiceResult {
                    Status = "Error", Message = "Role is not exists"
                }));
            }

            var result = await userManager.AddToRoleAsync(user, model.RoleName);

            return(Ok(new ServiceResult {
                Status = "Success", Message = "User is added to specified role successfully"
            }));
        }
Example #3
0
        public ActionResult AddToRole(AddToRoleModel model)
        {
            var korisnik = UserManager.FindByEmail(model.Email);

            UserManager.AddToRole(korisnik.Id, model.SelectRole);
            return(RedirectToAction("Index", "Home"));
        }
Example #4
0
        public ActionResult AddUserToRole(AddToRoleModel model)
        {
            var user = UserManager.FindByEmail(model.Email);

            UserManager.AddToRole(user.Id, model.Role);
            return(RedirectToAction("Index", "Albums"));
        }
        public async Task <IActionResult> AddToRole(AddToRoleModel model)
        {
            var roleExists = await this.roleManager.RoleExistsAsync(model.Role);

            var user = await this.userManager.FindByIdAsync(model.UserId);

            var userExists = user != null;

            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(All)));
            }

            if (!roleExists || !userExists)
            {
                return(RedirectToAction(nameof(All)));
            }

            var result = await userManager.AddToRoleAsync(user, model.Role);

            if (!result.Succeeded)
            {
                TempData.AddErrorMessage($"User {user.UserName} was NOT set to a role of {model.Role}");
                return(RedirectToAction(nameof(All)));
            }

            TempData.AddSuccessMessage($"User {user.UserName} was set to a role of {model.Role}");
            return(RedirectToAction(nameof(All)));
        }
        public async Task <MessageReponse> AddUserToRole(AddToRoleModel model)
        {
            var user = await _userManager.FindByNameAsync(model.UserName);

            if (user == null)
            {
                return(new MessageReponse()
                {
                    Message = "UserName not Found",
                    IsSuccess = false,
                });
            }
            else
            {
                var role = await _roleManager.FindByNameAsync(model.RoleName);

                if (role == null)
                {
                    return(new MessageReponse()
                    {
                        Message = "RoleName not Found",
                        IsSuccess = false,
                    });
                }
                else
                {
                    var userRole = await _userManager.GetRolesAsync(user);

                    bool checkrole = userRole.ToList().Contains(model.RoleName);

                    if (checkrole)
                    {
                        return(new MessageReponse()
                        {
                            Message = "User already belong to role",
                            IsSuccess = false,
                        });
                    }
                    else
                    {
                        var result = await _userManager.AddToRoleAsync(user, role.Name);

                        if (result.Succeeded)
                        {
                            return(new MessageReponse()
                            {
                                Message = "Added successed",
                                IsSuccess = true,
                            });
                        }
                        return(new MessageReponse()
                        {
                            Message = "Added Failed",
                            IsSuccess = true,
                        });
                    }
                }
            }
        }
Example #7
0
        public ActionResult AddUserToRole()
        {
            var model = new AddToRoleModel();

            model.roles.Add("Administrator");
            model.roles.Add("User");
            return(View(model));
        }
Example #8
0
        public ActionResult AdminPanel()
        {
            var model = new AddToRoleModel();

            model.Roles.Add("Admin");
            model.Roles.Add("User");
            return(View(model));
        }
Example #9
0
        public async Task <IActionResult> AddUserToRole(AddToRoleModel model)
        {
            var userToRole = await _roleService.AddUserToRole(model);

            if (userToRole == null)
            {
                return(BadRequest(userToRole));
            }
            return(Ok(userToRole));
        }
Example #10
0
        public ActionResult AddUserToRole()
        {
            var model = new AddToRoleModel();

            model.Roles.Add("ADMIN");
            model.Roles.Add("EDITOR");
            model.Roles.Add("USER");

            return(View(model));
        }
Example #11
0
        public async Task <IActionResult> RemoveUserFromRole(AddToRoleModel model)
        {
            var remove = await _roleService.RemoveUserFromRole(model);

            if (remove == null)
            {
                return(BadRequest(remove));
            }
            return(Ok(remove));
        }
Example #12
0
        public ActionResult AddUserToRole()
        {
            var roleStore = new RoleStore <IdentityRole>(db);
            var roleMngr  = new RoleManager <IdentityRole>(roleStore);
            var model     = new AddToRoleModel();

            model.roles  = roleMngr.Roles.Select(x => x.Name).ToList();
            model.Emails = UserManager.Users.Select(x => x.Email).ToList();
            return(View(model));
        }
Example #13
0
        //custom code
        public ActionResult AddUserToRole()
        {
            AddToRoleModel model = new AddToRoleModel();

            model.roles = new List <string>()
            {
                "Admin", "Editor", "User"
            };
            return(View(model));
        }
Example #14
0
        public ActionResult AddRoleToUser()
        {
            AddToRoleModel m = new AddToRoleModel();

            m.ulogi = new List <string>()
            {
                "Administrator", "Manager", "User"
            };
            return(View(m));
        }
Example #15
0
        public ActionResult AddUserToRole()
        {
            var model = new AddToRoleModel();

            model.roles = new System.Collections.Generic.List <string>();
            model.roles.Add("Administrator");
            model.roles.Add("Publisher");
            model.roles.Add("User");
            return(View(model));
        }
Example #16
0
 public ActionResult AddUserToRole(AddToRoleModel model)
 {
     try {
         var userr = UserManager.FindByEmail(model.Email);
         UserManager.AddToRole(userr.Id, model.SelectedRole);
         return(RedirectToAction("Index", "Stores"));
     }
     catch (Exception ex) {
         return(HttpNotFound());
     }
 }
        public ActionResult AddUserToRole()
        {
            var model = new AddToRoleModel();

//            model.roles = UserManager.GetRoles().ToList();
            model.roles.Add("Admin");
            model.roles.Add("User");


            return(View(model));
        }
Example #18
0
        public ActionResult AddUserToRole(AddToRoleModel model)
        {
            var user = UserManager.FindByEmail(model.Email);

            if (user == null)
            {
                throw new HttpException(404, "Не постои корисник со следната Е-пошта: " + model.Email);
            }
            UserManager.AddToRole(user.Id, model.selectedRole);
            return(RedirectToAction("Index", "Home"));
        }
Example #19
0
        public ActionResult AddUserToRole()
        {
            updateCartIcon();
            AddToRoleModel model = new AddToRoleModel();

            model.roles = new List <string>()
            {
                "User", "Publisher", "Admin"
            };
            return(View(model));
        }
        public ActionResult AddUserToRole()
        {
            var users = UserManager.Users.ToList();

            users.RemoveAll(u => u.UserName == User.Identity.Name);
            var model = new AddToRoleModel();

            model.Roles = Roles.ListRoles();
            model.Users = users;
            return(View(model));
        }
Example #21
0
        public ActionResult AddUserToRole(AddToRoleModel m)
        {
            var mail = m.mail;
            var user = UserManager.FindByEmail(m.mail);

            if (user == null)
            {
                throw new HttpException(404, "There is no user with this email");
            }
            UserManager.AddToRole(user.Id, m.selected);
            return(RedirectToAction("Index", "FriendModels"));
        }
        public ActionResult AddUserToRole()
        {
            var model = new AddToRoleModel();

            model.roles.Add(Roles.Administrator);
            model.roles.Add(Roles.Moderator);
            model.roles.Add(Roles.User);

            model.mails = UserManager.Users.Select(u => u.Email).ToList();

            return(View(model));
        }
Example #23
0
        public ActionResult AddUserToRole(AddToRoleModel model)
        {
            var email = model.Email;
            var user  = UserManager.FindByEmail(model.Email);

            if (user == null)
            {
                throw new HttpException(404, "There is no user with email: " + model.Email);
            }

            UserManager.AddToRole(user.Id, model.selectedRole);
            return(RedirectToAction("Index", "Home"));
        }
Example #24
0
        public ActionResult AddUserToRole(AddToRoleModel model)
        {
            var email = model.Email;
            var user  = UserManager.FindByEmail(model.Email);

            if (user == null)
            {
                return(HttpNotFound());
            }

            UserManager.AddToRole(user.Id, model.selectedRole);
            return(RedirectToAction("Index", "Posts"));
        }
 public ActionResult AddUserToRole(AddToRoleModel model)
 {
     try
     {
         var user = UserManager.Users.FirstOrDefault(u => u.Email == model.Email);
         UserManager.AddToRole(user.Id, model.selectedRole);
         return(RedirectToAction("Index", "Home"));
     }
     catch (Exception ex)
     {
         return(HttpNotFound());
     }
 }
 public ActionResult AddUserToRole(AddToRoleModel model)
 {
     try
     {
         var user = UserManager.FindByEmail(model.Email);
         this.UserManager.AddToRoleAsync(user.Id, model.selectedRole);
         return(RedirectToAction("Index", "Home"));
     }
     catch (Exception ex)
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Example #27
0
        public ActionResult AddUserToRole(AddToRoleModel model)
        {
            try
            {
                var user = UserManager.FindByEmail(model.Email);

                UserManager.AddToRole(user.Id, model.Role);
                return(View("AddUserToRole", model));
            }
            catch (Exception ex)
            {
                return(HttpNotFound());
            }
        }
        public ActionResult AddUserToRole()
        {
            var model = new AddToRoleModel();

            model.roles.Add("Administrator");
            model.roles.Add("User");
            foreach (Person p in db.People)
            {
                model.emails.Add(p.Email);
            }


            return(View(model));
        }
        public ActionResult AddUserToRole()
        {
            AddToRoleModel model = new AddToRoleModel();
            User           user  = new User();

            foreach (var u in UserManager.Users)
            {
                model.users.Add(u.Email);
            }

            model.roles.Add("Admin");
            model.roles.Add("Employee");
            return(View(model));
        }
Example #30
0
        public ActionResult AddUserToRole()
        {
            AddToRoleModel model = new AddToRoleModel();

            foreach (var u in UserManager.Users)
            {
                model.users.Add(u.Email);
            }

            model.roles.Add("Administrator");
            model.roles.Add("User");
            model.roles.Add("Owner");


            return(View(model));
        }