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