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 21:46:22 +00:00
using System.Linq;
2013-06-27 19:29:58 +00:00
namespace MediaBrowser.Controller.Entities
{
/// <summary>
/// Marker interface
/// </summary>
public interface IItemByName
{
2013-12-02 21:46:22 +00:00
List<ItemByNameCounts> UserItemCountList { get; set; }
2013-06-27 19:29:58 +00:00
}
2013-09-10 19:30:56 +00:00
2013-11-21 20:48:26 +00:00
public interface IHasDualAccess : IItemByName
{
bool IsAccessedByName { get; }
}
2013-12-02 21:46:22 +00:00
public static class ItemByNameExtensions
2013-09-10 19:30:56 +00:00
{
2013-12-02 21:46:22 +00:00
public static ItemByNameCounts GetItemByNameCounts(this IItemByName item, Guid userId)
2013-09-10 19:30:56 +00:00
{
2013-12-02 21:46:22 +00:00
if (userId == Guid.Empty)
2013-09-10 19:30:56 +00:00
{
2013-12-02 21:46:22 +00:00
throw new ArgumentNullException("userId");
2013-09-10 19:30:56 +00:00
}
2013-12-02 21:46:22 +00: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 19:30:56 +00:00
2013-12-02 21:46:22 +00:00
if (current != null)
2013-09-10 19:30:56 +00:00
{
2013-12-02 21:46:22 +00:00
item.UserItemCountList.Remove(current);
2013-09-10 19:30:56 +00:00
}
2013-12-02 21:46:22 +00:00
counts.UserId = userId;
item.UserItemCountList.Add(counts);
2013-09-10 19:30:56 +00:00
}
}
2013-06-27 19:29:58 +00:00
}