ItemListHandler.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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<BaseItemContainer<BaseItem>>>
  11. {
  12. protected override IEnumerable<BaseItemContainer<BaseItem>> GetObjectToSerialize()
  13. {
  14. return ItemsToSerialize.Select(i =>
  15. {
  16. return ApiService.GetSerializationObject(i, false, UserId);
  17. });
  18. }
  19. protected IEnumerable<BaseItem> ItemsToSerialize
  20. {
  21. get
  22. {
  23. Folder parent = ApiService.GetItemById(ItemId) as Folder;
  24. if (ListType.Equals("inprogressitems", StringComparison.OrdinalIgnoreCase))
  25. {
  26. return Kernel.Instance.GetInProgressItems(parent, UserId);
  27. }
  28. else if (ListType.Equals("recentlyaddeditems", StringComparison.OrdinalIgnoreCase))
  29. {
  30. return Kernel.Instance.GetRecentlyAddedItems(parent, UserId);
  31. }
  32. else if (ListType.Equals("recentlyaddedunplayeditems", StringComparison.OrdinalIgnoreCase))
  33. {
  34. return Kernel.Instance.GetRecentlyAddedUnplayedItems(parent, UserId);
  35. }
  36. else if (ListType.Equals("itemswithgenre", StringComparison.OrdinalIgnoreCase))
  37. {
  38. return Kernel.Instance.GetItemsWithGenre(parent, QueryString["name"], UserId);
  39. }
  40. else if (ListType.Equals("itemswithyear", StringComparison.OrdinalIgnoreCase))
  41. {
  42. return Kernel.Instance.GetItemsWithYear(parent, int.Parse(QueryString["year"]), UserId);
  43. }
  44. else if (ListType.Equals("itemswithstudio", StringComparison.OrdinalIgnoreCase))
  45. {
  46. return Kernel.Instance.GetItemsWithStudio(parent, QueryString["name"], UserId);
  47. }
  48. else if (ListType.Equals("itemswithperson", StringComparison.OrdinalIgnoreCase))
  49. {
  50. return Kernel.Instance.GetItemsWithPerson(parent, QueryString["name"], UserId);
  51. }
  52. throw new InvalidOperationException();
  53. }
  54. }
  55. protected string ItemId
  56. {
  57. get
  58. {
  59. return QueryString["id"];
  60. }
  61. }
  62. protected Guid UserId
  63. {
  64. get
  65. {
  66. return Guid.Parse(QueryString["userid"]);
  67. }
  68. }
  69. private string ListType
  70. {
  71. get
  72. {
  73. return QueryString["listtype"] ?? string.Empty;
  74. }
  75. }
  76. }
  77. }