aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Entities/UserItemData.cs
blob: 3eacdae5bc551e6cd58822ba9c7dd0e72be07fa5 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Runtime.Serialization;

namespace MediaBrowser.Controller.Entities
{
    public class UserItemData
    {
        private float? _Rating = null;
        /// <summary>
        /// Gets or sets the users 0-10 rating
        /// </summary>
        public float? Rating
        {
            get
            {
                return _Rating;
            }
            set
            {
                if (value.HasValue)
                {
                    if (value.Value < 0 || value.Value > 10)
                    {
                        throw new InvalidOperationException("A 0-10 rating is required for UserItemData.");
                    }
                }

                _Rating = value;
            }
        }

        public long PlaybackPositionTicks { get; set; }

        public int PlayCount { get; set; }

        public bool IsFavorite { get; set; }

        /// <summary>
        /// This is an interpreted property to indicate likes or dislikes
        /// This should never be serialized.
        /// </summary>
        [IgnoreDataMember]
        public bool? Likes
        {
            get
            {
                if (Rating != null)
                {
                    return Rating >= 6.5;
                }

                return null;
            }
            set
            {
                if (value.HasValue)
                {
                    Rating = value.Value ? 10 : 1;
                }
                else
                {
                    Rating = null;
                }
            }
        }
    }
}