YearHandler.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /// <summary>
  11. /// Gets a single year
  12. /// </summary>
  13. public class YearHandler : BaseJsonHandler<IBNItem<Year>>
  14. {
  15. protected override IBNItem<Year> GetObjectToSerialize()
  16. {
  17. Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
  18. Guid userId = Guid.Parse(QueryString["userid"]);
  19. User user = Kernel.Instance.Users.First(u => u.Id == userId);
  20. string year = QueryString["year"];
  21. return GetYear(parent, user, int.Parse(year));
  22. }
  23. /// <summary>
  24. /// Gets a Year
  25. /// </summary>
  26. private IBNItem<Year> GetYear(Folder parent, User user, int year)
  27. {
  28. int count = 0;
  29. // Get all the allowed recursive children
  30. IEnumerable<BaseItem> allItems = parent.GetParentalAllowedRecursiveChildren(user);
  31. foreach (var item in allItems)
  32. {
  33. if (item.ProductionYear.HasValue && item.ProductionYear.Value == year)
  34. {
  35. count++;
  36. }
  37. }
  38. // Get the original entity so that we can also supply the PrimaryImagePath
  39. return new IBNItem<Year>()
  40. {
  41. Item = Kernel.Instance.ItemController.GetYear(year),
  42. BaseItemCount = count
  43. };
  44. }
  45. }
  46. }