Esempio n. 1
0
        public IHttpActionResult InitiateWorkflow(InitiateWorkflowModel model)
        {
            try
            {
                WorkflowProcess process;

                if (model.Publish)
                {
                    process = new DocumentPublishProcess();
                }
                else
                {
                    process = new DocumentUnpublishProcess();
                }

                IUser currentUser             = _utility.GetCurrentUser();
                WorkflowInstancePoco instance = process.InitiateWorkflow(int.Parse(model.NodeId), currentUser.Id, model.Comment);

                string msg = string.Empty;

                switch (instance.WorkflowStatus)
                {
                case WorkflowStatus.PendingApproval:
                    msg = $"Page submitted for {(model.Publish ? "publish" : "unpublish")} approval.";
                    break;

                case WorkflowStatus.Approved:
                    msg = (model.Publish ? "Publish" : "Unpublish") + " workflow complete.";

                    if (instance.ScheduledDate.HasValue)
                    {
                        msg += $" Page scheduled for publishing at {instance.ScheduledDate.Value.ToString("dd MMM YYYY", CultureInfo.CurrentCulture)}";
                    }

                    break;
                }

                Log.Info(msg);

                // broadcast the new task back to the client to update dashboards etc
                // needs to be converted from a poco to remove unused properties and force camelCase
                _hubContext.Clients.All.WorkflowStarted(
                    _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance: instance)
                    .FirstOrDefault());

                return(Json(new
                {
                    message = msg,
                    status = 200
                }, ViewHelpers.CamelCase));
            }
            catch (Exception e)
            {
                const string msg = "An error occurred initiating the workflow";
                Log.Error(msg, e);

                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(e, msg)));
            }
        }
Esempio n. 2
0
        public IHttpActionResult InitiateWorkflow(InitiateWorkflowModel model)
        {
            try
            {
                WorkflowProcess process;

                if (model.Publish)
                {
                    process = new DocumentPublishProcess();
                }
                else
                {
                    process = new DocumentUnpublishProcess();
                }

                WorkflowInstancePoco instance = process.InitiateWorkflow(int.Parse(model.NodeId), _utility.GetCurrentUser().Id, model.Comment);

                string msg = string.Empty;

                switch (instance.WorkflowStatus)
                {
                case WorkflowStatus.PendingApproval:
                    msg = $"Page submitted for {(model.Publish ? "publish" : "unpublish")} approval.";
                    break;

                case WorkflowStatus.Approved:
                    msg = (model.Publish ? "Publish" : "Unpublish") + " workflow complete.";

                    if (instance.ScheduledDate.HasValue)
                    {
                        msg += $" Page scheduled for publishing at {instance.ScheduledDate.Value.ToString("dd MMM YYYY", CultureInfo.CurrentCulture)}";
                    }

                    break;
                }

                Log.Info(msg);

                return(Json(new
                {
                    message = msg,
                    status = 200
                }, ViewHelpers.CamelCase));
            }
            catch (Exception e)
            {
                const string msg = "An error occurred initiating the workflow";
                Log.Error(msg, e);

                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(e, msg)));
            }
        }
Esempio n. 3
0
        public IHttpActionResult InitiateWorkflow(InitiateWorkflowModel model)
        {
            try
            {
                WorkflowApprovalProcess process;

                if (model.Publish)
                {
                    process = new DocumentPublishProcess();
                }
                else
                {
                    process = new DocumentUnpublishProcess();
                }

                var instance = process.InitiateWorkflow(int.Parse(model.NodeId), Utility.GetCurrentUser().Id, model.Comment);

                var msg = string.Empty;

                switch (instance.WorkflowStatus)
                {
                case WorkflowStatus.PendingApproval:
                    msg = "Page submitted for " + (model.Publish ? "publish" : "unpublish") + " approval.";
                    break;

                case WorkflowStatus.Approved:
                    msg = (model.Publish ? "Publish" : "Unpublish") + " workflow complete.";

                    if (instance.ScheduledDate.HasValue)
                    {
                        msg += " Page scheduled for publishing at " + instance.ScheduledDate.ToString();
                    }

                    break;
                }

                return(Json(new
                {
                    message = msg,
                    status = 200
                }, ViewHelpers.CamelCase));
            }
            catch (Exception e)
            {
                return(Json(new
                {
                    message = ViewHelpers.ApiException(e),
                    status = 500
                }, ViewHelpers.CamelCase));
            }
        }