public string GetNotifications(int instanceId, int emailType)
        {
            try
            {
                WorkflowInstancePoco instance = Pr.GetAllInstances().FirstOrDefault(x => x.Id == instanceId);

                Notifications.Send(instance, (EmailType)emailType);

                return("done - check the mail drop folder");
            }
            catch (Exception e)
            {
                return(ViewHelpers.ApiException(e).ToString());
            }
        }
Example #2
0
        public IHttpActionResult SaveConfig(Dictionary <int, List <UserGroupPermissionsPoco> > model)
        {
            try
            {
                bool success = _configService.UpdateNodeConfig(model);
                return(Ok(success));
            }
            catch (Exception ex)
            {
                const string msg = "Error saving config";
                Log.Error(msg, ex);

                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }
Example #3
0
        public async Task <IHttpActionResult> Get()
        {
            try
            {
                ImportExportModel export = await _exportService.Export();

                return(Json(export, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                const string error = "Error exporting workflow configuration";
                Log.Error(error, ex);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, error)));
            }
        }
Example #4
0
        public string GetNotifications(Guid instanceGuid, int emailType)
        {
            try
            {
                WorkflowInstancePoco instance = _instancesService.GetByGuid(instanceGuid);

                _emailer.Send(instance, (EmailType)emailType);

                return($"Notifications sent for { instance.Id }. Check the mail pickup folder.");
            }
            catch (Exception e)
            {
                return(ViewHelpers.ApiException(e).ToString());
            }
        }
Example #5
0
        public IHttpActionResult Put(UserGroupPoco group)
        {
            bool nameExists  = Pr.UserGroupsByName(group.Name).Any();
            bool aliasExists = Pr.UserGroupsByAlias(group.Alias).Any();

            try
            {
                UserGroupPoco userGroup = Pr.UserGroupsById(group.GroupId).First();

                // need to check the new name/alias isn't already in use
                if (userGroup.Name != group.Name && nameExists)
                {
                    return(Content(HttpStatusCode.OK, new { status = 500, msg = "Group name already exists" }));
                }

                if (userGroup.Alias != group.Alias && aliasExists)
                {
                    return(Content(HttpStatusCode.OK, new { status = 500, msg = "Group alias already exists" }));
                }

                // Update the Members - TODO - should find a more efficient way to do this...
                Database db = DatabaseContext.Database;

                db.Execute("DELETE FROM WorkflowUser2UserGroup WHERE GroupId = @0", userGroup.GroupId);

                if (group.Users.Count > 0)
                {
                    foreach (User2UserGroupPoco user in group.Users)
                    {
                        db.Insert(user);
                    }
                }

                db.Update(group);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex)));
            }

            // feedback to the browser
            string msgText = $"User group '{group.Name}' has been saved.";

            Log.Debug(msgText);

            return(Ok(new { status = 200, msg = msgText }));
        }
Example #6
0
        public IHttpActionResult GetVersion()
        {
            try
            {
                MemoryCache cache = MemoryCache.Default;
                if (cache[MagicStrings.VersionKey] != null)
                {
                    return(Json((PackageVersion)cache.Get(MagicStrings.VersionKey), ViewHelpers.CamelCase));
                }

                Assembly assembly = Assembly.GetExecutingAssembly();
                Version  version  = assembly.GetName().Version;

                var client = new WebClient();
                client.Headers.Add("user-agent", MagicStrings.Name);

                string  response = client.DownloadString(MagicStrings.LatestVersionUrl);
                JObject content  = JObject.Parse(response);

                string currentVersion = $"v{version.Major}.{version.Minor}.{version.Build}";
                string latestVersion  = content["tag_name"].ToString();

                var packageVersion = new PackageVersion
                {
                    CurrentVersion = currentVersion,
                    LatestVersion  = latestVersion,
                    ReleaseDate    = DateTime.Parse(content["published_at"].ToString()).ToString("d MMMM yyyy"),
                    ReleaseNotes   = content["body"].ToString(),
                    PackageUrl     = content["assets"][0]["browser_download_url"].ToString(),
                    PackageName    = content["assets"][0]["name"].ToString(),
                    OutOfDate      = !string.Equals(currentVersion, latestVersion,
                                                    StringComparison.InvariantCultureIgnoreCase)
                };


                // Store data in the cache
                cache.Add(MagicStrings.VersionKey, packageVersion,
                          new CacheItemPolicy {
                    AbsoluteExpiration = DateTime.Now.AddHours(6)
                });

                return(Json(packageVersion, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex)));
            }
        }
Example #7
0
 public IHttpActionResult GetStatus(int id)
 {
     try
     {
         List <WorkflowInstancePoco> instances = Pr.InstancesByNodeAndStatus(id, new List <int> {
             (int)WorkflowStatus.PendingApproval
         });
         return(Ok(instances.Any()));
     }
     catch (Exception ex)
     {
         string msg = $"Error getting status for node {id}";
         Log.Error(msg, ex);
         return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
     }
 }
 public IHttpActionResult GetAllInstancesForDateRange(int days)
 {
     try
     {
         var instances = Pr.GetAllInstancesForDateRange(DateTime.Now.AddDays(days * -1)).ToWorkflowInstanceList();
         return(Json(new
         {
             items = instances,
             total = instances.Count
         }, ViewHelpers.CamelCase));
     }
     catch (Exception e)
     {
         return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(e)));
     }
 }
Example #9
0
 public IHttpActionResult GetTask(int id)
 {
     try
     {
         return(Json(new
         {
             task = _tasksService.GetTask(id)
         }, ViewHelpers.CamelCase));
     }
     catch (Exception ex)
     {
         string msg = $"Error getting task {id}";
         Log.Error(msg, ex);
         return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
     }
 }
Example #10
0
        public IHttpActionResult Delete(int id)
        {
            // existing workflow processes are left as is, and need to be managed by a human person
            try
            {
                DatabaseContext.Database.Execute("UPDATE WorkflowUserGroups SET Deleted = 1 WHERE GroupId = @0", id);
            }
            catch (Exception ex)
            {
                Log.Error($"Error deleting user group. {ex.Message}", ex);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, "Error deleting user group")));
            }

            // gone.
            return(Ok("User group has been deleted"));
        }
        public async Task <IHttpActionResult> GetFlowsForUser(int userId, int type, int count, int page)
        {
            try
            {
                List <WorkflowTaskPoco> taskInstances = (type == 0
                    ? _tasksService.GetAllPendingTasks(new List <int>
                {
                    (int)TaskStatus.PendingApproval, (int)TaskStatus.Rejected
                })
                    : _tasksService.GetTaskSubmissionsForUser(userId, new List <int>
                {
                    (int)TaskStatus.PendingApproval, (int)TaskStatus.Rejected
                }))
                                                        .Where(x => x.WorkflowInstance.Active)
                                                        .ToList();


                if (type == 0)
                {
                    foreach (WorkflowTaskPoco taskInstance in taskInstances)
                    {
                        taskInstance.UserGroup = await _groupService.GetPopulatedUserGroupAsync(taskInstance.UserGroup.GroupId);
                    }

                    taskInstances = taskInstances.Where(x =>
                                                        x.UserGroup.IsMember(userId) ||
                                                        x.Status == (int)TaskStatus.Rejected && x.WorkflowInstance.AuthorUserId == userId).ToList();
                }

                taskInstances = taskInstances.Where(x => x.WorkflowInstance.Node != null && !x.WorkflowInstance.Node.Path.Contains(UmbConstants.System.RecycleBinContentString)).ToList();
                List <WorkflowTaskViewModel> 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 trying to build user workflow tasks list for user {userId}";
                Log.Error(msg, ex);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }
        public string GetNotifications(Guid instanceGuid, int emailType)
        {
            try
            {
                WorkflowInstancePoco instance = _instancesService.GetByGuid(instanceGuid);

                var node = _utility.GetPublishedContent(1078);

                _notifications.Send(instance, (EmailType)emailType);

                return(node.Name);
            }
            catch (Exception e)
            {
                return(ViewHelpers.ApiException(e).ToString());
            }
        }
Example #13
0
        public async Task <IHttpActionResult> Delete(int id)
        {
            // existing workflow processes are left as is, and need to be managed by a human person
            try
            {
                await groupService.DeleteUserGroupAsync(id);
            }
            catch (Exception ex)
            {
                const string msg = "Error deleting user group";
                Log.Error(msg, ex);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }

            // gone.
            return(Ok("User group has been deleted"));
        }
Example #14
0
        public async Task <IHttpActionResult> Delete(int id)
        {
            // existing workflow processes are left as is, and need to be managed by a human person
            try
            {
                await _groupService.DeleteUserGroupAsync(id);
            }
            catch (Exception ex)
            {
                Log.Error(Constants.ErrorDeletingGroup, ex);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, Constants.ErrorDeletingGroup)));
            }

            // gone.
            Log.Debug($"User group {id} deleted by {_utility.GetCurrentUser()?.Name}");
            return(Ok("User group has been deleted"));
        }
Example #15
0
 public IHttpActionResult GetAllInstancesForDateRange(int days)
 {
     try
     {
         List <WorkflowInstance> instances = Pr.GetAllInstancesForDateRange(DateTime.Now.AddDays(days * -1)).ToWorkflowInstanceList();
         return(Json(new
         {
             items = instances,
             total = instances.Count
         }, ViewHelpers.CamelCase));
     }
     catch (Exception e)
     {
         const string error = "Error getting instances for date range";
         Log.Error(error, e);
         return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(e, error)));
     }
 }
Example #16
0
 public IHttpActionResult GetAllTasksForDateRange(int days)
 {
     try
     {
         List <WorkflowTaskInstancePoco> taskInstances = Pr.GetAllTasksForDateRange(DateTime.Now.AddDays(days * -1));
         return(Json(new
         {
             items = taskInstances,
             total = taskInstances.Count
         }, ViewHelpers.CamelCase));
     }
     catch (Exception ex)
     {
         const string msg = "Error getting tasks for date range";
         Log.Error(msg, ex);
         return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
     }
 }
Example #17
0
 public IHttpActionResult GetNodeTasks(int id, int count, int page)
 {
     try
     {
         var taskInstances = Pr.TasksByNode(id);
         var workflowItems = taskInstances.Skip((page - 1) * count).Take(count).ToList().ToWorkflowTaskList();
         return(Json(new
         {
             items = workflowItems,
             total = taskInstances.Count,
             page,
             count
         }, ViewHelpers.CamelCase));
     }
     catch (Exception e)
     {
         return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(e)));
     }
 }
Example #18
0
 public IHttpActionResult GetAllTasksForGroup(int groupId, int count = 10, int page = 1)
 {
     try
     {
         var taskInstances = Pr.GetAllGroupTasks(groupId, count, page);
         var workflowItems = taskInstances.ToWorkflowTaskList();
         return(Json(new
         {
             items = workflowItems,
             total = Pr.CountGroupTasks(groupId),
             page,
             count
         }, ViewHelpers.CamelCase));
     }
     catch (Exception e)
     {
         return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(e)));
     }
 }
Example #19
0
        public IHttpActionResult GetTasksByInstanceGuid(Guid guid)
        {
            try
            {
                List <WorkflowTaskInstancePoco> tasks    = Pr.TasksAndGroupByInstanceId(guid);
                WorkflowInstancePoco            instance = Pr.InstanceByGuid(guid);

                return(Json(new
                {
                    items = tasks,
                    currentStep = tasks.Count(x => x.TaskStatus.In(TaskStatus.Approved, TaskStatus.NotRequired)) + 1, // value is for dispplay, so zero-index isn't friendly
                    totalSteps = instance.TotalSteps
                }, ViewHelpers.CamelCase));
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(e)));
            }
        }
 public IHttpActionResult GetAllInstances(int count, int page)
 {
     try
     {
         var instances         = Pr.GetAllInstances().OrderByDescending(x => x.CreatedDate).ToList();
         var workflowInstances = instances.Skip((page - 1) * count).Take(count).ToList().ToWorkflowInstanceList();
         return(Json(new
         {
             items = workflowInstances,
             total = instances.Count,
             page,
             count
         }, ViewHelpers.CamelCase));
     }
     catch (Exception e)
     {
         return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(e)));
     }
 }
Example #21
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)));
            }
        }
Example #22
0
        public IHttpActionResult GetAllInstances(int count, int page)
        {
            try
            {
                List <WorkflowInstance> workflowInstances = _instancesService.Get(page, count, null);

                return(Json(new
                {
                    items = workflowInstances,
                    total = _instancesService.CountPending(),
                    page,
                    count
                }, ViewHelpers.CamelCase));
            }
            catch (Exception e)
            {
                const string error = "Error getting workflow instances";
                Log.Error(error, e);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(e, error)));
            }
        }
Example #23
0
        public IHttpActionResult GetTasksByInstanceGuid(Guid guid)
        {
            try
            {
                List <WorkflowTaskInstancePoco> tasks    = _tasksService.GetTasksWithGroupByInstanceGuid(guid);
                WorkflowInstancePoco            instance = _instancesService.GetByGuid(guid);

                return(Json(new
                {
                    items = tasks,
                    currentStep = tasks.Count(x => x.TaskStatus.In(TaskStatus.Approved, TaskStatus.NotRequired)) + 1, // value is for display, so zero-index isn't friendly
                    totalSteps = instance.TotalSteps
                }, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                string msg = $"Error getting tasks by instance guid {guid}";
                Log.Error(msg, ex);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }
Example #24
0
 public IHttpActionResult GetPendingTasks(int count, int page)
 {
     try
     {
         List <WorkflowTaskInstancePoco> taskInstances = Pr.GetPendingTasks(new List <int> {
             (int)TaskStatus.PendingApproval, (int)TaskStatus.Rejected
         }, count, page);
         List <WorkflowTask> workflowItems = taskInstances.ToWorkflowTaskList();
         return(Json(new
         {
             items = workflowItems,
             total = Pr.CountPendingTasks(),
             page,
             count
         }, ViewHelpers.CamelCase));
     }
     catch (Exception e)
     {
         return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(e)));
     }
 }
Example #25
0
 public IHttpActionResult GetAllTasksForGroup(int groupId, int count = 10, int page = 1)
 {
     try
     {
         List <WorkflowTaskInstancePoco> taskInstances = Pr.GetAllGroupTasks(groupId, count, page);
         List <WorkflowTask>             workflowItems = taskInstances.ToWorkflowTaskList();
         return(Json(new
         {
             items = workflowItems,
             total = Pr.CountGroupTasks(groupId),
             page,
             count
         }, ViewHelpers.CamelCase));
     }
     catch (Exception ex)
     {
         string msg = $"Error getting all tasks for group {groupId}";
         Log.Error(msg, ex);
         return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
     }
 }
Example #26
0
        public IHttpActionResult GetAllInstancesByNodeId(int nodeId, int count, int page)
        {
            try
            {
                List <WorkflowInstance> workflowInstances = _instancesService.GetByNodeId(nodeId, page, count);

                return(Json(new
                {
                    items = workflowInstances,
                    totalPages = (int)Math.Ceiling(_instancesService.CountAll() / count),
                    page,
                    count
                }, ViewHelpers.CamelCase));
            }
            catch (Exception e)
            {
                const string error = "Error getting workflow instances";
                Log.Error(error, e);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(e, error)));
            }
        }
Example #27
0
 public IHttpActionResult GetAllInstances(int count, int page)
 {
     try
     {
         List <WorkflowInstancePoco> instances         = Pr.GetAllInstances().OrderByDescending(x => x.CreatedDate).ToList();
         List <WorkflowInstance>     workflowInstances = instances.Skip((page - 1) * count).Take(count).ToList().ToWorkflowInstanceList();
         return(Json(new
         {
             items = workflowInstances,
             total = instances.Count,
             page,
             count
         }, ViewHelpers.CamelCase));
     }
     catch (Exception e)
     {
         const string error = "Error getting workflow instances";
         Log.Error(error, e);
         return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(e, error)));
     }
 }
Example #28
0
 public IHttpActionResult GetNodeTasks(int id, int count, int page)
 {
     try
     {
         List <WorkflowTaskInstancePoco> taskInstances = Pr.TasksByNode(id);
         List <WorkflowTask>             workflowItems = taskInstances.Skip((page - 1) * count).Take(count).ToList().ToWorkflowTaskList();
         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)));
     }
 }
Example #29
0
        public async Task <IHttpActionResult> GetFlowsForUser(int userId, int type, int count, int page)
        {
            try
            {
                List <WorkflowTaskInstancePoco> taskInstances = type == 0
                    ? _tasksService.GetAllPendingTasks(new List <int> {
                    (int)TaskStatus.PendingApproval
                })
                    : _tasksService.GetTaskSubmissionsForUser(userId, new List <int> {
                    (int)TaskStatus.PendingApproval, (int)TaskStatus.Rejected
                });

                if (type == 0)
                {
                    foreach (WorkflowTaskInstancePoco taskInstance in taskInstances)
                    {
                        taskInstance.UserGroup = await _groupService.GetPopulatedUserGroupAsync(taskInstance.UserGroup.GroupId);
                    }

                    taskInstances = taskInstances.Where(x => x.UserGroup.IsMember(userId)).ToList();
                }

                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 trying to build user workflow tasks list for user {userId}";
                Log.Error(msg, ex);
                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }
Example #30
0
        public IHttpActionResult GetAllTasksForGroup(int groupId, int count = 10, int page = 1)
        {
            try
            {
                List <WorkflowTask> workflowItems = _tasksService.GetAllGroupTasks(groupId, count, page);
                int groupTaskCount = _tasksService.CountGroupTasks(groupId);

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