You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Controller/Entities/IItemByName.cs

47 lines
1.2 KiB

using MediaBrowser.Model.Dto;
using System;
using System.Collections.Generic;
11 years ago
using System.Linq;
namespace MediaBrowser.Controller.Entities
{
/// <summary>
/// Marker interface
/// </summary>
public interface IItemByName
{
11 years ago
List<ItemByNameCounts> UserItemCountList { get; set; }
}
public interface IHasDualAccess : IItemByName
{
bool IsAccessedByName { get; }
}
11 years ago
public static class ItemByNameExtensions
{
11 years ago
public static ItemByNameCounts GetItemByNameCounts(this IItemByName item, Guid userId)
{
11 years ago
if (userId == Guid.Empty)
{
11 years ago
throw new ArgumentNullException("userId");
}
11 years ago
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);
11 years ago
if (current != null)
{
11 years ago
item.UserItemCountList.Remove(current);
}
11 years ago
counts.UserId = userId;
item.UserItemCountList.Add(counts);
}
}
}