public IHttpActionResult RejectWorkflowTask(TaskData model)
        {
            WorkflowInstancePoco instance = GetInstance(model.InstanceGuid);

            try
            {
                WorkflowApprovalProcess process = GetProcess(instance.Type);
                IUser currentUser = Utility.GetCurrentUser();

                instance = process.ActionWorkflow(
                    instance,
                    WorkflowAction.Reject,
                    currentUser.Id,
                    model.Comment
                    );

                Log.Info($"{instance.TypeDescription} request for {instance.Node.Name} [{instance.NodeId}] was rejected by {currentUser.Name}");

                return(Json(new
                {
                    message = instance.TypeDescription + " request has been rejected.",
                    status = 200
                }, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                string msg = $"An error occurred rejecting the workflow on {instance.Node.Name} [{instance.NodeId}]";
                Log.Error(msg, ex);

                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }
Exemple #2
0
        public IHttpActionResult RejectWorkflowTask(TaskData model)
        {
            var instance = GetInstance(model.InstanceGuid);

            try
            {
                WorkflowApprovalProcess process = GetProcess(instance.Type);

                instance = process.ActionWorkflow(
                    instance,
                    WorkflowAction.Reject,
                    Utility.GetCurrentUser().Id,
                    model.Comment
                    );

                return(Json(new
                {
                    message = instance.TypeDescription + " request has been rejected.",
                    status = 200
                }, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                var msg = "An error occurred rejecting the workflow: " + ex.Message + ex.StackTrace;
                Log.Error(msg + " for workflow " + instance.Id, ex);

                return(Json(new
                {
                    message = msg,
                    status = 500
                }, ViewHelpers.CamelCase));
            }
        }
        public IHttpActionResult ApproveWorkflowTask(TaskData model)
        {
            WorkflowInstancePoco instance = GetInstance(model.InstanceGuid);

            try
            {
                WorkflowApprovalProcess process = GetProcess(instance.Type);
                IUser currentUser = Utility.GetCurrentUser();

                instance = process.ActionWorkflow(
                    instance,
                    WorkflowAction.Approve,
                    currentUser.Id,
                    model.Comment
                    );

                string msg    = string.Empty;
                string logMsg = string.Empty;

                switch (instance.WorkflowStatus)
                {
                case WorkflowStatus.PendingApproval:
                    msg    = $"Approval completed successfully. Page will be {instance.TypeDescriptionPastTense.ToLower()} following workflow completion.";
                    logMsg = $"Workflow {instance.TypeDescription} task on {instance.Node.Name} [{instance.NodeId}] approved by {currentUser.Name}";
                    break;

                case WorkflowStatus.Approved:
                    msg    = "Workflow approved successfully.";
                    logMsg = $"Workflow approved by {currentUser.Name} on {instance.Node.Name} [{instance.NodeId}]";

                    if (instance.ScheduledDate.HasValue)
                    {
                        string scheduled = $" Page scheduled for {instance.TypeDescription} at {instance.ScheduledDate.Value.ToString("dd MMM YYYY", CultureInfo.CurrentCulture)}";
                        msg    += scheduled;
                        logMsg += scheduled;
                    }
                    else
                    {
                        msg += $" Page has been {instance.TypeDescriptionPastTense.ToLower()}";
                    }
                    break;
                }

                Log.Info(logMsg);

                return(Json(new
                {
                    message = msg,
                    status = 200
                }, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                string msg = $"An error occurred processing the approval on {instance.Node.Name} [{instance.Node.Id}]";
                Log.Error(msg, ex);

                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }
Exemple #4
0
        public IHttpActionResult ApproveWorkflowTask(TaskData model)
        {
            var instance = GetInstance(model.InstanceGuid);

            try
            {
                WorkflowApprovalProcess process = GetProcess(instance.Type);

                instance = process.ActionWorkflow(
                    instance,
                    WorkflowAction.Approve,
                    Utility.GetCurrentUser().Id,
                    model.Comment
                    );

                var msg = string.Empty;

                switch (instance.WorkflowStatus)
                {
                case WorkflowStatus.PendingApproval:
                    msg = "Approval completed successfully. Page will be " + instance.TypeDescriptionPastTense.ToLower() + " following workflow completion.";
                    break;

                case WorkflowStatus.Approved:
                    msg = "Workflow approved successfully.";

                    if (instance.ScheduledDate.HasValue)
                    {
                        msg += " Page scheduled for " + instance.TypeDescription + " at " + instance.ScheduledDate.ToString();
                    }
                    else
                    {
                        msg += " Page has been " + instance.TypeDescriptionPastTense.ToLower();
                    }
                    break;
                }

                return(Json(new
                {
                    message = msg,
                    status = 200
                }, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                var msg = "An error occurred processing the approval: " + ex.Message + ex.StackTrace;
                Log.Error(msg + " for workflow " + instance.Id, ex);
                return(Json(new
                {
                    message = msg,
                    status = 500
                }, ViewHelpers.CamelCase));
            }
        }