Пример #1
0
        private IssueViewModel GetViewModel(IssueErrorsPostModel postModel, PageRequestWithSort paging, bool useSystemUser = false)
        {
            var issue = _getIssueQuery.Invoke(new GetIssueRequest
            {
                IssueId     = postModel.Id,
                CurrentUser = useSystemUser ? Errordite.Core.Domain.Organisation.User.System() : Core.AppContext.CurrentUser
            }).Issue;

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

            var users        = Core.GetUsers();
            var applications = Core.GetApplications();
            var assignedUser = users.Items.FirstOrDefault(u => u.Id == issue.UserId);

            //if the assigned user has been deleted, update it to the current user
            if (assignedUser == null)
            {
                var updateIssue = Core.Session.Raven.Load <Issue>(issue.Id);
                updateIssue.UserId = Core.AppContext.CurrentUser.Id;
                assignedUser       = Core.AppContext.CurrentUser;
            }

            int ii = 0;

            var extraDataKeys = _getExtraDataKeysForIssueQuery.Invoke(new GetExtraDataKeysForIssueRequest
            {
                IssueId = issue.Id,
            }).Keys ?? new List <string>();

            var ruleViewModels = issue.Rules.OfType <PropertyMatchRule>().Select(r => new RuleViewModel
            {
                ErrorProperty  = r.ErrorProperty,
                StringOperator = r.StringOperator,
                Value          = r.Value,
                Index          = ii++,
                Properties     = _configuration.GetRuleProperties(r.ErrorProperty)
                                 .Union(extraDataKeys.Select(k => new SelectListItem
                {
                    Selected = r.ErrorProperty == k,
                    Text     = k,
                    Value    = k
                })),
            }).ToList();

            var updateViewModel = new UpdateIssueViewModel
            {
                ApplicationId           = issue.ApplicationId,
                Rules                   = ruleViewModels,
                Name                    = issue.Name,
                AdjustmentName          = GetAdjustmentRejectsName(issue.Name),
                IssueId                 = issue.Id,
                Users                   = users.Items.ToSelectList(u => u.Id, u => "{0} {1}".FormatWith(u.FirstName, u.LastName), sortListBy: SortSelectListBy.Text, selected: u => u.Id == issue.UserId),
                Statuses                = issue.Status.ToSelectedList(IssueResources.ResourceManager, false, issue.Status == IssueStatus.Unacknowledged ? IssueStatus.Acknowledged.ToString() : issue.Status.ToString()),
                UserId                  = issue.UserId,
                Status                  = issue.Status == IssueStatus.Unacknowledged ? IssueStatus.Acknowledged : issue.Status,
                NotifyFrequency         = issue.NotifyFrequency,
                Reference               = issue.Reference,
                NotificationFrequencies = FrequencyHours,
                Comment                 = null
            };

            var viewModel = new IssueViewModel
            {
                Details = new IssueDetailsViewModel
                {
                    ApplicationId    = issue.ApplicationId,
                    OrganisationId   = issue.OrganisationId,
                    ErrorCount       = issue.ErrorCount,
                    LastErrorUtc     = issue.LastErrorUtc,
                    FirstErrorUtc    = issue.CreatedOnUtc,
                    UserName         = assignedUser == null ? string.Empty : assignedUser.FullName,
                    ApplicationName  = applications.Items.First(a => a.Id == issue.ApplicationId).Name,
                    ErrorLimitStatus = IssueResources.ResourceManager.GetString("ErrorLimitStatus_{0}".FormatWith(issue.LimitStatus)),
                    TestIssue        = issue.TestIssue,
                    IssueId          = issue.Id,
                    Status           = issue.Status,
                    NotifyFrequency  = issue.NotifyFrequency,
                    Reference        = issue.Reference
                },
                Errors    = GetErrorsViewModel(postModel, paging, extraDataKeys),
                Update    = updateViewModel,
                Tab       = postModel.Tab,
                PublicUrl = "{0}/issue/public?token={1}".FormatWith(
                    _configuration.SiteBaseUrl,
                    _encryptor.Encrypt("{0}|{1}|{2}".FormatWith(
                                           Core.AppContext.CurrentUser.ActiveOrganisation.FriendlyId,
                                           issue.FriendlyId,
                                           Core.AppContext.CurrentUser.ActiveOrganisation.ApiKeySalt)).Base64Encode())
            };

            //dont let users set an issue to unacknowledged
            if (issue.Status != IssueStatus.Unacknowledged)
            {
                var statuses = viewModel.Update.Statuses.ToList();
                statuses.Remove(viewModel.Update.Statuses.First(s => s.Value == IssueStatus.Unacknowledged.ToString()));
                viewModel.Update.Statuses = statuses;
            }

            return(viewModel);
        }
Пример #2
0
 public UpdateIssueCommand(UpdateIssueViewModel upVM, IIssueDataService issueDataService)
 {
     _upVM             = upVM;
     _issueDataService = issueDataService;
 }
Пример #3
0
        public async Task <IActionResult> Update(UpdateIssueViewModel model, string projectUrl, string versionUrl, int issueId)
        {
            if (ModelState.IsValid)
            {
                int userId = int.Parse(User.Claims.First(c => c.Type == "UserId").Value);

                if (model.StartDate > model.DueDate)
                {
                    ModelState.AddModelError("DueDate", "Due date cannot be before start date.");
                    return(View(model));
                }

                var version = Database.ProjectVersion
                              .Include(v => v.Project)
                              .Where(v => v.Url == versionUrl && v.Project.Url == projectUrl)
                              .FirstOrDefault();

                if (model.StartDate < version.StartDate)
                {
                    ModelState.AddModelError("StartDate", $"Start date must be after or equal {version.StartDate:dd.MM.yy}");
                    return(View(model));
                }
                if (model.DueDate > version.DueDate)
                {
                    ModelState.AddModelError("DueDate", $"Due date must be before or euqal {version.DueDate:dd.MM.yy}");
                    return(View(model));
                }

                Issue issue = Database.Issue
                              .Where(i => i.Id == issueId)
                              .FirstOrDefault();

                issue.Subject          = model.Subject;
                issue.Description      = model.Description;
                issue.TypeId           = model.TypeId;
                issue.StatusId         = model.StatusId;
                issue.PriorityId       = model.PriorityId;
                issue.StartDate        = model.StartDate;
                issue.DueDate          = model.DueDate;
                issue.EstimatedTime    = model.EstimatedTime;
                issue.Done             = model.Done;
                issue.ProjectVersionId = version.Id;
                issue.ParentIssueId    = model.ParentIssueId == 0 ? (int?)null : model.ParentIssueId;

                var user = Database.User
                           .Where(u => u.Id == userId)
                           .FirstOrDefault();

                await Database.SaveChangesAsync();

                ProjectActivity activity = new ProjectActivity
                {
                    ProjectId = version.ProjectId,
                    AuthorId  = userId,
                    Content   = $"Updated issue '#{issue.Id}: {issue.Subject}'"
                };
                Database.ProjectActivity.Add(activity);

                await Database.SaveChangesAsync();

                return(RedirectToAction("Index", "Issue", new { projectUrl = projectUrl, versionUrl = versionUrl, issueId = issue.Id }));
            }

            return(View(model));
        }