ItemListHandler.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MediaBrowser.Common.Net.Handlers;
  5. using MediaBrowser.Controller;
  6. using MediaBrowser.Model.DTO;
  7. using MediaBrowser.Model.Entities;
  8. namespace MediaBrowser.Api.HttpHandlers
  9. {
  10. public class ItemListHandler : BaseJsonHandler<IEnumerable<DTOBaseItem>>
  11. {
  12. protected override IEnumerable<DTOBaseItem> GetObjectToSerialize()
  13. {
  14. User user = Kernel.Instance.Users.First(u => u.Id == UserId);
  15. return ItemsToSerialize.Select(i =>
  16. {
  17. return ApiService.GetDTOBaseItem(i, user, includeChildren: false, includePeople: false);
  18. });
  19. }
  20. protected IEnumerable<BaseItem> ItemsToSerialize
  21. {
  22. get
  23. {
  24. Folder parent = ApiService.GetItemById(ItemId) as Folder;
  25. User user = Kernel.Instance.Users.First(u => u.Id == UserId);
  26. if (ListType.Equals("inprogressitems", StringComparison.OrdinalIgnoreCase))
  27. {
  28. return parent.GetInProgressItems(user);
  29. }
  30. else if (ListType.Equals("recentlyaddeditems", StringComparison.OrdinalIgnoreCase))
  31. {
  32. return parent.GetRecentlyAddedItems(user);
  33. }
  34. else if (ListType.Equals("recentlyaddedunplayeditems", StringComparison.OrdinalIgnoreCase))
  35. {
  36. return parent.GetRecentlyAddedUnplayedItems(user);
  37. }
  38. else if (ListType.Equals("itemswithgenre", StringComparison.OrdinalIgnoreCase))
  39. {
  40. return parent.GetItemsWithGenre(QueryString["name"], user);
  41. }
  42. else if (ListType.Equals("itemswithyear", StringComparison.OrdinalIgnoreCase))
  43. {
  44. return parent.GetItemsWithYear(int.Parse(QueryString["year"]), user);
  45. }
  46. else if (ListType.Equals("itemswithstudio", StringComparison.OrdinalIgnoreCase))
  47. {
  48. return parent.GetItemsWithStudio(QueryString["name"], user);
  49. }
  50. else if (ListType.Equals("itemswithperson", StringComparison.OrdinalIgnoreCase))
  51. {
  52. return parent.GetItemsWithPerson(QueryString["name"], null, user);
  53. }
  54. throw new InvalidOperationException();
  55. }
  56. }
  57. protected string ItemId
  58. {
  59. get
  60. {
  61. return QueryString["id"];
  62. }
  63. }
  64. protected Guid UserId
  65. {
  66. get
  67. {
  68. return Guid.Parse(QueryString["userid"]);
  69. }
  70. }
  71. private string ListType
  72. {
  73. get
  74. {
  75. return QueryString["listtype"] ?? string.Empty;
  76. }
  77. }
  78. }
  79. }