Exemplo n.º 1
0
        // GET: Projects/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Projects project = db.Projects.Find(id);
            if (project == null)
            {
                return HttpNotFound();
            }
            var usersOnProject = project.ProjectMembers.Select(u=>u.Id);
            ProjectAndUsersModels p = new ProjectAndUsersModels();
            p.Project = project;
            if (User.IsInRole("Admin"))
            {
                p.Users = new MultiSelectList(db.Users, "Id", "DisplayName", usersOnProject);
            } else
            {
                var onlyDevs = "Developer".UsersInRole();
                p.Users = new MultiSelectList(onlyDevs, "Id", "DisplayName", usersOnProject);
            }

            return View(p);
        }
Exemplo n.º 2
0
        public ActionResult Edit(ProjectAndUsersModels projectAndUsers)
        {
            if (ModelState.IsValid)
            {
                var project = db.Projects.Find(projectAndUsers.Project.ID);
                project.ProjectMembers.Clear();

                project.ProjectMembers = db.Users.Where(u => projectAndUsers.SelectedUsers.Contains(u.Id)).ToList();

                db.SaveChanges();

                return RedirectToAction("Details", "Projects", new { id = projectAndUsers.Project.ID });
            }
            return View(projectAndUsers);
        }