예제 #1
0
        public void UnAssignUserToProject(string userId, int projectId)
        {
            var user    = db.Users.Find(userId);
            var project = db.Projects.Find(projectId);

            if (user == null || project == null)
            {
                return;
            }
            UserProject userProject = db.UserProjects.Where(x => x.ProjectId == project.Id && x.ApplicationUserId == user.Id).FirstOrDefault();

            db.UserProjects.Remove(userProject);
            db.SaveChanges();
        }
예제 #2
0
        // Assign/unassign users to/from projects
        // Here there is a class called UserProject which should be use.
        // Organization of resources / project managers or admin only

        public void AssignUserToProject(string userId, int projectId)
        {
            var user    = db.Users.Find(userId);
            var project = db.Projects.Find(projectId);

            if (user == null || project == null)
            {
                return;
            }
            UserProject userProject = new UserProject();

            userProject.ProjectId         = project.Id;
            userProject.Project           = project;
            userProject.ApplicationUserId = user.Id;
            userProject.ApplicationUser   = user;
            db.UserProjects.Add(userProject);
            db.SaveChanges();
        }