Example #1
0
        public async Task<ActionResult> Edit(string id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var user = await userManager.FindByIdAsync(id);
            if (user == null)
            {
                return HttpNotFound();
            }

            var vm = new EditUserViewModel() { UserId = user.Id, Email = user.Email };

            //var allSystemClaims = claimManager.List();

            //var userEnableClaims = from x in user.Claims
            //                       where x.ClaimValue==true.ToString()
            //                       select x.ClaimType;
            //vm.ClaimsList = new List<SelectListItem>();

            //popula os selectitens
            //foreach (var sClaim in allSystemClaims)
            //{
            //    vm.ClaimsList.Add(new SelectListItem() { Text = sClaim.Name, Selected = false, Value = sClaim.Name });
            //}

            //foreach (var claimType in userEnableClaims)
            //{
            //    vm.ClaimsList.Find(x => x.Value == claimType).Selected = true;
            //}

            return View(vm);
        }
Example #2
0
        public async Task<ActionResult> Edit(EditUserViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.FindByIdAsync(vm.UserId);
                if (user == null)
                {
                    return HttpNotFound();
                }

                user.UserName = vm.Email;
                user.Email = vm.Email;

                var result = await userManager.UpdateAsync(user);
                if (!result.Succeeded)
                {
                    ModelState.AddModelError("", result.Errors.ToString());
                    return View(vm);
                }

                return RedirectToAction("Index");
            }
            ModelState.AddModelError("", "Algo deu errado.");
            return View(vm);
        }