Ejemplo n.º 1
0
        public async Task <IActionResult> EditAsync(int projectId, IssueViewModel model)
        {
            var projectResult = await projects.GetProjectAsync <ProjectViewModel>(projectId);

            if (projectResult.NotificationType == NotificationType.Error)
            {
                this.AddNotification(projectResult.Message, projectResult.NotificationType);
                return(RedirectToAction("Index", "Projects"));
            }

            var project = projectResult.Value;
            var issue   = project?.Issues.SingleOrDefault(i => i.Id == model.Id);

            if (issue == null)
            {
                return(BadRequest());
            }

            await PerformServerValidationsAsync(project, model, issue);

            if (!ModelState.IsValid)
            {
                var isAdmin       = User.IsInRole("Admin");
                var isProjectLead = project.LeaderId == userManager.GetUserId(User);
                model.CanEdit           = isAdmin || isProjectLead;
                model.CanDeleteComments = isAdmin || isProjectLead;
                model.Comments          = await comments.GetIssueCommentsAsync(model.Id);

                await GetDropdownValues(projectId, issue.Status);

                return(View(model));
            }

            var result = await issues.EditIssueAsync(model, User);

            this.AddNotification(result.Message, result.NotificationType);
            return(RedirectToAction("Details", "Projects", new { id = projectId }));
        }