GenreHandler.cs 1.7 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 genre
  12. /// </summary>
  13. public class GenreHandler : BaseJsonHandler<IBNItem<Genre>>
  14. {
  15. protected override IBNItem<Genre> 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 name = QueryString["name"];
  21. return GetGenre(parent, user, name);
  22. }
  23. /// <summary>
  24. /// Gets a Genre
  25. /// </summary>
  26. private IBNItem<Genre> GetGenre(Folder parent, User user, string name)
  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.Genres != null && item.Genres.Any(s => s.Equals(name, StringComparison.OrdinalIgnoreCase)))
  34. {
  35. count++;
  36. }
  37. }
  38. // Get the original entity so that we can also supply the PrimaryImagePath
  39. return new IBNItem<Genre>()
  40. {
  41. Item = Kernel.Instance.ItemController.GetGenre(name),
  42. BaseItemCount = count
  43. };
  44. }
  45. }
  46. }