Пример #1
0
        public async Task<ActionResult> Create(RegisterViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = vm.Email, Email = vm.Email };
                var adminresult = await userManager.CreateAsync(user, vm.Password);

                //Add User to the selected Claims 
                if (adminresult.Succeeded)
                {
                    if (vm.selectedClaims != null)
                    {
                        foreach (var item in vm.selectedClaims)
                        {
                            var claim = new Claim(item, true.ToString());
                            var result = await userManager.AddClaimAsync(user.Id, claim); if (!result.Succeeded)
                            {
                                ModelState.AddModelError("", result.Errors.First());
                                return View(vm);
                            }
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", adminresult.Errors.First());
                    return View(vm);

                }
                return RedirectToAction("Index");
            }
            return View(vm);
        }
Пример #2
0
 public ActionResult Create()
 {
     RegisterViewModel vm = new RegisterViewModel();
     vm.ClaimsList = claimManager.List().Select<SystemClaimType,string>(x=>x.Name).ToList();
     return View(vm);
 }