jellyfin/MediaBrowser.Controller/Entities/IItemByName.cs

47 lines
1.2 KiB
C#
Raw Normal View History

using MediaBrowser.Model.Dto;
using System;
using System.Collections.Generic;
2013-12-02 14:46:22 -07:00
using System.Linq;
2013-06-27 12:29:58 -07:00
namespace MediaBrowser.Controller.Entities
{
/// <summary>
/// Marker interface
/// </summary>
public interface IItemByName
{
2013-12-02 14:46:22 -07:00
List<ItemByNameCounts> UserItemCountList { get; set; }
2013-06-27 12:29:58 -07:00
}
2013-09-10 12:30:56 -07:00
2013-11-21 13:48:26 -07:00
public interface IHasDualAccess : IItemByName
{
bool IsAccessedByName { get; }
}
2013-12-02 14:46:22 -07:00
public static class ItemByNameExtensions
2013-09-10 12:30:56 -07:00
{
2013-12-02 14:46:22 -07:00
public static ItemByNameCounts GetItemByNameCounts(this IItemByName item, Guid userId)
2013-09-10 12:30:56 -07:00
{
2013-12-02 14:46:22 -07:00
if (userId == Guid.Empty)
2013-09-10 12:30:56 -07:00
{
2013-12-02 14:46:22 -07:00
throw new ArgumentNullException("userId");
2013-09-10 12:30:56 -07:00
}
2013-12-02 14:46:22 -07:00
return item.UserItemCountList.FirstOrDefault(i => i.UserId == userId);
}
public static void SetItemByNameCounts(this IItemByName item, Guid userId, ItemByNameCounts counts)
{
var current = item.UserItemCountList.FirstOrDefault(i => i.UserId == userId);
2013-09-10 12:30:56 -07:00
2013-12-02 14:46:22 -07:00
if (current != null)
2013-09-10 12:30:56 -07:00
{
2013-12-02 14:46:22 -07:00
item.UserItemCountList.Remove(current);
2013-09-10 12:30:56 -07:00
}
2013-12-02 14:46:22 -07:00
counts.UserId = userId;
item.UserItemCountList.Add(counts);
2013-09-10 12:30:56 -07:00
}
}
2013-06-27 12:29:58 -07:00
}