Esempio n. 1
0
        // GET: Projects
        public ActionResult Index(int?page, int?id)
        {
            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            ProjectUserViewModels uservm = new ProjectUserViewModels();

            //Find project based on project id
            var project = db.Projects.Find(id);

            //Find user for this project id
            //var assignmentList = db.ProjectUser.Where(a => a.ProjectId == project.Id).ToList();
            //var i = 0;
            //foreach(var assignment in assignmentList)
            //{
            //    var user = db.Users.Find(assignment.UserId);
            //    uservm.SelectedUsers[i] = user.DisplayName;
            //    i++;
            //}

            //uservm.SelectedUsers = assignmentList.ListAssignedUsers(id).Select(u => u.Id).ToArray();
            //uservm.Users = new MultiSelectList(db.Users.Where(u => (u.DisplayName != "N/A" && u.DisplayName != "(Remove Assigned User)")).OrderBy(u => u.FirstName), "Id", "DisplayName", uservm.SelectedUsers);


            uservm.AssignProject = project;

            return(View(db.Projects.OrderByDescending(p => p.CreatedDate).ToPagedList(pageNumber, pageSize)));
        }
Esempio n. 2
0
        public ActionResult ProjectUser(int?id)
        {
            var project = db.Projects.Find(id);
            ProjectUserViewModels projectuserVM = new ProjectUserViewModels();

            projectuserVM.AssignProject   = project;
            projectuserVM.AssignProjectId = Convert.ToInt32(project.Id);
            projectuserVM.SelectedUsers   = project.Users.Select(u => u.Id).ToArray();
            projectuserVM.Users           = new MultiSelectList(db.Users.ToList(), "Id", "FirstName", projectuserVM.SelectedUsers);
            // MultiSelectList parameters: collection of objects used for select list (user for us), inside user table we have diff properties that we submit by like Id or FirstName, display is FirstNames, highlighted selected users
            return(View(projectuserVM)); // how does this view return work? View(model) for example: passes in an object
        }
Esempio n. 3
0
        public ActionResult ProjectUser(ProjectUserViewModels model)
        {
            // submit assign and it goes through here, we need to go through users assigned in database and put in the users selected
            ProjectAssignHelper projectassignhelper = new ProjectAssignHelper();

            //var project = db.Projects.Find(model.AssignProject.Id); No need for this since we don't need to find project in db by Id
            foreach (var userId in db.Users.Select(r => r.Id).ToList()) // remove all users from project
            {
                projectassignhelper.RemoveUserFromProject(userId, model.AssignProjectId);
            }
            foreach (var userId in model.SelectedUsers) // add back the ones you want
            {
                projectassignhelper.AddUserToProject(userId, model.AssignProjectId);
            }

            return(RedirectToAction("Index"));
        }