2012-08-18 18:27:34 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2012-08-19 22:38:31 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2012-08-18 18:27:34 +02:00
|
|
|
|
using MediaBrowser.Common.Net.Handlers;
|
2012-08-15 15:20:29 +02:00
|
|
|
|
using MediaBrowser.Controller;
|
2012-08-18 18:27:34 +02:00
|
|
|
|
using MediaBrowser.Model.DTO;
|
2012-08-17 15:16:50 +02:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2012-07-13 05:50:50 +02:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.HttpHandlers
|
|
|
|
|
{
|
2012-08-18 18:27:34 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a single Person
|
|
|
|
|
/// </summary>
|
2012-08-23 14:50:41 +02:00
|
|
|
|
public class PersonHandler : BaseJsonHandler<IBNItem>
|
2012-07-13 05:50:50 +02:00
|
|
|
|
{
|
2012-08-23 14:50:41 +02:00
|
|
|
|
protected override Task<IBNItem> GetObjectToSerialize()
|
2012-07-13 05:50:50 +02:00
|
|
|
|
{
|
2012-08-18 18:27:34 +02:00
|
|
|
|
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
|
|
|
|
Guid userId = Guid.Parse(QueryString["userid"]);
|
|
|
|
|
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
|
|
|
|
|
|
|
|
|
string name = QueryString["name"];
|
|
|
|
|
|
2012-08-22 04:50:59 +02:00
|
|
|
|
return GetPerson(parent, user, name);
|
2012-08-18 18:27:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a Person
|
|
|
|
|
/// </summary>
|
2012-08-23 14:50:41 +02:00
|
|
|
|
private async Task<IBNItem> GetPerson(Folder parent, User user, string name)
|
2012-08-18 18:27:34 +02:00
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
// Get all the allowed recursive children
|
|
|
|
|
IEnumerable<BaseItem> allItems = parent.GetParentalAllowedRecursiveChildren(user);
|
|
|
|
|
|
|
|
|
|
foreach (var item in allItems)
|
|
|
|
|
{
|
|
|
|
|
if (item.People != null && item.People.Any(s => s.Name.Equals(name, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the original entity so that we can also supply the PrimaryImagePath
|
2012-08-23 14:50:41 +02:00
|
|
|
|
return ApiService.GetIBNItem(await Kernel.Instance.ItemController.GetPerson(name).ConfigureAwait(false), count);
|
2012-07-13 05:50:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|