Esempio n. 1
0
 public ActionResult CreateIssueOnProject(int projectId)
 {
     EditIssueOnProjectViewModel viewModel = new EditIssueOnProjectViewModel();
     viewModel.ProjectId = projectId;
     viewModel.ProjectSelect = db.Projects;
     viewModel.PrioritySelect = db.IssuePriorities;
     return View(viewModel);
 }
Esempio n. 2
0
        public ActionResult CreateIssueOnProject(EditIssueOnProjectViewModel createIssueOnProjectViewModel)
        {
            if (ModelState.IsValid)
            {
                IssueEntry issueentry = new IssueEntry();

                BugTrackerUser authoringUser = (from user in db.BugTrackerUsers
                                                where (String.Compare(user.UserName, User.Identity.Name) == 0)
                                                select user).Single();
                issueentry.CreatedBy = authoringUser.UserName;
                issueentry.AssignedTo = createIssueOnProjectViewModel.AssignedTo;
                issueentry.Description = createIssueOnProjectViewModel.Description;
                issueentry.Title = createIssueOnProjectViewModel.Title;
                issueentry.IsSolved = createIssueOnProjectViewModel.IsSolved;
                issueentry.IssueEntryId = Guid.NewGuid();
                string selectedProject = createIssueOnProjectViewModel.SelectedProject;
                string selectedPriority = createIssueOnProjectViewModel.SelectedPriority;
                issueentry.Project = db.Projects.Find(Convert.ToInt32(selectedProject));
                issueentry.Project.IssueEntries.Add(issueentry);

                BugTrackerUser assignedToUser = (from user in db.BugTrackerUsers
                                                 where user.UserName.Equals(issueentry.AssignedTo)
                                                 select user).SingleOrDefault();

                issueentry.IssuePriority = db.IssuePriorities.Find(Convert.ToInt32(selectedPriority));
                issueentry.IssuePriority.IssueEntries.Add(issueentry);
                if (assignedToUser != null) assignedToUser.IssueEntries.Add(issueentry);

                try
                {
                    db.IssueEntries.Add(issueentry);
                    db.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            System.Diagnostics.Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                return RedirectToAction("IssuesByProject", new { projectId = createIssueOnProjectViewModel.ProjectId } );
            }

            return View(createIssueOnProjectViewModel);
        }
Esempio n. 3
0
        public ActionResult EditIssueOnProject(EditIssueOnProjectViewModel editIssueOnProjectViewModel)
        {
            if (ModelState.IsValid)
            {
                bool assigningChanged = false;
                bool priorityChanged = false;
                bool projectChanged = false;

                IssueEntry issueentry = db.IssueEntries.Find(editIssueOnProjectViewModel.IssueId);

                int redirectToProject = issueentry.Project.ProjectId;
                issueentry.IsSolved = editIssueOnProjectViewModel.IsSolved;

                assigningChanged = ModifyAssigningBasedOnIssue(editIssueOnProjectViewModel.AssignedTo, issueentry);

                /*
                if (!issueentry.AssignedTo.Equals(editIssueOnProjectViewModel.AssignedTo))
                {
                    assigningChanged = true;
                    BugTrackerUser assignee = (from user in db.BugTrackerUsers
                                               where user.UserName.Equals(issueentry.AssignedTo)
                                               select user).SingleOrDefault();
                    if (assignee == null)
                    {

                    }
                    else
                    {
                        assignee.IssueEntries.Remove(issueentry);
                    }
                }
                else
                {
                    BugTrackerUser assignedTo = (from user in db.BugTrackerUsers
                                                 where user.UserName.Equals(issueentry.AssignedTo)
                                                 select user).SingleOrDefault();

                    if (issueentry.IsSolved)
                    {
                        assignedTo.IssueEntries.Remove(issueentry);
                    }
                    else
                    {
                        assignedTo.IssueEntries.Add(issueentry);
                    }
                }
                */
                issueentry.Description = editIssueOnProjectViewModel.Description;
                issueentry.Title = editIssueOnProjectViewModel.Title;

                string selectedProject = editIssueOnProjectViewModel.SelectedProject;
                Int32 projectSelector = Convert.ToInt32(selectedProject);
                if (projectSelector != issueentry.Project.ProjectId)
                {
                    projectChanged = true;
                    Project projectReference = (from project in db.Projects
                                                where project.ProjectId == issueentry.Project.ProjectId
                                                select project).SingleOrDefault();
                    projectReference.IssueEntries.Remove(issueentry);

                }
                string selectedPriority = editIssueOnProjectViewModel.SelectedPriority;
                Int32 prioritySelector = Convert.ToInt32(selectedPriority);
                if (prioritySelector != issueentry.IssuePriority.PriorityId)
                {
                    priorityChanged = true;
                    Priority priorityReference = (from priority in db.IssuePriorities
                                                    where priority.PriorityId == issueentry.IssuePriority.PriorityId
                                                    select priority).SingleOrDefault();
                    priorityReference.IssueEntries.Remove(issueentry);
                }
                if (projectChanged)
                {
                    issueentry.Project = db.Projects.Find(projectSelector);
                    issueentry.Project.IssueEntries.Add(issueentry);
                }
                /*
                if (assigningChanged && issueentry.IsSolved == false)
                {
                    issueentry.AssignedTo = editIssueOnProjectViewModel.AssignedTo;
                    BugTrackerUser assignedToUser = (from user in db.BugTrackerUsers
                                                     where user.UserName.Equals(issueentry.AssignedTo)
                                                     select user).SingleOrDefault();

                    if (assignedToUser != null) assignedToUser.IssueEntries.Add(issueentry);
                }
                 */
                if (priorityChanged)
                {
                    issueentry.IssuePriority = db.IssuePriorities.Find(prioritySelector);
                    issueentry.IssuePriority.IssueEntries.Add(issueentry);
                }
                try
                {
                    db.Entry(issueentry).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            System.Diagnostics.Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                return RedirectToAction("IssuesByProject", "Issue", new { projectId = redirectToProject } );
            }

            return View(editIssueOnProjectViewModel);
        }
Esempio n. 4
0
        public ActionResult EditIssueOnProject(Guid? issueId)
        {
            IssueEntry issue = db.IssueEntries.Find(issueId);
            Guid? tmpId = issueId;

            /** Do not allow to edit issue if user is not responsible on this bug, or created it, or Admin user */
            if (issue.AssignedTo != null && (
                issue.AssignedTo.Equals(User.Identity.Name) ||
                issue.CreatedBy.Equals(User.Identity.Name) ||
                User.Identity.Name.Equals("Admin"))
                )
            {
                EditIssueOnProjectViewModel viewModel = new EditIssueOnProjectViewModel
                {
                    ProjectId = issue.Project.ProjectId,
                    IssueId = issue.IssueEntryId,
                    Title = issue.Title,
                    Description = issue.Description,
                    PrioritySelect = db.IssuePriorities,
                    ProjectSelect = db.Projects,
                    AssignedTo = issue.AssignedTo,
                    IsSolved = issue.IsSolved
                };
                return View(viewModel);
            }
            else return RedirectToAction("Details", new { issueId = tmpId });
        }