public ActionResult Create([Bind(Include = "Name")] Permission permission) { if (ModelState.IsValid) { db.Permissions.Add(permission); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(permission)); }
public ActionResult Create(CreateUserViewModel model, String[] selectedRoles) { var user = model.User; user.Roles = new List <Role>(); foreach (var selectedRole in selectedRoles) { var role = db.Roles.FirstOrDefault(r => r.Name == selectedRole); user.Roles.Add(role); } if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Create(CreateRoleViewModel model, String[] SelectedPermissions) { var role = model.Role; role.Permissions = new List <Permission>(); foreach (var p in SelectedPermissions) { var permission = db.Permissions.FirstOrDefault(perm => perm.Name == p); role.Permissions.Add(permission); } if (ModelState.IsValid) { db.Roles.Add(role); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }