示例#1
0
        public async Task <IActionResult> AddRole(AddRoleBindingModel addModel)
        {
            // Adds a new role different than the existing ones
            var isAdded = await this.roleService.AddRole(addModel.RoleName);

            var message = isAdded ? "Successfully added role."
                : "Role already exists.";

            return(this.RedirectToAction("Index", new { statusMessage = message }));
        }
示例#2
0
        public async Task <IHttpActionResult> AddRoleToUser(AddRoleBindingModel model)
        {
            var user = await _userManager.FindByNameAsync(model.UserName);

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

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

            var errorResult = GetErrorResult(result);

            if (errorResult != null)
            {
                return(errorResult);
            }

            return(Ok());
        }