Beispiel #1
0
        public async Task OnGetAsync(Guid projectId)
        {
            AssignUserViewModel = new AssignUserToProjectViewModel();
            var userLookup = await _projectBoardAppService.GetUserLookupAsync();

            Users = userLookup.Items
                    .Select(x => new SelectListItem(x.Name, x.Id.ToString()))
                    .ToList();
            AssignUserViewModel.ProjectId = projectId;
        }
Beispiel #2
0
        public ActionResult AssignUserToProject()
        {
            AssignUserToProjectViewModel model = new AssignUserToProjectViewModel();

            model.UserId      = new SelectList(db.Users, "Id", "FirstName");
            model.ProjectId   = new SelectList(db.Projects, "Id", "Name");
            model.ProjectUser = db.Users.ToList();

            return(View(model));
        }
Beispiel #3
0
        public ActionResult AssignUsers(int id)
        {
            var projectdb = db.Projects.Find(id);
            var projectUs = db.Users.Where(u => u.Projects.All(pu => pu.Id != projectdb.Id)).ToList();
            var users     = projectdb.Users;

            var model = new AssignUserToProjectViewModel();

            model.Id       = id;
            model.AddUsers = new MultiSelectList(db.Users, "Id", "FirstName", model.SelectedUsers);
            //model.SelectedUsers = pjHelper.UsersInProject(projectdb.id).ToArray();


            model.SelectedUsers = users.Select(u => u.Id).ToArray(); //<==(give me a list of all users not in a project and then push them into an array)

            return(View(model));
        }
Beispiel #4
0
        public ActionResult AssignUsers(AssignUserToProjectViewModel model)
        {
            if (model != null)                                     //check that the model isn't null
            {
                var project = db.Projects.Find(model.Id);          //get the project that your currently assigning/removing users to/from
                if (project != null)                               //check that the project isn't null
                {
                    project.Users.Clear();                         //remove all users from the project
                    ApplicationUser user = new ApplicationUser();  //create an instance of the ApplicationUser class
                    foreach (var userId in model.SelectedUsers)    //loop through all users that are included in the 'SelectedUsers' collection
                    {
                        user = db.Users.Find(userId);              //get the user by their 'Id' property
                        project.Users.Add(user);                   //add the user to the project, thus assigning the user to the project
                    }
                    db.SaveChanges();                              //save changes made to the database

                    return(RedirectToAction("Index", "Projects")); //I am assuming that you'll want to return to a list view of projects but you may want to change this to redirect to the details view for this project or redirect back to the view where you are assigning/removing users to/from this project....whatever you want to do
                }
            }

            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));//if the model is null or the project is null return a BadRequest error
        }