Exemple #1
0
 public ActionResult Edit(RoleForm form)
 {
     if(!ModelState.IsValid) return View(form);
     Role role = db.Roles.Single(x => x.ID == form.ID);
     role.Permissions.Clear();
     foreach (Guid permissionId in form.SelectedPermissionIds)
     {
         role.Permissions.Add(db.Permissions.Single(x => x.ID == permissionId));
     }
     role.Name = form.Name;
     db.SaveChanges();
     return RedirectToAction("Index");
 }
Exemple #2
0
 private Role formToRole(RoleForm form)
 {
     IList<Permission> rolePermissions = new List<Permission>();
     foreach (Guid guid in form.SelectedPermissionIds)
     {
         rolePermissions.Add(db.Permissions.Single(x => x.ID == guid));
     }
     return new Role()
     {
         ID = form.ID,
         Permissions = rolePermissions,
         Name = form.Name
     };
 }