public ActionResult Create([Bind(Include = "Name")] Permission permission)
        {
            if (ModelState.IsValid)
            {
                db.Permissions.Add(permission);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(permission));
        }
示例#2
0
        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));
        }
示例#3
0
        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));
        }