예제 #1
0
 public JsonResult UserRoleEdit(SelectUserRolesViewModel model)
 {
     //if (ModelState.IsValid)
     {
         var idManager = new IdentityManager();
         var Db = new commenergyContext();
         var user = Db.Users.First(u => u.UserName == model.UserName);
         idManager.ClearUserRoles(user.Id);
         foreach (var role in model.Roles)
         {
             if (role.Selected)
             {
                 idManager.AddUserToRole(user.Id, role.RoleName);
                 Db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                 Db.SaveChangesAsync();
             }
             return Json(model, JsonRequestBehavior.AllowGet);
         }
     }
     return Json(model, JsonRequestBehavior.AllowGet);
 }
예제 #2
0
        public async Task<ActionResult> Edit(EditUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var Db = new commenergyContext();
                var user = Db.Users.First(u => u.UserName == model.UserName);
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.Email = model.Email;
                Db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                await Db.SaveChangesAsync();
                return RedirectToAction("Index");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }