YearHandler.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using MediaBrowser.Common.Net.Handlers;
  6. using MediaBrowser.Controller;
  7. using MediaBrowser.Model.DTO;
  8. using MediaBrowser.Model.Entities;
  9. namespace MediaBrowser.Api.HttpHandlers
  10. {
  11. /// <summary>
  12. /// Gets a single year
  13. /// </summary>
  14. public class YearHandler : BaseJsonHandler<IBNItem<Year>>
  15. {
  16. protected override Task<IBNItem<Year>> GetObjectToSerialize()
  17. {
  18. Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
  19. Guid userId = Guid.Parse(QueryString["userid"]);
  20. User user = Kernel.Instance.Users.First(u => u.Id == userId);
  21. string year = QueryString["year"];
  22. return GetYear(parent, user, int.Parse(year));
  23. }
  24. /// <summary>
  25. /// Gets a Year
  26. /// </summary>
  27. private async Task<IBNItem<Year>> GetYear(Folder parent, User user, int year)
  28. {
  29. int count = 0;
  30. // Get all the allowed recursive children
  31. IEnumerable<BaseItem> allItems = parent.GetParentalAllowedRecursiveChildren(user);
  32. foreach (var item in allItems)
  33. {
  34. if (item.ProductionYear.HasValue && item.ProductionYear.Value == year)
  35. {
  36. count++;
  37. }
  38. }
  39. // Get the original entity so that we can also supply the PrimaryImagePath
  40. return new IBNItem<Year>()
  41. {
  42. Item = await Kernel.Instance.ItemController.GetYear(year).ConfigureAwait(false),
  43. BaseItemCount = count
  44. };
  45. }
  46. }
  47. }