aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Entities/IItemByName.cs
blob: 1e83c7466ea741b17d1b9c4d09d8a34ce2418517 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using MediaBrowser.Model.Dto;
using System;
using System.Collections.Generic;
using System.Linq;

namespace MediaBrowser.Controller.Entities
{
    /// <summary>
    /// Marker interface
    /// </summary>
    public interface IItemByName
    {
        List<ItemByNameCounts> UserItemCountList { get; set; }
    }

    public interface IHasDualAccess : IItemByName
    {
        bool IsAccessedByName { get; }
    }

    public static class ItemByNameExtensions
    {
        public static ItemByNameCounts GetItemByNameCounts(this IItemByName item, Guid userId)
        {
            if (userId == Guid.Empty)
            {
                throw new ArgumentNullException("userId");
            }

            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);

            if (current != null)
            {
                item.UserItemCountList.Remove(current);
            }

            counts.UserId = userId;
            item.UserItemCountList.Add(counts);
        }
    }
}