Zdravim, som uplny novacik v asp.net mvc a mam problem s priradenim role k pouzivatelovi v defaultnej databaze. Nasiel som priradenie role natvrdo: RoleManager<IdentityRole> roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new IdentityDbContext())); UserManager<ApplicationUser> userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())); roleManager.Create(new IdentityRole(RoleName)); ApplicationUser user = userManager.FindByEmail(UserName); userManager.AddToRole(user.Id, RoleName); kde UserName a RoleName je konkretny string v db. Chcel by som vytvorit formular s dvoma dropdown listmi a jednym tlacidlom, kde z dropdown listu vyberiem pouzivatela a rolu, a tlacidlom potvrdim priradenie k roly. Vyber dropdown listov som vytvoril takto: List<SelectListItem> selectListItems = new List<SelectListItem>(); foreach (AspNetUsers userName in db.AspNetUsers) { SelectListItem selectListItem = new SelectListItem { Text = userName.UserName, Value = userName.Id.ToString() }; selectListItems.Add(selectListItem); } ViewBag.UserName = selectListItems; List<SelectListItem> selectListItems1 = new List<SelectListItem>(); foreach (AspNetRoles roleName in db.AspNetRoles) { SelectListItem selectListItem = new SelectListItem { Text = roleName.Name, Value = roleName.Id.ToString() }; selectListItems1.Add(selectListItem); } ViewBag.RoleName = selectListItems1; Neviem vsak vybranu hodnotu zo dropdavn listu vlozit do premennej a pouzivat ju dalej. Viete mi poradit?
|