Guest User

Untitled

a guest
May 26th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. public class BinCountDTO
  2. {
  3. public string BinName { get; set; }
  4. public int ItemCount { get; set; }
  5. }
  6.  
  7.  
  8.  
  9. public class ConsoleDTO
  10. {
  11. public int UnqueuedItemsCount { get; set; }
  12. public int QueuedItemsCount { get; set; }
  13. public BinCountDTO[] ByItemType { get; set; }
  14. public BinCountDTO[] Queues { get; set; }
  15. public BinCountDTO[] Tags { get; set; }
  16. }
  17.  
  18. public class ConsoleMap : QueryMap<ConsoleDTO>
  19. {
  20. public ConsoleMap()
  21. {
  22. // This map requires a single input: The user
  23. RequireParam<User>("current_user");
  24.  
  25. // First get the open, unqueued items that I own
  26. For(d => d.UnqueuedItemsCount)
  27. .Count<WorkflowItem>(i =>
  28. i.Condition != "Closed"
  29. && i.Owner == GetParam("current_user")
  30. && i.Queue == null);
  31.  
  32. // Next get the open, queued items that I own
  33. For(d => d.QueuedItemsCount)
  34. .Count<WorkflowItem>(i =>
  35. i.Condition != "Closed"
  36. && i.Owner == GetParam("current_user")
  37. && i.Queue != null);
  38.  
  39. // Next, get the counts of each workflowitem by type (Case, Solution, etc)
  40. // "GetWorkflowItemTypes()" is just a static method that returns a string[]
  41. // and doesn't actually hit the DB
  42. For(d => d.ByItemType).Each(GetWorkflowItemTypes())
  43. .Project(m =>
  44. {
  45. m.For(b => b.BinName).Use(entityType => entityType.Name);
  46. m.For(b => b.ItemCount)
  47. .Count<WorkflowItem>(i =>
  48. i.Condition != "Closed"
  49. && i.Owner == GetParam("current_user")
  50. && i.Queue == null
  51. });
  52.  
  53. // Next, get the list of queues that I'm a member of from the DB
  54. // Then, for each queue, get the count of the number of open items in that queue
  55. For(d => d.Queues)
  56. .Fetch<Queue>(q => q.Members.Contains(GetParam("current_user")))
  57. .Project(m =>
  58. {
  59. m.For(b => b.BinName).Use(q => q.Name);
  60. m.For(b => b.ItemCount)
  61. .Count<WorkflowItem>(i =>
  62. i.Condition != "Closed"
  63. && i.Queue == m.CurrentObject())
  64. });
  65.  
  66.  
  67. // Next, get the list of my tags and project the list with the counts of items
  68. // in each tag
  69. For(d => d.Tags)
  70. .Fetch<Tag>(t => t.User == GetParam("current_user"))
  71. .Project(m =>
  72. {
  73. m.GroupBy(t => t.Name).MapTo(b => b.BinName);
  74. m.For(b => b.ItemCount).Count();
  75. });
  76.  
  77.  
  78. }
  79. }
Add Comment
Please, Sign In to add comment