Ejemplo n.º 1
0
        public ActionResult ManageUserProjects()
        {
            ViewBag.ProjecstIds = new MultiSelectList(db.Projects, "Id", "Name");
            ViewBag.UsersIds    = new MultiSelectList(db.Users, "Id", "FullName");
            if (User.IsInRole("Admin"))
            {
                ViewBag.UsersIds = new MultiSelectList(db.Users, "Id", "FullName");
            }
            else if (User.IsInRole("Developer"))
            {
                ViewBag.UsersIds = new MultiSelectList(roleHelper.UsersInRole("Developer"), "Id", "FullName");
            }

            //ViewBag.UsersIds = new MultiSelectList(roleHelper.UsersInRole("Developer"), "Id", "FullName");

            //if(User.IsInRole("Admin"))
            //{
            //    ViewBag.ProjectManagerId = new SelectList(roleHelper.UsersInRole("Project Manager"), "Id", "Email");
            //}


            // var myData = new List<UserProjectListViewModel>();
            // UserProjectViewModel userVm = null;
            //foreach(var user in db.Users.ToList())
            // {
            //     userVm = new USerProjectListViewModel
            //     {
            //         Name = ${ user.LastName},{ user.FirstName}"," +
            //         PRojectNames = projectHelper.ListOfProjects(user.Id).Select(p => p.Name).Count() == 0 ? "N/A" : projectHelper.ListOfProjects(user.Id).Select(p => p.Name).ToList();
            //     };

            // myData.Add(userVm);
            // }


            var users = new List <ManageProjecstUsersViewModel>();

            foreach (var user in db.Users.ToList())
            {
                users.Add(new ManageProjecstUsersViewModel
                {
                    FullName    = $"{ user.LastName},{ user.FirstName}",
                    RoleName    = roleHelper.ListUserRoles(user.Id).FirstOrDefault(),
                    Email       = user.Email,
                    ProjectName = projectHelper.ListOfProjects(user.Id)
                });;
            }
            return(View(users));
        }