Exemple #1
0
        public IActionResult RegisterRole(string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            var vm = new RegisterRoleViewModel
            {
                ApplicationRoles = _roleManager.Roles.ToList(),
                Counties         = _ctx.Counties.ToList()
            };

            return(View(vm));
        }
Exemple #2
0
        public async Task <IActionResult> RegisterRole(RegisterRoleViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var role = new ApplicationRole
            {
                Name     = model.Name,
                CountyId = model.CountyId
            };
            var result = await _roleManager.CreateAsync(role);

            if (result.Succeeded)
            {
                _logger.LogInformation("Role created.");
                return(RedirectToLocal(returnUrl));
            }
            AddErrors(result);
            return(View(model));
        }