Exemple #1
0
        public IHttpActionResult RejectWorkflowTask(TaskData model)
        {
            WorkflowInstancePoco instance = GetInstance(model.InstanceGuid);

            try
            {
                WorkflowProcess 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 ApproveWorkflowTask(TaskData model)
        {
            WorkflowInstancePoco instance = GetInstance(model.InstanceGuid);

            try
            {
                WorkflowProcess 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 #3
0
        public IHttpActionResult RejectWorkflowTask(TaskData model)
        {
            WorkflowInstancePoco instance = _instancesService.GetPopulatedInstance(model.InstanceGuid);

            try
            {
                WorkflowProcess process     = instance.GetProcess();
                IUser           currentUser = _utility.GetCurrentUser();

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

                string typeDescription = instance.WorkflowType.Description(instance.ScheduledDate);

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

                _hubContext.Clients.All.TaskRejected(
                    _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance: instance));

                if (model.Offline)
                {
                    UmbracoContext.Security.ClearCurrentLogin();
                }

                return(Json(new
                {
                    message = 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 #4
0
        public IHttpActionResult ApproveWorkflowTask(TaskData model)
        {
            WorkflowInstancePoco instance = _instancesService.GetPopulatedInstance(model.InstanceGuid);
            WorkflowProcess      process  = instance.GetProcess();

            try
            {
                IUser currentUser = _utility.GetCurrentUser();

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

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

                string typeDescription     = instance.WorkflowType.Description(instance.ScheduledDate);
                string typeDescriptionPast = instance.WorkflowType.DescriptionPastTense(instance.ScheduledDate);

                switch (instance.WorkflowStatus)
                {
                case WorkflowStatus.PendingApproval:
                    msg    = $"Approval completed successfully. Page will be {typeDescriptionPast.ToLower()} following workflow completion.";
                    logMsg = $"Workflow {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 {typeDescription} at {instance.ScheduledDate.Value.ToString("dd MMM yyyy", CultureInfo.CurrentCulture)}";
                        msg    += scheduled;
                        logMsg += scheduled;
                    }
                    else
                    {
                        msg += $" Page has been {typeDescriptionPast.ToLower()}";
                    }
                    break;
                }

                Log.Info(logMsg);

                _hubContext.Clients.All.TaskApproved(
                    _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance: instance));

                if (model.Offline)
                {
                    UmbracoContext.Security.ClearCurrentLogin();
                }

                return(Json(new
                {
                    message = msg,
                    status = 200,
                    notifications = NotificationHelpers.MapEventMessagesToNotifications(process.EventMessages)
                }, ViewHelpers.CamelCase));
            }
            catch (UmbracoOperationFailedException e)
            {
                string msg = $"A Publishing failure occurred processing the approval on {instance.Node.Name} [{instance.Node.Id}]";
                Log.Error(msg, e);

                return(Json(new
                {
                    message = msg,
                    status = 200,
                    isUmbracoOperationError = true,
                    notifications = NotificationHelpers.MapEventMessagesToNotifications(process.EventMessages)
                }
                            , 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)));
            }
        }