public ActionResult MyTasks(string t, string sortCol, string sortDir, int?page, int?pageSize) { SetNoDataMessage(NoDataMessages.NoTasks); var workflows = DB.Workflows.Where(wf => wf.OwnerUserId == CurrentUserId).WhereReviewExists(); var countByKey = new Dictionary <string, int>(workflows.GroupBy(w => w.CurrentWorkflowActivityKey).Select(g => new { CurrentWorkflowActivityKey = g.Key, Count = g.Count() }).ToDictionaryOnConflictKeepLast(z => z.CurrentWorkflowActivityKey, z => z.Count), Comparers.CaseInsensitiveStringComparer); var keyByName = Cacher.FindOrCreateValWithSimpleKey("workflowKeyByActivityNameForAllActiveWorkflows", () => { var d = new Dictionary <string, string>(Comparers.CaseInsensitiveStringComparer); foreach (var wfd in DB.WorkflowDefinitions.Where(z => z.IsActive)) { if (wfd.Description == null || wfd.Description.Activities == null) { continue; } foreach (var a in wfd.Description.Activities) { d[a.ActivityName] = a.WorkflowActivityKey; } } return(d); }, UloHelpers.MediumCacheTimeout); var tabs = new List <WorkflowListTab>(); foreach (var name in CSV.ParseLine(Properties.Settings.Default.MyTasksTabsCsv)) { var tab = new WorkflowListTab { TabName = StringHelpers.TrimOrNull(name) }; if (tab.TabName == null) { continue; } tab.TabKey = keyByName.GetValue(tab.TabName); if (tab.TabKey == null) { continue; } tab.ItemCount = countByKey.GetValue(tab.TabKey); tab.IsCurrent = tab.TabKey == t; tabs.Add(tab); } var items = DB.ListableWorkflows(CurrentUserId, CurrentUserId); if (t != null) { items = items.Where(z => z.CurrentWorkflowActivityKey == t); } sortCol = sortCol ?? nameof(ListableWorkflows_Result.Status); if (sortCol == nameof(ListableWorkflows_Result.Status)) { items = ApplyBrowse( items, sortCol, CSV.ParseLine(Properties.Settings.Default.ReviewStatusOrdering), sortDir, page, pageSize); } else { items = ApplyBrowse( items, sortCol, sortDir, page, pageSize); } PopulateTabsIntoViewBag(tabs); return(View(items)); }
public IActionResult MyTasks(string t, string sortCol, string sortDir, int?page, int?pageSize) { LogInformation("{method}({t}, {sortCol}, {sortDir}, {page}, {pageSize})", nameof(MyTasks), t, sortCol, sortDir, page, pageSize); SetNoDataMessage(ConfigOptions.Value.NoTasks); var workflows = Workflows.Where(wf => wf.OwnerUserId == CurrentUserId); var countByKey = new Dictionary <string, int>(workflows.GroupBy(w => w.CurrentWorkflowActivityKey).Select(g => new { CurrentWorkflowActivityKey = g.Key, Count = g.Count() }).ToDictionaryOnConflictKeepLast(z => z.CurrentWorkflowActivityKey, z => z.Count), Comparers.CaseInsensitiveStringComparer); var keyByName = Cacher.FindOrCreateValue( "workflowKeyByActivityNameForAllActiveWorkflows", () => { var d = new Dictionary <string, string>(Comparers.CaseInsensitiveStringComparer); foreach (var wfd in DB.WorkflowDefinitions.Where(z => z.IsActive)) { if (wfd.Description == null || wfd.Description.Activities == null) { continue; } foreach (var a in wfd.Description.Activities) { d[a.ActivityName] = a.WorkflowActivityKey; } } return(d); }, PortalHelpers.MediumCacheTimeout); var tabs = new List <WorkflowListTab>(); foreach (var name in ConfigOptions.Value.MyTasksTabs) { var tab = new WorkflowListTab { TabName = StringHelpers.TrimOrNull(name) }; if (tab.TabName == null) { continue; } tab.TabKey = keyByName.GetValue(tab.TabName); if (tab.TabKey == null) { continue; } tab.ItemCount = countByKey.GetValue(tab.TabKey); if (t == null && tab.ItemCount > 0) { t = tab.TabKey; LogInformation("Tabkey was null. Setting it to the first tab that has data = {tabTabKey}", t); } tab.IsCurrent = tab.TabKey == t; LogInformation( "TABITERATION: {controller} {name} {tabIsCurrent} {tabTabKey} {t}", this.GetType().Name, name, tab.IsCurrent, tab.TabKey, t); tabs.Add(tab); } var items = DB.ListableWorkflows.Execute(CurrentUserId, CurrentUserId); if (t != null) { items = items.Where(z => z.CurrentWorkflowActivityKey == t); } sortCol = sortCol ?? nameof(ListableWorkflows_Result0.Status); if (sortCol == nameof(ListableWorkflows_Result0.Status)) { items = ApplyBrowse(items, sortCol, sortDir, page, pageSize, orderedValues: ConfigOptions.Value.ReviewStatusOrdering); } else { items = ApplyBrowse(items, sortCol, sortDir, page, pageSize); } PopulateTabsIntoViewBag(tabs); return(View(items)); }