Пример #1
0
        public static void CreateRole(RoleManager<ApplicationRole> roleManager, string roleName)
        {
            var role = roleManager.FindByName(roleName);

            if (role != null) return;
            role = new ApplicationRole(roleName);
            var roleResult = roleManager.Create(role);
        }
        public async Task<ActionResult> Create([Bind(Include = "Name")] ApplicationRoleViewModel applicationRoleViewModel)
        {
            if (ModelState.IsValid)
            {
                ApplicationRole applicationRole = new ApplicationRole{Name = applicationRoleViewModel.Name};

                var roleResult = await _roleManager.CreateAsync(applicationRole);
                if (!roleResult.Succeeded)
                {
                    ModelState.AddModelError("", roleResult.Errors.First());
                    return View();
                }

                return RedirectToAction("Index");
            }

            return View();
        }