Ejemplo n.º 1
0
        public ActionResult ManageProjectUsers(List <int> projects, string projectManagerId, List <string> developers, List <string> submitters)
        {
            if (projects != null)
            {
                foreach (var projectId in projects)
                {
                    //Remove everyone from this project
                    foreach (var user in projectHelper.UsersOnProject(projectId).ToList())
                    {
                        projectHelper.RemoveUserFromProject(user.Id, projectId);
                    }
                    //Add back PM if possible
                    if (!string.IsNullOrEmpty(projectManagerId))
                    {
                        projectHelper.AddUserToProject(projectManagerId, projectId);
                    }

                    if (developers != null)
                    {
                        foreach (var developerId in developers)
                        {
                            projectHelper.AddUserToProject(developerId, projectId);
                        }
                    }

                    if (submitters != null)
                    {
                        foreach (var submitterId in submitters)
                        {
                            projectHelper.AddUserToProject(submitterId, projectId);
                        }
                    }
                }
            }

            return(RedirectToAction("ManageProjectUsers"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> EditUsers([Bind(Include = "Users,Project,SelectedUsers")] ProjectViewModel model, TicketNotification ticketNotification)
        {
            ProjectHelper helper = new ProjectHelper();

            foreach (var user in db.Users)
            {
                if (helper.IsUserOnProject(user.Id, model.Project.Id))
                {
                    helper.RemoveUserFromProject(user.Id, model.Project.Id);
                }
            }
            foreach (var user in model.SelectedUsers)
            {
                if (!helper.IsUserOnProject(user, model.Project.Id))
                {
                    helper.AddUserToProject(user, model.Project.Id);
                    //userManager.SendEmailAsync(user, "Notification", "You have been added to project " + model.Project.Name);
                    var callbackUrl = Url.Action("Details", "Projects", new { id = model.Project.Id }, protocol: Request.Url.Scheme);
                    try
                    {
                        EmailService    ems = new EmailService();
                        IdentityMessage msg = new IdentityMessage();
                        ApplicationUser usr = db.Users.Find(user);
                        msg.Body        = "You have been added to a Project." + Environment.NewLine + "Please click the following link to view the details" + "<a href=\"" + callbackUrl + "\">PROJECT</a>";
                        msg.Destination = usr.Email;
                        msg.Subject     = "BugTracker";
                        await ems.SendMailAsync(msg);
                    }
                    catch (Exception ex)
                    {
                        await Task.FromResult(0);
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public ActionResult Edit([Bind(Include = "Id,Name,Description, Archived")] Project project, List <string> Developer, string ProjectManager, string Admin, string Submitter)
        {
            var checktickets = archiveHelper.doesProjectHaveTicketsOpen(project.Id);

            if (checktickets && project.Archived)
            {
                var           id      = project.Id;
                var           users   = projectHelper.UsersOnProject(id);
                var           pmId    = "";
                var           adminId = "";
                var           sub     = "";
                List <string> devIds  = new List <string>();

                foreach (var user in users)
                {
                    if (rolerHelpers.IsUserInRole(user.Id, "Project Manager"))
                    {
                        pmId = user.Id;
                    }

                    if (rolerHelpers.IsUserInRole(user.Id, "Developer"))
                    {
                        devIds.Add(user.Id);
                    }
                    if (rolerHelpers.IsUserInRole(user.Id, "Admin"))
                    {
                        adminId = user.Id;
                    }
                    if (rolerHelpers.IsUserInRole(user.Id, "Submitter"))
                    {
                        sub = user.Id;
                    }
                }


                var submitter = rolerHelpers.UsersInRole("Submitter");
                ViewBag.Submitter = new SelectList(submitter, "Id", "Email", sub);

                var admin = rolerHelpers.UsersInRole("Admin");
                ViewBag.Admin = new SelectList(admin, "Id", "Email", adminId);

                var pms = rolerHelpers.UsersInRole("Project Manager");
                ViewBag.ProjectManager = new SelectList(pms, "Id", "Email", pmId);

                var dv = rolerHelpers.UsersInRole("Developer");
                ViewBag.Developer = new MultiSelectList(dv, "Id", "Email", devIds);

                ViewBag.ticketWarning = "The project you are trying to archive has tickets open. Please close all tickets and try again.";
                return(View(project));
            }
            if (ModelState.IsValid)
            {
                var users       = projectHelper.UsersOnProject(project.Id).ToList();
                var projectmana = "";
                foreach (var use in users)
                {
                    if (rolerHelpers.IsUserInRole(use.Id, "Project Manager"))
                    {
                        projectmana = use.Id;
                    }
                    projectHelper.RemoveUserFromProject(use.Id, project.Id);
                }
                if (Developer != null)
                {
                    foreach (var dev in Developer)
                    {
                        projectHelper.AddUserToProject(dev, project.Id);
                    }
                }
                if (ProjectManager != null)
                {
                    projectHelper.AddUserToProject(ProjectManager, project.Id);
                }
                else
                {
                    projectHelper.AddUserToProject(projectmana, project.Id);
                }

                if (Submitter != null)
                {
                    projectHelper.AddUserToProject(Submitter, project.Id);
                }

                if (Admin != null)
                {
                    projectHelper.AddUserToProject(Admin, project.Id);
                }

                db.Entry(project).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            return(View(project));
        }