Exemple #1
0
        public AdvanceViewModel(WorkflowQuestionChoices workflowQuestionChoices, UnliqudatedObjectsWorkflowQuestion question, Workflow workflow, DateTime?expectedDateForCompletion, bool expectedDateForCompletionEditable)
        {
            var workflowId = workflow.WorkflowId;

            WorkflowRowVersionString = workflow.WorkflowRowVersionString;
            EditingBeganAtUtc        = DateTime.UtcNow;
            Answer   = question != null ? question.Answer : "";
            Comments = question != null ? question.Comments : "";
            UnliqudatedWorkflowQuestionsId = question?.UnliqudatedWorkflowQuestionsId ?? 0;
            JustificationKey                  = question?.JustificationKey;
            ExpectedDateForCompletion         = expectedDateForCompletion;
            ExpectedDateForCompletionEditable = expectedDateForCompletionEditable;
            var ulo = workflow.TargetUlo;

            PDN     = ulo.PegasysDocumentNumber;
            IsValid = ulo.Valid;
            //            workflow.WorkflowRowVersionString;
            if (workflowQuestionChoices != null)
            {
                QuestionLabel = workflowQuestionChoices.QuestionLabel;
                foreach (var questionChoice in workflowQuestionChoices.WhereMostApplicable(workflow.TargetUlo.DocType, workflow.MostRecentNonReassignmentAnswer, workflow.MostRecentRealAnswer))
                {
                    QuestionChoices.Add(new QuestionChoicesViewModel(questionChoice));
                }
            }
        }
        public async Task <ActionResult> RequestReassign(
            int workflowId,
            [Bind(Include =
                      nameof(RequestForReassignmentViewModel.WorkflowId) + "," +
                      nameof(RequestForReassignmentViewModel.SuggestedReviewerId) + "," +
                      nameof(RequestForReassignmentViewModel.JustificationKey) + "," +
                      nameof(RequestForReassignmentViewModel.Comments))]
            RequestForReassignmentViewModel requestForReassignmentViewModel)
        {
            if (ModelState.IsValid)
            {
                var wf = await FindWorkflowAsync(workflowId);

                if (wf == null)
                {
                    return(HttpNotFound());
                }
                var question = new UnliqudatedObjectsWorkflowQuestion
                {
                    JustificationKey   = requestForReassignmentViewModel.JustificationKey,
                    UserId             = CurrentUserId,
                    Answer             = UnliqudatedObjectsWorkflowQuestion.CommonAnswers.RequestForReasssignment,
                    WorkflowId         = workflowId,
                    Comments           = requestForReassignmentViewModel.Comments,
                    WorkflowRowVersion = wf.WorkflowRowVersion,
                    CreatedAtUtc       = DateTime.UtcNow
                };
                DB.UnliqudatedObjectsWorkflowQuestions.Add(question);
                await DB.SaveChangesAsync();

                return(await RequestReassign(wf, question, requestForReassignmentViewModel.SuggestedReviewerId));
            }

            return(PartialView("~/Views/Ulo/Details/Workflow/RequestForReassignments/_Details.cshtml", requestForReassignmentViewModel));
        }
        private async Task <IActionResult> RequestReassign(Workflow wf, UnliqudatedObjectsWorkflowQuestion question, string suggestedReviewerId)
        {
            var requestForReassignment = new RequestForReassignment
            {
                SuggestedReviewerId            = suggestedReviewerId,
                UnliqudatedWorkflowQuestionsId = question.UnliqudatedWorkflowQuestionsId,
                WorkflowId = wf.WorkflowId,
                IsActive   = true
            };

            DB.RequestForReassignment.Add(requestForReassignment);
            var ret = await Manager.RequestReassignAsync(wf);

            await DB.SaveChangesAsync();

            return(ret);
        }
Exemple #4
0
 public UloWfQuestionViewModel(IDictionary <string, Justification> justificationByKey, UnliqudatedObjectsWorkflowQuestion question)
 {
     Username = question.User.UserName;
     // Username = question.UserId;
     Answer           = question.Answer;
     JustificationKey = question.JustificationKey;
     Justification    = justificationByKey.FindOrDefault(question.JustificationKey ?? "")?.Description;
     Comments         = question.Comments;
     CreatedAtUtc     = question.CreatedAtUtc;
 }
Exemple #5
0
        async Task <IActionResult> IWorkflowManager.AdvanceAsync(Workflow wf, UnliqudatedObjectsWorkflowQuestion question, IList <string> submitterGroupNames, bool forceAdvance, bool ignoreActionResult, bool sendNotifications)
        {
            Requires.NonNull(wf, nameof(wf));

            string nextOwnerId     = "";
            var    desc            = await(this as IWorkflowManager).GetWorkflowDescriptionAsync(wf);
            var    currentActivity = desc.WebActionWorkflowActivities.FirstOrDefault(z => z.WorkflowActivityKey == wf.CurrentWorkflowActivityKey);

            //if question is null stays in current activity
            string nextActivityKey = "";

            try
            {
                BusinessLayer.Workflow.WorkflowActivity nextActivity;
                if (question != null)
                {
                    var t = ActivityChooserTypes.FirstOrDefault(z => z.Name == currentActivity.NextActivityChooserTypeName);
                    if (t == null)
                    {
                        LogError("Cannot find type for NextActivityChooser of name {NextActivityChooserTypeName}", currentActivity.NextActivityChooserTypeName);
                    }
                    var chooser = (IActivityChooser)ServiceProvider.GetService(t);
                    nextActivityKey = chooser.GetNextActivityKey(wf, question, currentActivity.NextActivityChooserConfig, submitterGroupNames) ?? wf.CurrentWorkflowActivityKey;
                    nextActivity    = desc.Activities.First(z => z.WorkflowActivityKey == nextActivityKey) ?? currentActivity;
                }
                else
                {
                    nextActivity = currentActivity;
                }

                //TODO: Handle null case which says stay where you are.
                wf.CurrentWorkflowActivityKey = nextActivity.WorkflowActivityKey;

                //TODO: Updata other info like the owner, date
                //TODO: Add logic for handling groups of users.
                if (nextActivity is WebActionWorkflowActivity)
                {
                    if ((wf.CurrentWorkflowActivityKey != currentActivity.WorkflowActivityKey && wf.OwnerUser.UserName != nextActivity.OwnerUserName) || forceAdvance == true)
                    {
                        nextOwnerId = await GetNextOwnerUserIdAsync(wf, null, nextActivity.WorkflowActivityKey);

                        wf.OwnerUserId = nextOwnerId;

                        if (sendNotifications)
                        {
                            await NotifyNewAssigneeAsync(wf, nextOwnerId, nextActivity.EmailTemplateId);
                        }
                    }
                    wf.TargetUlo.Status = nextActivity.ActivityName;

                    if (nextActivity.DueIn != null)
                    {
                        wf.ExpectedDurationInSeconds = (long?)nextActivity.DueIn.Value.TotalSeconds;
                    }

                    if (question != null && question.IsValid)
                    {
                        wf.TargetUlo.Valid = true;
                    }
                    else if (question != null && question.IsInvalid)
                    {
                        wf.TargetUlo.Valid = false;
                    }

                    if (ignoreActionResult)
                    {
                        return(null);
                    }

                    //TODO: if owner changes, look at other ways of redirecting.

                    var next = (WebActionWorkflowActivity)nextActivity;
                    var c    = new RedirectingController();

                    var routeValues = new RouteValueDictionary(next.RouteValueByName);
                    //routeValues[WorkflowIdRouteValueName] = wf.WorkflowId;
                    return(c.RedirectToAction(next.ActionName, next.ControllerName, routeValues));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            finally
            {
                LogInformation("Workflow {WorkflowId} with {WorkflowKey} changing from activity {OldWorkflowActivityKey} to activity {NewWorkflowActivityKey} owned By {NewOwnerId}", wf.WorkflowId, wf.WorkflowKey, currentActivity, wf.CurrentWorkflowActivityKey, nextOwnerId);
            }
        }
        public async Task <ActionResult> Save(
            int uloId,
            int workflowId,
            [Bind(Include =
                      nameof(AdvanceViewModel.JustificationKey) + "," +
                      nameof(AdvanceViewModel.Answer) + "," +
                      nameof(AdvanceViewModel.ExpectedDateForCompletion) + "," +
                      nameof(AdvanceViewModel.Comments) + "," +
                      nameof(AdvanceViewModel.WorkflowRowVersionString) + "," +
                      nameof(AdvanceViewModel.EditingBeganAtUtc) + "," +
                      nameof(AdvanceViewModel.UnliqudatedWorkflowQuestionsId))]
            AdvanceViewModel advanceModel = null)
        {
            var wf = await DB.FindWorkflowAsync(workflowId);

            if (wf == null)
            {
                return(HttpNotFound());
            }
            if (ModelState.IsValid)
            {
                Log.Information("Altering ULO {UloId} with Workflow {WorkflowId} via command {AlterCommand}", uloId, workflowId, Request["WhatNext"]);

                if (wf.WorkflowRowVersionString != advanceModel.WorkflowRowVersionString)
                {
                    LogStaleWorkflowError(wf, advanceModel.WorkflowRowVersionString, advanceModel.EditingBeganAtUtc);
                    var staleMessage = GetStaleWorkflowErrorMessage(wf, advanceModel.WorkflowRowVersionString, advanceModel.EditingBeganAtUtc);
                    AddPageAlert(staleMessage, false, PageAlert.AlertTypes.Danger, true);
                    return(RedirectToAction(ActionNames.Details, new { uloId = wf.TargetUloId, workflowId = wf.WorkflowId }));
                }

                var submit   = Request["WhatNext"] == "Submit";
                var question = await DB.UnliqudatedObjectsWorkflowQuestions.Where(z => z.WorkflowId == workflowId).OrderByDescending(z => z.UnliqudatedWorkflowQuestionsId).FirstOrDefaultAsync();

                if (question == null || !question.Pending)
                {
                    if (question != null)
                    {
                        question.Pending = false;
                    }
                    question = new UnliqudatedObjectsWorkflowQuestion
                    {
                        WorkflowId = workflowId
                    };
                    DB.UnliqudatedObjectsWorkflowQuestions.Add(question);
                }
                question.JustificationKey = advanceModel.JustificationKey;
                question.UserId           = CurrentUserId;
                question.Answer           = advanceModel.Answer;
                question.Comments         = advanceModel.Comments;
                question.Pending          = !submit;
                question.UnliqudatedWorkflowQuestionsId = advanceModel.UnliqudatedWorkflowQuestionsId;
                question.WorkflowRowVersion             = wf.WorkflowRowVersion;
                question.CreatedAtUtc = DateTime.UtcNow;
                wf.UnliquidatedObligation.ExpectedDateForCompletion = advanceModel.ExpectedDateForCompletion;
                await DB.SaveChangesAsync();

                if (submit)
                {
                    var ulo = await DB.UnliquidatedObligations.FindAsync(uloId);

                    var groupNames = ulo != null && ulo.RegionId != null?User.GetUserGroupNames(ulo.RegionId.Value) : Empty.StringArray.ToList();

                    var ret = await Manager.AdvanceAsync(wf, question, groupNames, Properties.Settings.Default.ForceAdvanceFromUloSubmit);

                    await DB.SaveChangesAsync();

                    AddPageAlert($"WorkflowId={workflowId} for UloId={uloId} on PDN={wf.UnliquidatedObligation.PegasysDocumentNumber} was submitted.", false, PageAlert.AlertTypes.Success, true);
                    return(ret);
                }
                else
                {
                    AddPageAlert($"WorkflowId={workflowId} for UloId={uloId} on PDN={wf.UnliquidatedObligation.PegasysDocumentNumber} was saved.", false, PageAlert.AlertTypes.Success, true);
                    return(RedirectToIndex());
                }
            }
            return(await Details(uloId, workflowId));
        }