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)));
            }
        }
        /// <summary>
        /// Converts a list of instance pocos into UI-friendly instance models
        /// </summary>
        /// <param name="instances"></param>
        /// <returns></returns>
        public List <WorkflowInstanceViewModel> ConvertToWorkflowInstanceList(List <WorkflowInstancePoco> instances)
        {
            List <WorkflowInstanceViewModel> workflowInstances = new List <WorkflowInstanceViewModel>();

            if (instances == null || instances.Count <= 0)
            {
                return(workflowInstances);
            }

            foreach (WorkflowInstancePoco instance in instances)
            {
                var model = new WorkflowInstanceViewModel
                {
                    Type          = instance.WorkflowType.Description(instance.ScheduledDate),
                    InstanceGuid  = instance.Guid,
                    Status        = instance.StatusName,
                    CssStatus     = instance.StatusName.ToLower().Split(' ')[0],
                    NodeId        = instance.NodeId,
                    NodeName      = instance.Node?.Name,
                    RequestedBy   = instance.AuthorUser?.Name,
                    RequestedOn   = instance.CreatedDate.ToFriendlyDate(),
                    CreatedDate   = instance.CreatedDate,
                    CompletedDate = instance.CompletedDate,
                    Comment       = instance.AuthorComment,
                    Tasks         = _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), false, instance)
                };

                workflowInstances.Add(model);
            }

            return(workflowInstances.OrderByDescending(x => x.CreatedDate).ToList());
        }
Esempio n. 3
0
        /// <summary>
        /// Converts a list of instance pocos into UI-friendly instance models
        /// </summary>
        /// <param name="instances"></param>
        /// <returns></returns>
        public List <WorkflowInstance> ConvertToWorkflowInstanceList(List <WorkflowInstancePoco> instances)
        {
            List <WorkflowInstance> workflowInstances = new List <WorkflowInstance>();

            if (instances == null || instances.Count <= 0)
            {
                return(workflowInstances.OrderByDescending(x => x.RequestedOn).ToList());
            }

            foreach (WorkflowInstancePoco instance in instances)
            {
                var model = new WorkflowInstance
                {
                    Type        = instance.TypeDescription,
                    Status      = instance.StatusName,
                    CssStatus   = instance.StatusName.ToLower().Split(' ')[0],
                    NodeId      = instance.NodeId,
                    NodeName    = instance.Node.Name,
                    RequestedBy = instance.AuthorUser.Name,
                    RequestedOn = instance.CreatedDate,
                    CompletedOn = instance.CompletedDate,
                    Tasks       = _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance)
                };

                workflowInstances.Add(model);
            }

            return(workflowInstances.OrderByDescending(x => x.RequestedOn).ToList());
        }
Esempio n. 4
0
        public IHttpActionResult GetNodeTasks(int id, int count, int page)
        {
            try
            {
                // todo -> ony fetch the require page, not all
                List <WorkflowTaskInstancePoco> taskInstances = _tasksService.GetTasksByNodeId(id);
                List <WorkflowTask>             workflowItems = _tasksService.ConvertToWorkflowTaskList(taskInstances.Skip((page - 1) * count).Take(count).ToList());

                return(Json(new
                {
                    items = workflowItems,
                    total = taskInstances.Count,
                    page,
                    count
                }, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                string msg = $"Error getting tasks for node {id}";
                Log.Error(msg, ex);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }
Esempio n. 5
0
        public IHttpActionResult GetNodeTasks(int id, int count, int page)
        {
            try
            {
                // todo -> ony fetch the require page, not all
                List <WorkflowTaskInstancePoco> taskInstances = _tasksService.GetTasksByNodeId(id);
                // set sorted to false as the instances are ordered by create date -> sorting will order the paged items by workflow step
                List <WorkflowTask> workflowItems = _tasksService.ConvertToWorkflowTaskList(taskInstances.Skip((page - 1) * count).Take(count).ToList(), false);

                return(Json(new
                {
                    items = workflowItems,
                    totalPages = (int)Math.Ceiling((double)taskInstances.Count / count),
                    page,
                    count
                }, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                string msg = $"Error getting tasks for node {id}";
                Log.Error(msg, ex);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }