Example #1
0
        public IHttpActionResult DoInvoiceWorkflowAction(InvoicesApprovalWorkflow workflow)
        {
            if (workflow == null)
            {
                return(BadRequest("workflow object must be passed in the request body"));
            }
            try
            {
                var wfProcessor = new InvoiceWorkflowProcessor();
                var dbWorkflow  = wfProcessor.ChangeWorkflowStageAction(workflow.Id, (int)workflow.Status, workflow.Remarks, User.FullName);

                var currentStageOrderNumber = workflowService.
                                              GetWorkflowStage(dbWorkflow.StageId).
                                              StageOrderNumber;

                var nextStageSerialNumber = currentStageOrderNumber + 1;
                var nextStage             = workflowService.GetWorkflowStages().SingleOrDefault(w => w.StageOrderNumber == nextStageSerialNumber);

                if (nextStage != null)
                {
                    var nextPaymentWorkflow = new InvoicesApprovalWorkflow()
                    {
                        CreatedBy       = User.UserId,
                        CreatedDate     = DateTime.Now,
                        IsActive        = true,
                        InvoiceId       = dbWorkflow.InvoiceId,
                        ProcessedDate   = null,
                        StageId         = nextStage.StageId,
                        Status          = (int)WorkflowLevelStatus.Forwarded,
                        Remarks         = null,
                        IsFinished      = false,
                        ReferenceNumber = "",
                        SequentialId    = nextStageSerialNumber
                    };
                    wfProcessor.ForwardNextStage(nextPaymentWorkflow, nextStage);
                }
                else
                {
                    var taskId = invoicesService.GetInvoice(workflow.InvoiceId).MilestoneId;
                    TasksHandler.Finish(taskId);
                }

                var workflows = invoicesService.GetUserInvoiceWorkflow(User.UserId).Where(l => l.InvoiceId == dbWorkflow.InvoiceId);
                var html      = Helpers.RenderPartial("~/Views/Shared/Partial/Invoices/InvoiceWorkflowList.cshtml", workflows);
                return(Ok(html));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
 public void FinishTaskPercentage(int taskId)
 {
     TasksHandler.Finish(taskId);
 }