Esempio n. 1
0
        public async Task<ActionResult> SaveUser(string id, AdminEditViewModel model)
        {
            try
            {
                // TODO: Add update logic here
                AdmUsrRole = model.RankName;
                AdmUsrName = model.UserName;
                var userid = _context.Users.Where(x => x.UserName == AdmUsrName).Select(x => x.Id).FirstOrDefault();
                var user = await _userManager.FindByIdAsync(userid);
                var userRole = await _userManager.GetRolesAsync(user);
                await _userManager.RemoveFromRolesAsync(user, userRole);
                await _userManager.AddToRoleAsync(user, AdmUsrRole);

                return RedirectToAction("Index", "Admin", new { Message = ManageMessageId.UserUpdated });

            }
            catch
            {
                return RedirectToAction("Index", "Admin", new { Message = ManageMessageId.Error });
            }
        }
Esempio n. 2
0
 public async Task<ActionResult> EditUser(string id, AdminEditViewModel model)
 {
     try
     {
         // TODO: Add update logic here
         var user = await _userManager.FindByIdAsync(id);
         model.Email = user.Email;
         var roles = await _userManager.GetRolesAsync(user);
         model.UserName = user.UserName;
         foreach (var role in roles)
         {
             model.RankName = role;
         }
         AdmUsrName = model.UserName;
         AdmUsrEmail = model.Email;
         AdmUsrRole = model.RankName;
         return RedirectToAction("EditUser");
     }
     catch
     {
         return View();
     }
 }