コード例 #1
0
        public ActionResult ProjectUser(string Id, AdminProjectUserAssignViewModel model)
        {
            var user = db.Users.Find(model.User.Id);

            foreach (var project in user.Projects.ToList())
            {
                if (!model.SelectedProjects.Contains(project.Id))
                {
                    phelper.RemoveProjectFromUser(user.Id, project.Id);
                }
            }
            foreach (var projectId in model.SelectedProjects)
            {
                if (model.SelectedProjects.Contains(projectId))
                {
                    phelper.AddProjectToUser(user.Id, projectId);
                }
            }

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }