IItemByName.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using MediaBrowser.Model.Dto;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace MediaBrowser.Controller.Entities
  6. {
  7. /// <summary>
  8. /// Marker interface
  9. /// </summary>
  10. public interface IItemByName
  11. {
  12. List<ItemByNameCounts> UserItemCountList { get; set; }
  13. }
  14. public interface IHasDualAccess : IItemByName
  15. {
  16. bool IsAccessedByName { get; }
  17. }
  18. public static class ItemByNameExtensions
  19. {
  20. public static ItemByNameCounts GetItemByNameCounts(this IItemByName item, Guid userId)
  21. {
  22. if (userId == Guid.Empty)
  23. {
  24. throw new ArgumentNullException("userId");
  25. }
  26. return item.UserItemCountList.FirstOrDefault(i => i.UserId == userId);
  27. }
  28. public static void SetItemByNameCounts(this IItemByName item, Guid userId, ItemByNameCounts counts)
  29. {
  30. var current = item.UserItemCountList.FirstOrDefault(i => i.UserId == userId);
  31. if (current != null)
  32. {
  33. item.UserItemCountList.Remove(current);
  34. }
  35. counts.UserId = userId;
  36. item.UserItemCountList.Add(counts);
  37. }
  38. }
  39. }