PersonHandler.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using MediaBrowser.Common.Net.Handlers;
  2. using MediaBrowser.Controller;
  3. using MediaBrowser.Model.DTO;
  4. using MediaBrowser.Model.Entities;
  5. using System.Collections.Generic;
  6. using System.Threading.Tasks;
  7. namespace MediaBrowser.Api.HttpHandlers
  8. {
  9. /// <summary>
  10. /// Gets a single Person
  11. /// </summary>
  12. public class PersonHandler : BaseSerializationHandler<IBNItem>
  13. {
  14. protected override Task<IBNItem> GetObjectToSerialize()
  15. {
  16. Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
  17. User user = ApiService.GetUserById(QueryString["userid"], true);
  18. string name = QueryString["name"];
  19. return GetPerson(parent, user, name);
  20. }
  21. /// <summary>
  22. /// Gets a Person
  23. /// </summary>
  24. private async Task<IBNItem> GetPerson(Folder parent, User user, string name)
  25. {
  26. int count = 0;
  27. // Get all the allowed recursive children
  28. IEnumerable<BaseItem> allItems = parent.GetParentalAllowedRecursiveChildren(user);
  29. foreach (var item in allItems)
  30. {
  31. if (item.People != null && item.People.ContainsKey(name))
  32. {
  33. count++;
  34. }
  35. }
  36. // Get the original entity so that we can also supply the PrimaryImagePath
  37. return ApiService.GetIBNItem(await Kernel.Instance.ItemController.GetPerson(name).ConfigureAwait(false), count);
  38. }
  39. }
  40. }