Example #1
0
        public ActionResult WhatIfAdjustRules(UpdateIssuePostModel postModel)
        {
            if (!ModelState.IsValid)
            {
                if (Request.IsAjaxRequest())
                {
                    return(new JsonErrorResult());
                }

                return(RedirectWithViewModel(postModel, "index", routeValues: new { id = postModel.IssueId.GetFriendlyId(), tab = IssueTab.Rules.ToString() }));
            }

            var result = _adjustRulesCommand.Invoke(new AdjustRulesRequest
            {
                IssueId       = postModel.IssueId,
                ApplicationId = postModel.ApplicationId,
                Rules         =
                    postModel.Rules.Select(
                        r => (IMatchRule) new PropertyMatchRule(r.ErrorProperty, r.StringOperator, r.Value))
                    .ToList(),
                CurrentUser       = Core.AppContext.CurrentUser,
                NewIssueName      = postModel.AdjustmentName,
                OriginalIssueName = postModel.Name,
                WhatIf            = true,
            });

            return(new JsonSuccessResult(
                       new {
                total = result.ErrorsMatched + result.ErrorsNotMatched,
                matched = result.ErrorsMatched,
                notmatched = result.ErrorsNotMatched,
            }));
        }
Example #2
0
        public ActionResult AdjustRules(UpdateIssuePostModel postModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectWithViewModel(postModel, "index", routeValues: new { id = postModel.IssueId.GetFriendlyId(), tab = IssueTab.Rules.ToString() }));
            }

            try
            {
                var updateResult = _updateIssueDetailsCommand.Invoke(new UpdateIssueDetailsRequest
                {
                    IssueId         = postModel.IssueId,
                    Status          = postModel.Status,
                    Name            = postModel.Name,
                    CurrentUser     = Core.AppContext.CurrentUser,
                    NotifyFrequency = postModel.NotifyFrequency,
                    Reference       = postModel.Reference,
                    AssignedUserId  = postModel.UserId,
                    Comment         = postModel.Comment,
                });

                if (updateResult.Status == UpdateIssueDetailsStatus.IssueNotFound)
                {
                    return(RedirectToAction("notfound", new { FriendlyId = postModel.IssueId.GetFriendlyId() }));
                }

                var result = _adjustRulesCommand.Invoke(new AdjustRulesRequest
                {
                    IssueId           = postModel.IssueId,
                    ApplicationId     = postModel.ApplicationId,
                    Rules             = postModel.Rules.Select(r => (IMatchRule) new PropertyMatchRule(r.ErrorProperty, r.StringOperator, r.Value)).ToList(),
                    CurrentUser       = Core.AppContext.CurrentUser,
                    NewIssueName      = postModel.AdjustmentName,
                    OriginalIssueName = postModel.Name
                });

                switch (result.Status)
                {
                case AdjustRulesStatus.IssueNotFound:
                    return(RedirectToAction("notfound", new { FriendlyId = postModel.IssueId.GetFriendlyId() }));

                case AdjustRulesStatus.Ok:
                    ConfirmationNotification(new MvcHtmlString("Issue details updated successfully, of {0}, {1} still match{2} and remain{3} attached to the issue.{4}".FormatWith(
                                                                   "error".Quantity(result.ErrorsMatched + result.ErrorsNotMatched),
                                                                   result.ErrorsMatched == 1 ? "1" : result.ErrorsNotMatched == 0 ? "all" : result.ErrorsMatched.ToString(),
                                                                   result.ErrorsMatched == 1 ? "es" : "",
                                                                   result.ErrorsMatched == 1 ? "s" : "",
                                                                   result.ErrorsNotMatched > 0
                                ? " The {0} that did not match {1} been attached to newly created issue # <a href='{2}'>{3}</a>".FormatWith(
                                                                       result.ErrorsNotMatched,
                                                                       result.ErrorsNotMatched == 1 ? "has" : "have",
                                                                       Url.Issue(result.UnmatchedIssueId),
                                                                       result.UnmatchedIssueId)
                                : string.Empty
                                                                   )));
                    break;

                default:
                    return(RedirectWithViewModel(postModel, "index", "Issue details were updated successfully, the rules for this issue were not changed.", false, new { id = postModel.IssueId.GetFriendlyId(), tab = IssueTab.Details.ToString() }));
                }

                return(RedirectToAction("index", new { id = result.IssueId.GetFriendlyId(), tab = IssueTab.Details.ToString() }));
            }
            catch (ConcurrencyException)
            {
                ErrorNotification("A background process modified this issue at the same time as you requested to adjust the rules which resulted in a failure, please try again.");
                return(RedirectToAction("index", new { id = postModel.IssueId.GetFriendlyId(), tab = IssueTab.Details.ToString() }));
            }
        }