2014-05-08 20:09:53 +00:00
using MediaBrowser.Controller.Dto ;
2013-04-13 18:02:30 +00:00
using MediaBrowser.Controller.Entities ;
2013-02-21 01:33:05 +00:00
using MediaBrowser.Controller.Entities.Movies ;
2013-08-31 01:08:32 +00:00
using MediaBrowser.Controller.Entities.TV ;
2013-02-21 01:33:05 +00:00
using MediaBrowser.Controller.Library ;
2013-05-09 17:38:02 +00:00
using MediaBrowser.Controller.Session ;
2013-02-21 17:50:46 +00:00
using MediaBrowser.Model.Dto ;
2013-10-02 17:23:10 +00:00
using MediaBrowser.Model.Entities ;
2014-06-07 19:46:24 +00:00
using MediaBrowser.Model.Library ;
2013-03-10 05:36:39 +00:00
using MediaBrowser.Model.Querying ;
2014-04-16 02:17:48 +00:00
using MediaBrowser.Model.Session ;
2013-12-07 15:52:38 +00:00
using ServiceStack ;
2013-02-21 01:33:05 +00:00
using System ;
using System.Collections.Generic ;
2013-12-07 15:52:38 +00:00
using System.Globalization ;
2013-02-21 01:33:05 +00:00
using System.Linq ;
2013-04-05 17:10:55 +00:00
using System.Threading ;
2013-02-21 01:33:05 +00:00
using System.Threading.Tasks ;
namespace MediaBrowser.Api.UserLibrary
{
/// <summary>
/// Class GetItem
/// </summary>
[Route("/Users/{UserId}/Items/{Id}", "GET")]
2013-04-05 17:10:55 +00:00
[Api(Description = "Gets an item from a user's library")]
2013-02-21 17:50:46 +00:00
public class GetItem : IReturn < BaseItemDto >
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
2013-03-08 22:41:38 +00:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
2013-02-21 01:33:05 +00:00
public Guid UserId { get ; set ; }
2013-02-24 21:53:54 +00:00
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
2013-02-21 01:33:05 +00:00
public string Id { get ; set ; }
}
2014-06-05 02:32:40 +00:00
[Route("/Users/{UserId}/Views", "GET")]
public class GetUserViews : IReturn < QueryResult < BaseItemDto > >
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
2014-06-07 19:46:24 +00:00
public string UserId { get ; set ; }
[ApiMember(Name = "IncludeExternalContent", Description = "Whether or not to include external views such as channels or live tv", IsRequired = true, DataType = "boolean", ParameterType = "query", Verb = "POST")]
public bool? IncludeExternalContent { get ; set ; }
2014-06-05 02:32:40 +00:00
}
2013-03-09 02:34:54 +00:00
/// <summary>
/// Class GetItem
/// </summary>
[Route("/Users/{UserId}/Items/Root", "GET")]
2013-04-05 17:10:55 +00:00
[Api(Description = "Gets the root folder from a user's library")]
2013-03-09 02:34:54 +00:00
public class GetRootFolder : IReturn < BaseItemDto >
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public Guid UserId { get ; set ; }
}
2013-02-21 01:33:05 +00:00
/// <summary>
/// Class GetIntros
/// </summary>
[Route("/Users/{UserId}/Items/{Id}/Intros", "GET")]
2013-04-05 17:10:55 +00:00
[Api(("Gets intros to play before the main media item plays"))]
2013-10-04 17:04:18 +00:00
public class GetIntros : IReturn < ItemsResult >
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
2013-03-08 22:41:38 +00:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
2013-02-21 01:33:05 +00:00
public Guid UserId { get ; set ; }
2013-02-24 21:53:54 +00:00
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets or sets the item id.
/// </summary>
/// <value>The item id.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
2013-02-21 01:33:05 +00:00
public string Id { get ; set ; }
}
/// <summary>
/// Class MarkFavoriteItem
/// </summary>
[Route("/Users/{UserId}/FavoriteItems/{Id}", "POST")]
2013-03-29 17:25:12 +00:00
[Api(Description = "Marks an item as a favorite")]
2013-08-22 21:33:39 +00:00
public class MarkFavoriteItem : IReturn < UserItemDataDto >
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
2013-03-08 22:41:38 +00:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2013-02-21 01:33:05 +00:00
public Guid UserId { get ; set ; }
2013-02-24 21:53:54 +00:00
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2013-02-21 01:33:05 +00:00
public string Id { get ; set ; }
}
/// <summary>
/// Class UnmarkFavoriteItem
/// </summary>
[Route("/Users/{UserId}/FavoriteItems/{Id}", "DELETE")]
2013-03-29 17:25:12 +00:00
[Api(Description = "Unmarks an item as a favorite")]
2013-08-22 21:33:39 +00:00
public class UnmarkFavoriteItem : IReturn < UserItemDataDto >
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
2013-03-08 22:41:38 +00:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
2013-02-21 01:33:05 +00:00
public Guid UserId { get ; set ; }
2013-02-24 21:53:54 +00:00
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
2013-02-21 01:33:05 +00:00
public string Id { get ; set ; }
}
/// <summary>
/// Class ClearUserItemRating
/// </summary>
[Route("/Users/{UserId}/Items/{Id}/Rating", "DELETE")]
2013-04-05 17:10:55 +00:00
[Api(Description = "Deletes a user's saved personal rating for an item")]
2013-08-22 21:33:39 +00:00
public class DeleteUserItemRating : IReturn < UserItemDataDto >
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
2013-03-08 22:41:38 +00:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
2013-02-21 01:33:05 +00:00
public Guid UserId { get ; set ; }
2013-02-24 21:53:54 +00:00
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
2013-02-21 01:33:05 +00:00
public string Id { get ; set ; }
}
/// <summary>
/// Class UpdateUserItemRating
/// </summary>
[Route("/Users/{UserId}/Items/{Id}/Rating", "POST")]
2013-04-05 17:10:55 +00:00
[Api(Description = "Updates a user's rating for an item")]
2013-08-22 21:33:39 +00:00
public class UpdateUserItemRating : IReturn < UserItemDataDto >
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
2013-03-08 22:41:38 +00:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2013-02-21 01:33:05 +00:00
public Guid UserId { get ; set ; }
2013-02-24 21:53:54 +00:00
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2013-02-21 01:33:05 +00:00
public string Id { get ; set ; }
/// <summary>
2013-04-24 16:37:12 +00:00
/// Gets or sets a value indicating whether this <see cref="UpdateUserItemRating" /> is likes.
2013-02-21 01:33:05 +00:00
/// </summary>
/// <value><c>true</c> if likes; otherwise, <c>false</c>.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Likes", Description = "Whether the user likes the item or not. true/false", IsRequired = true, DataType = "boolean", ParameterType = "query", Verb = "POST")]
2013-02-21 01:33:05 +00:00
public bool Likes { get ; set ; }
}
/// <summary>
/// Class MarkPlayedItem
/// </summary>
[Route("/Users/{UserId}/PlayedItems/{Id}", "POST")]
2013-04-05 17:10:55 +00:00
[Api(Description = "Marks an item as played")]
2013-08-22 21:33:39 +00:00
public class MarkPlayedItem : IReturn < UserItemDataDto >
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
2013-03-08 22:41:38 +00:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2013-02-21 01:33:05 +00:00
public Guid UserId { get ; set ; }
2013-10-16 23:35:11 +00:00
[ApiMember(Name = "DatePlayed", Description = "The date the item was played (if any). Format = yyyyMMddHHmmss", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string DatePlayed { get ; set ; }
2013-09-24 15:08:51 +00:00
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2013-02-21 01:33:05 +00:00
public string Id { get ; set ; }
}
/// <summary>
/// Class MarkUnplayedItem
/// </summary>
[Route("/Users/{UserId}/PlayedItems/{Id}", "DELETE")]
2013-04-05 17:10:55 +00:00
[Api(Description = "Marks an item as unplayed")]
2013-08-22 21:33:39 +00:00
public class MarkUnplayedItem : IReturn < UserItemDataDto >
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
2013-03-08 22:41:38 +00:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
2013-02-21 01:33:05 +00:00
public Guid UserId { get ; set ; }
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
2013-02-21 01:33:05 +00:00
public string Id { get ; set ; }
}
2014-04-16 02:17:48 +00:00
[Route("/Sessions/Playing", "POST")]
[Api(Description = "Reports playback has started within a session")]
public class ReportPlaybackStart : PlaybackStartInfo , IReturnVoid
{
}
[Route("/Sessions/Playing/Progress", "POST")]
[Api(Description = "Reports playback progress within a session")]
public class ReportPlaybackProgress : PlaybackProgressInfo , IReturnVoid
{
}
[Route("/Sessions/Playing/Stopped", "POST")]
[Api(Description = "Reports playback has stopped within a session")]
public class ReportPlaybackStopped : PlaybackStopInfo , IReturnVoid
{
}
2014-06-05 02:32:40 +00:00
2013-04-24 16:37:12 +00:00
/// <summary>
/// Class OnPlaybackStart
/// </summary>
2013-02-25 02:41:51 +00:00
[Route("/Users/{UserId}/PlayingItems/{Id}", "POST")]
2013-04-05 17:10:55 +00:00
[Api(Description = "Reports that a user has begun playing an item")]
2013-02-25 02:41:51 +00:00
public class OnPlaybackStart : IReturnVoid
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
2013-03-08 22:41:38 +00:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2013-02-25 02:41:51 +00:00
public Guid UserId { get ; set ; }
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2013-02-25 02:41:51 +00:00
public string Id { get ; set ; }
2013-09-24 15:08:51 +00:00
2014-03-22 16:16:43 +00:00
[ApiMember(Name = "MediaSourceId", Description = "The id of the MediaSource", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string MediaSourceId { get ; set ; }
2014-03-22 03:35:03 +00:00
2013-09-24 15:08:51 +00:00
/// <summary>
/// Gets or sets a value indicating whether this <see cref="UpdateUserItemRating" /> is likes.
/// </summary>
/// <value><c>true</c> if likes; otherwise, <c>false</c>.</value>
[ApiMember(Name = "CanSeek", Description = "Indicates if the client can seek", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "POST")]
public bool CanSeek { get ; set ; }
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "QueueableMediaTypes", Description = "A list of media types that can be queued from this item, comma delimited. Audio,Video,Book,Game", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST", AllowMultiple = true)]
public string QueueableMediaTypes { get ; set ; }
2014-04-06 17:53:23 +00:00
[ApiMember(Name = "AudioStreamIndex", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "POST")]
public int? AudioStreamIndex { get ; set ; }
[ApiMember(Name = "SubtitleStreamIndex", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "POST")]
public int? SubtitleStreamIndex { get ; set ; }
2013-02-25 02:41:51 +00:00
}
2013-04-24 16:37:12 +00:00
/// <summary>
/// Class OnPlaybackProgress
/// </summary>
2013-02-25 02:41:51 +00:00
[Route("/Users/{UserId}/PlayingItems/{Id}/Progress", "POST")]
2013-04-05 17:10:55 +00:00
[Api(Description = "Reports a user's playback progress")]
2013-02-25 02:41:51 +00:00
public class OnPlaybackProgress : IReturnVoid
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
2013-03-08 22:41:38 +00:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2013-02-25 02:41:51 +00:00
public Guid UserId { get ; set ; }
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
2013-02-25 02:41:51 +00:00
public string Id { get ; set ; }
2014-03-22 16:16:43 +00:00
[ApiMember(Name = "MediaSourceId", Description = "The id of the MediaSource", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string MediaSourceId { get ; set ; }
2014-04-06 17:53:23 +00:00
2013-02-25 02:41:51 +00:00
/// <summary>
/// Gets or sets the position ticks.
/// </summary>
/// <value>The position ticks.</value>
2013-03-09 05:15:51 +00:00
[ApiMember(Name = "PositionTicks", Description = "Optional. The current position, in ticks. 1 tick = 10000 ms", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "POST")]
2013-02-25 02:41:51 +00:00
public long? PositionTicks { get ; set ; }
2013-05-10 12:18:07 +00:00
[ApiMember(Name = "IsPaused", Description = "Indicates if the player is paused.", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "POST")]
public bool IsPaused { get ; set ; }
2013-08-29 21:00:27 +00:00
[ApiMember(Name = "IsMuted", Description = "Indicates if the player is muted.", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "POST")]
public bool IsMuted { get ; set ; }
2014-04-06 17:53:23 +00:00
[ApiMember(Name = "AudioStreamIndex", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "POST")]
public int? AudioStreamIndex { get ; set ; }
[ApiMember(Name = "SubtitleStreamIndex", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "POST")]
public int? SubtitleStreamIndex { get ; set ; }
[ApiMember(Name = "VolumeLevel", Description = "Scale of 0-100", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "POST")]
public int? VolumeLevel { get ; set ; }
2013-02-25 02:41:51 +00:00
}
2013-04-24 16:37:12 +00:00
/// <summary>
/// Class OnPlaybackStopped
/// </summary>
2013-02-25 02:41:51 +00:00
[Route("/Users/{UserId}/PlayingItems/{Id}", "DELETE")]
2013-04-05 17:10:55 +00:00
[Api(Description = "Reports that a user has stopped playing an item")]
2013-02-25 02:41:51 +00:00
public class OnPlaybackStopped : IReturnVoid
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
2013-03-08 22:41:38 +00:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
2013-02-25 02:41:51 +00:00
public Guid UserId { get ; set ; }
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
2013-02-25 02:41:51 +00:00
public string Id { get ; set ; }
2014-03-22 16:16:43 +00:00
[ApiMember(Name = "MediaSourceId", Description = "The id of the MediaSource", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")]
public string MediaSourceId { get ; set ; }
2014-04-06 17:53:23 +00:00
2013-02-25 02:41:51 +00:00
/// <summary>
/// Gets or sets the position ticks.
/// </summary>
/// <value>The position ticks.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "PositionTicks", Description = "Optional. The position, in ticks, where playback stopped. 1 tick = 10000 ms", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "DELETE")]
2013-02-25 02:41:51 +00:00
public long? PositionTicks { get ; set ; }
}
2013-04-24 16:37:12 +00:00
2013-02-24 21:53:54 +00:00
/// <summary>
/// Class GetLocalTrailers
/// </summary>
2013-02-21 01:33:05 +00:00
[Route("/Users/{UserId}/Items/{Id}/LocalTrailers", "GET")]
2013-04-05 17:10:55 +00:00
[Api(Description = "Gets local trailers for an item")]
2013-02-21 17:50:46 +00:00
public class GetLocalTrailers : IReturn < List < BaseItemDto > >
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
2013-03-08 22:41:38 +00:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
2013-02-21 01:33:05 +00:00
public Guid UserId { get ; set ; }
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
2013-02-21 01:33:05 +00:00
public string Id { get ; set ; }
}
2013-02-24 21:53:54 +00:00
/// <summary>
/// Class GetSpecialFeatures
/// </summary>
2013-02-21 01:33:05 +00:00
[Route("/Users/{UserId}/Items/{Id}/SpecialFeatures", "GET")]
2013-08-31 01:08:32 +00:00
[Api(Description = "Gets special features for an item")]
2013-02-21 17:50:46 +00:00
public class GetSpecialFeatures : IReturn < List < BaseItemDto > >
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
2013-03-08 22:41:38 +00:00
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
2013-02-21 01:33:05 +00:00
public Guid UserId { get ; set ; }
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
2013-03-08 23:10:37 +00:00
[ApiMember(Name = "Id", Description = "Movie Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
2013-02-21 01:33:05 +00:00
public string Id { get ; set ; }
}
/// <summary>
/// Class UserLibraryService
/// </summary>
2013-03-16 05:52:33 +00:00
public class UserLibraryService : BaseApiService
2013-02-21 01:33:05 +00:00
{
2013-02-27 20:25:45 +00:00
/// <summary>
/// The _user manager
/// </summary>
private readonly IUserManager _userManager ;
2013-04-24 16:37:12 +00:00
/// <summary>
/// The _user data repository
/// </summary>
2013-10-02 16:08:58 +00:00
private readonly IUserDataManager _userDataRepository ;
2013-04-24 16:37:12 +00:00
/// <summary>
/// The _library manager
/// </summary>
2013-02-28 19:32:41 +00:00
private readonly ILibraryManager _libraryManager ;
2013-04-24 16:37:12 +00:00
2013-05-09 17:38:02 +00:00
private readonly ISessionManager _sessionManager ;
2013-09-04 17:02:19 +00:00
private readonly IDtoService _dtoService ;
2013-05-09 17:38:02 +00:00
2014-06-07 19:46:24 +00:00
private readonly IUserViewManager _userViewManager ;
2013-02-24 21:53:54 +00:00
/// <summary>
/// Initializes a new instance of the <see cref="UserLibraryService" /> class.
/// </summary>
2013-04-24 16:37:12 +00:00
/// <param name="userManager">The user manager.</param>
/// <param name="libraryManager">The library manager.</param>
/// <param name="userDataRepository">The user data repository.</param>
2013-09-24 15:08:51 +00:00
/// <param name="sessionManager">The session manager.</param>
/// <param name="dtoService">The dto service.</param>
2013-02-24 21:53:54 +00:00
/// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
2014-06-07 19:46:24 +00:00
public UserLibraryService ( IUserManager userManager , ILibraryManager libraryManager , IUserDataManager userDataRepository , ISessionManager sessionManager , IDtoService dtoService , IUserViewManager userViewManager )
2013-02-24 21:53:54 +00:00
{
2013-02-27 20:25:45 +00:00
_userManager = userManager ;
2013-02-28 19:32:41 +00:00
_libraryManager = libraryManager ;
2013-04-13 18:02:30 +00:00
_userDataRepository = userDataRepository ;
2013-05-09 17:38:02 +00:00
_sessionManager = sessionManager ;
2013-09-04 17:02:19 +00:00
_dtoService = dtoService ;
2014-06-07 19:46:24 +00:00
_userViewManager = userViewManager ;
2013-02-24 21:53:54 +00:00
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
2013-02-21 01:33:05 +00:00
public object Get ( GetSpecialFeatures request )
2013-08-22 21:33:39 +00:00
{
2013-09-17 02:44:06 +00:00
var result = GetAsync ( request ) ;
2013-08-22 21:33:39 +00:00
2014-02-04 04:04:19 +00:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-08-22 21:33:39 +00:00
}
2014-06-05 02:32:40 +00:00
public object Get ( GetUserViews request )
{
2014-06-07 19:46:24 +00:00
var user = _userManager . GetUserById ( new Guid ( request . UserId ) ) ;
2014-06-05 02:32:40 +00:00
// Get everything
var fields = Enum . GetNames ( typeof ( ItemFields ) ) . Select ( i = > ( ItemFields ) Enum . Parse ( typeof ( ItemFields ) , i , true ) ) . ToList ( ) ;
2014-06-07 19:46:24 +00:00
var query = new UserViewQuery
{
UserId = request . UserId
} ;
if ( request . IncludeExternalContent . HasValue )
{
query . IncludeExternalContent = request . IncludeExternalContent . Value ;
}
var folders = _userViewManager . GetUserViews ( query , CancellationToken . None ) . Result ;
2014-06-05 02:32:40 +00:00
var dtos = folders . OrderBy ( i = > i . SortName )
. Select ( i = > _dtoService . GetBaseItemDto ( i , fields , user ) )
. ToArray ( ) ;
var result = new QueryResult < BaseItemDto >
{
Items = dtos ,
TotalRecordCount = dtos . Length
} ;
return ToOptimizedResult ( result ) ;
}
2013-09-20 00:53:18 +00:00
private List < BaseItemDto > GetAsync ( GetSpecialFeatures request )
2013-02-21 01:33:05 +00:00
{
2013-02-27 20:25:45 +00:00
var user = _userManager . GetUserById ( request . UserId ) ;
2013-02-21 01:33:05 +00:00
2014-06-05 02:32:40 +00:00
var item = string . IsNullOrEmpty ( request . Id ) ?
user . RootFolder :
2014-04-25 20:15:50 +00:00
_libraryManager . GetItemById ( request . Id ) ;
2013-02-24 21:53:54 +00:00
2013-02-21 01:33:05 +00:00
// Get everything
var fields = Enum . GetNames ( typeof ( ItemFields ) ) . Select ( i = > ( ItemFields ) Enum . Parse ( typeof ( ItemFields ) , i , true ) ) . ToList ( ) ;
2013-08-31 01:08:32 +00:00
var movie = item as Movie ;
2013-02-21 01:33:05 +00:00
2013-08-31 01:08:32 +00:00
// Get them from the db
if ( movie ! = null )
{
// Avoid implicitly captured closure
var movie1 = movie ;
2013-09-17 02:44:06 +00:00
var dtos = movie . SpecialFeatureIds
2013-09-25 22:35:23 +00:00
. Select ( _libraryManager . GetItemById )
2013-08-31 01:08:32 +00:00
. OrderBy ( i = > i . SortName )
2013-09-04 17:02:19 +00:00
. Select ( i = > _dtoService . GetBaseItemDto ( i , fields , user , movie1 ) ) ;
2013-08-31 01:08:32 +00:00
2013-09-20 00:53:18 +00:00
return dtos . ToList ( ) ;
2013-08-31 01:08:32 +00:00
}
var series = item as Series ;
// Get them from the child tree
if ( series ! = null )
{
2013-09-17 02:44:06 +00:00
var dtos = series
2014-07-01 21:13:32 +00:00
. GetRecursiveChildren ( )
. Where ( i = > i is Episode & & i . ParentIndexNumber . HasValue & & i . ParentIndexNumber . Value = = 0 )
2013-08-31 14:55:10 +00:00
. OrderBy ( i = >
{
if ( i . PremiereDate . HasValue )
{
return i . PremiereDate . Value ;
}
if ( i . ProductionYear . HasValue )
{
return new DateTime ( i . ProductionYear . Value , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
}
return DateTime . MinValue ;
} )
. ThenBy ( i = > i . SortName )
2013-09-04 17:02:19 +00:00
. Select ( i = > _dtoService . GetBaseItemDto ( i , fields , user ) ) ;
2013-08-31 01:08:32 +00:00
2013-09-20 00:53:18 +00:00
return dtos . ToList ( ) ;
2013-08-31 01:08:32 +00:00
}
2014-06-09 19:16:14 +00:00
return new List < BaseItemDto > ( ) ;
2013-02-21 01:33:05 +00:00
}
2013-02-24 21:53:54 +00:00
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
2013-02-21 01:33:05 +00:00
public object Get ( GetLocalTrailers request )
2013-08-22 21:33:39 +00:00
{
2013-09-17 02:44:06 +00:00
var result = GetAsync ( request ) ;
2013-08-22 21:33:39 +00:00
2014-02-04 04:04:19 +00:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-08-22 21:33:39 +00:00
}
2013-09-20 00:53:18 +00:00
private List < BaseItemDto > GetAsync ( GetLocalTrailers request )
2013-02-21 01:33:05 +00:00
{
2013-02-27 20:25:45 +00:00
var user = _userManager . GetUserById ( request . UserId ) ;
2013-02-21 01:33:05 +00:00
2014-04-25 20:15:50 +00:00
var item = string . IsNullOrEmpty ( request . Id ) ? user . RootFolder : _libraryManager . GetItemById ( request . Id ) ;
2013-02-24 21:53:54 +00:00
2013-02-21 01:33:05 +00:00
// Get everything
var fields = Enum . GetNames ( typeof ( ItemFields ) ) . Select ( i = > ( ItemFields ) Enum . Parse ( typeof ( ItemFields ) , i , true ) ) . ToList ( ) ;
2013-12-02 16:46:25 +00:00
var trailerIds = new List < Guid > ( ) ;
var hasTrailers = item as IHasTrailers ;
if ( hasTrailers ! = null )
{
trailerIds = hasTrailers . LocalTrailerIds ;
}
var dtos = trailerIds
2013-09-25 22:35:23 +00:00
. Select ( _libraryManager . GetItemById )
2013-07-30 14:51:28 +00:00
. OrderBy ( i = > i . SortName )
2013-09-04 17:02:19 +00:00
. Select ( i = > _dtoService . GetBaseItemDto ( i , fields , user , item ) ) ;
2013-02-21 01:33:05 +00:00
2013-09-20 00:53:18 +00:00
return dtos . ToList ( ) ;
2013-02-21 01:33:05 +00:00
}
2013-02-24 21:53:54 +00:00
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get ( GetItem request )
{
2013-02-27 20:25:45 +00:00
var user = _userManager . GetUserById ( request . UserId ) ;
2013-02-21 01:33:05 +00:00
2014-04-25 20:15:50 +00:00
var item = string . IsNullOrEmpty ( request . Id ) ? user . RootFolder : _libraryManager . GetItemById ( request . Id ) ;
2013-02-24 21:53:54 +00:00
2013-02-21 01:33:05 +00:00
// Get everything
var fields = Enum . GetNames ( typeof ( ItemFields ) ) . Select ( i = > ( ItemFields ) Enum . Parse ( typeof ( ItemFields ) , i , true ) ) . ToList ( ) ;
2013-09-17 02:44:06 +00:00
var result = _dtoService . GetBaseItemDto ( item , fields , user ) ;
2013-02-21 01:33:05 +00:00
2014-02-04 04:04:19 +00:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-02-21 01:33:05 +00:00
}
2013-04-24 16:37:12 +00:00
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
2013-03-09 02:34:54 +00:00
public object Get ( GetRootFolder request )
{
var user = _userManager . GetUserById ( request . UserId ) ;
var item = user . RootFolder ;
// Get everything
var fields = Enum . GetNames ( typeof ( ItemFields ) ) . Select ( i = > ( ItemFields ) Enum . Parse ( typeof ( ItemFields ) , i , true ) ) . ToList ( ) ;
2013-09-17 02:44:06 +00:00
var result = _dtoService . GetBaseItemDto ( item , fields , user ) ;
2013-03-09 02:34:54 +00:00
2014-02-04 04:04:19 +00:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-03-09 02:34:54 +00:00
}
2013-04-24 16:37:12 +00:00
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get ( GetIntros request )
{
2013-02-27 20:25:45 +00:00
var user = _userManager . GetUserById ( request . UserId ) ;
2013-02-21 01:33:05 +00:00
2014-04-25 20:15:50 +00:00
var item = string . IsNullOrEmpty ( request . Id ) ? user . RootFolder : _libraryManager . GetItemById ( request . Id ) ;
2013-02-21 01:33:05 +00:00
2013-10-04 17:04:18 +00:00
var items = _libraryManager . GetIntros ( item , user ) ;
// Get everything
var fields = Enum . GetNames ( typeof ( ItemFields ) )
. Select ( i = > ( ItemFields ) Enum . Parse ( typeof ( ItemFields ) , i , true ) )
. ToList ( ) ;
var dtos = items . Select ( i = > _dtoService . GetBaseItemDto ( i , fields , user ) )
. ToArray ( ) ;
var result = new ItemsResult
{
Items = dtos ,
TotalRecordCount = dtos . Length
} ;
2013-02-21 01:33:05 +00:00
2014-02-04 04:04:19 +00:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-02-21 01:33:05 +00:00
}
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
2013-08-22 21:56:19 +00:00
public object Post ( MarkFavoriteItem request )
2013-02-21 01:33:05 +00:00
{
2013-08-23 01:36:34 +00:00
var dto = MarkFavorite ( request . UserId , request . Id , true ) . Result ;
2013-08-22 21:56:19 +00:00
return ToOptimizedResult ( dto ) ;
2013-02-21 01:33:05 +00:00
}
/// <summary>
/// Deletes the specified request.
/// </summary>
/// <param name="request">The request.</param>
2013-08-22 21:56:19 +00:00
public object Delete ( UnmarkFavoriteItem request )
2013-02-21 01:33:05 +00:00
{
2013-08-23 01:36:34 +00:00
var dto = MarkFavorite ( request . UserId , request . Id , false ) . Result ;
2013-02-21 01:33:05 +00:00
2013-08-23 01:36:34 +00:00
return ToOptimizedResult ( dto ) ;
}
2013-10-04 17:04:18 +00:00
/// <summary>
/// Marks the favorite.
/// </summary>
/// <param name="userId">The user id.</param>
/// <param name="itemId">The item id.</param>
/// <param name="isFavorite">if set to <c>true</c> [is favorite].</param>
/// <returns>Task{UserItemDataDto}.</returns>
2013-08-23 01:36:34 +00:00
private async Task < UserItemDataDto > MarkFavorite ( Guid userId , string itemId , bool isFavorite )
{
var user = _userManager . GetUserById ( userId ) ;
2014-04-25 20:15:50 +00:00
var item = string . IsNullOrEmpty ( itemId ) ? user . RootFolder : _libraryManager . GetItemById ( itemId ) ;
2013-02-21 01:33:05 +00:00
2013-04-13 18:02:30 +00:00
var key = item . GetUserDataKey ( ) ;
2013-04-24 16:37:12 +00:00
2013-02-21 01:33:05 +00:00
// Get the user data for this item
2013-06-17 20:35:43 +00:00
var data = _userDataRepository . GetUserData ( user . Id , key ) ;
2013-02-21 01:33:05 +00:00
// Set favorite status
2013-08-23 01:36:34 +00:00
data . IsFavorite = isFavorite ;
2013-02-21 01:33:05 +00:00
2013-10-23 16:03:12 +00:00
await _userDataRepository . SaveUserData ( user . Id , item , data , UserDataSaveReason . UpdateUserRating , CancellationToken . None ) . ConfigureAwait ( false ) ;
2013-08-22 21:56:19 +00:00
data = _userDataRepository . GetUserData ( user . Id , key ) ;
2013-09-04 17:02:19 +00:00
return _dtoService . GetUserItemDataDto ( data ) ;
2013-02-21 01:33:05 +00:00
}
/// <summary>
/// Deletes the specified request.
/// </summary>
/// <param name="request">The request.</param>
2013-08-22 21:56:19 +00:00
public object Delete ( DeleteUserItemRating request )
2013-02-21 01:33:05 +00:00
{
2013-08-23 01:36:34 +00:00
var dto = UpdateUserItemRating ( request . UserId , request . Id , null ) . Result ;
2013-08-22 21:56:19 +00:00
return ToOptimizedResult ( dto ) ;
2013-02-21 01:33:05 +00:00
}
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
2013-08-22 21:56:19 +00:00
public object Post ( UpdateUserItemRating request )
2013-02-21 01:33:05 +00:00
{
2013-08-23 01:36:34 +00:00
var dto = UpdateUserItemRating ( request . UserId , request . Id , request . Likes ) . Result ;
2013-02-21 01:33:05 +00:00
2013-08-23 01:36:34 +00:00
return ToOptimizedResult ( dto ) ;
}
2013-10-04 17:04:18 +00:00
/// <summary>
/// Updates the user item rating.
/// </summary>
/// <param name="userId">The user id.</param>
/// <param name="itemId">The item id.</param>
/// <param name="likes">if set to <c>true</c> [likes].</param>
/// <returns>Task{UserItemDataDto}.</returns>
2013-08-23 01:36:34 +00:00
private async Task < UserItemDataDto > UpdateUserItemRating ( Guid userId , string itemId , bool? likes )
{
var user = _userManager . GetUserById ( userId ) ;
2014-04-25 20:15:50 +00:00
var item = string . IsNullOrEmpty ( itemId ) ? user . RootFolder : _libraryManager . GetItemById ( itemId ) ;
2013-02-21 01:33:05 +00:00
2013-04-13 18:02:30 +00:00
var key = item . GetUserDataKey ( ) ;
2013-04-24 16:37:12 +00:00
2013-02-21 01:33:05 +00:00
// Get the user data for this item
2013-06-17 20:35:43 +00:00
var data = _userDataRepository . GetUserData ( user . Id , key ) ;
2013-02-21 01:33:05 +00:00
2013-08-23 01:36:34 +00:00
data . Likes = likes ;
2013-02-21 01:33:05 +00:00
2013-10-23 16:03:12 +00:00
await _userDataRepository . SaveUserData ( user . Id , item , data , UserDataSaveReason . UpdateUserRating , CancellationToken . None ) . ConfigureAwait ( false ) ;
2013-08-22 21:56:19 +00:00
data = _userDataRepository . GetUserData ( user . Id , key ) ;
2013-09-04 17:02:19 +00:00
return _dtoService . GetUserItemDataDto ( data ) ;
2013-02-21 01:33:05 +00:00
}
2013-08-31 01:08:32 +00:00
2013-02-21 01:33:05 +00:00
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
2013-08-22 21:56:19 +00:00
public object Post ( MarkPlayedItem request )
2014-03-10 12:51:36 +00:00
{
var result = MarkPlayed ( request ) . Result ;
return ToOptimizedResult ( result ) ;
}
private async Task < UserItemDataDto > MarkPlayed ( MarkPlayedItem request )
2013-02-21 01:33:05 +00:00
{
2013-02-27 20:25:45 +00:00
var user = _userManager . GetUserById ( request . UserId ) ;
2013-02-21 01:33:05 +00:00
2013-10-16 23:35:11 +00:00
DateTime ? datePlayed = null ;
2014-03-10 12:51:36 +00:00
2013-10-16 23:35:11 +00:00
if ( ! string . IsNullOrEmpty ( request . DatePlayed ) )
{
datePlayed = DateTime . ParseExact ( request . DatePlayed , "yyyyMMddHHmmss" , CultureInfo . InvariantCulture , DateTimeStyles . AssumeUniversal ) ;
}
2014-07-02 04:57:18 +00:00
var session = GetSession ( ) ;
2014-03-10 12:51:36 +00:00
var dto = await UpdatePlayedStatus ( user , request . Id , true , datePlayed ) . ConfigureAwait ( false ) ;
2013-02-21 01:33:05 +00:00
2014-03-10 12:51:36 +00:00
foreach ( var additionalUserInfo in session . AdditionalUsers )
{
var additionalUser = _userManager . GetUserById ( new Guid ( additionalUserInfo . UserId ) ) ;
await UpdatePlayedStatus ( additionalUser , request . Id , true , datePlayed ) . ConfigureAwait ( false ) ;
}
return dto ;
2013-02-21 01:33:05 +00:00
}
2013-02-25 02:41:51 +00:00
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
public void Post ( OnPlaybackStart request )
{
2013-09-24 15:08:51 +00:00
var queueableMediaTypes = ( request . QueueableMediaTypes ? ? string . Empty ) ;
2014-04-16 02:17:48 +00:00
Post ( new ReportPlaybackStart
2013-09-24 15:08:51 +00:00
{
CanSeek = request . CanSeek ,
2014-04-16 02:17:48 +00:00
ItemId = request . Id ,
2014-03-22 03:35:03 +00:00
QueueableMediaTypes = queueableMediaTypes . Split ( ',' ) . ToList ( ) ,
2014-04-06 17:53:23 +00:00
MediaSourceId = request . MediaSourceId ,
AudioStreamIndex = request . AudioStreamIndex ,
SubtitleStreamIndex = request . SubtitleStreamIndex
2014-04-16 02:17:48 +00:00
} ) ;
}
2013-09-24 15:08:51 +00:00
2014-04-16 02:17:48 +00:00
public void Post ( ReportPlaybackStart request )
{
2014-07-02 04:57:18 +00:00
request . SessionId = GetSession ( ) . Id ;
2014-04-16 02:17:48 +00:00
var task = _sessionManager . OnPlaybackStart ( request ) ;
Task . WaitAll ( task ) ;
2013-02-25 02:41:51 +00:00
}
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
public void Post ( OnPlaybackProgress request )
{
2014-04-16 02:17:48 +00:00
Post ( new ReportPlaybackProgress
2013-09-30 15:05:07 +00:00
{
2014-04-16 02:17:48 +00:00
ItemId = request . Id ,
2013-09-30 15:05:07 +00:00
PositionTicks = request . PositionTicks ,
IsMuted = request . IsMuted ,
IsPaused = request . IsPaused ,
2014-04-06 17:53:23 +00:00
MediaSourceId = request . MediaSourceId ,
AudioStreamIndex = request . AudioStreamIndex ,
SubtitleStreamIndex = request . SubtitleStreamIndex ,
VolumeLevel = request . VolumeLevel
2014-04-16 02:17:48 +00:00
} ) ;
}
public void Post ( ReportPlaybackProgress request )
{
2014-07-02 04:57:18 +00:00
request . SessionId = GetSession ( ) . Id ;
2013-09-30 15:05:07 +00:00
2014-04-16 02:17:48 +00:00
var task = _sessionManager . OnPlaybackProgress ( request ) ;
2013-03-16 05:52:33 +00:00
2013-07-09 16:11:16 +00:00
Task . WaitAll ( task ) ;
2013-02-25 02:41:51 +00:00
}
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
2013-03-18 03:10:21 +00:00
public void Delete ( OnPlaybackStopped request )
2013-02-25 02:41:51 +00:00
{
2014-04-16 02:17:48 +00:00
Post ( new ReportPlaybackStopped
2013-09-30 15:05:07 +00:00
{
2014-04-16 02:17:48 +00:00
ItemId = request . Id ,
2013-09-30 15:05:07 +00:00
PositionTicks = request . PositionTicks ,
2014-03-22 16:16:43 +00:00
MediaSourceId = request . MediaSourceId
2014-04-16 02:17:48 +00:00
} ) ;
}
public void Post ( ReportPlaybackStopped request )
{
2014-07-02 04:57:18 +00:00
request . SessionId = GetSession ( ) . Id ;
2013-09-30 15:05:07 +00:00
2014-04-16 02:17:48 +00:00
var task = _sessionManager . OnPlaybackStopped ( request ) ;
2013-03-16 05:52:33 +00:00
2013-07-09 16:11:16 +00:00
Task . WaitAll ( task ) ;
2013-02-25 02:41:51 +00:00
}
2013-02-21 01:33:05 +00:00
/// <summary>
/// Deletes the specified request.
/// </summary>
/// <param name="request">The request.</param>
2013-08-22 21:56:19 +00:00
public object Delete ( MarkUnplayedItem request )
2014-03-10 12:51:36 +00:00
{
var task = MarkUnplayed ( request ) ;
return ToOptimizedResult ( task . Result ) ;
}
private async Task < UserItemDataDto > MarkUnplayed ( MarkUnplayedItem request )
2013-02-21 01:33:05 +00:00
{
2013-02-27 20:25:45 +00:00
var user = _userManager . GetUserById ( request . UserId ) ;
2013-02-21 01:33:05 +00:00
2014-07-02 04:57:18 +00:00
var session = GetSession ( ) ;
2014-03-10 12:51:36 +00:00
var dto = await UpdatePlayedStatus ( user , request . Id , false , null ) . ConfigureAwait ( false ) ;
2013-02-21 01:33:05 +00:00
2014-03-10 12:51:36 +00:00
foreach ( var additionalUserInfo in session . AdditionalUsers )
{
var additionalUser = _userManager . GetUserById ( new Guid ( additionalUserInfo . UserId ) ) ;
await UpdatePlayedStatus ( additionalUser , request . Id , false , null ) . ConfigureAwait ( false ) ;
}
return dto ;
2013-02-21 01:33:05 +00:00
}
/// <summary>
/// Updates the played status.
/// </summary>
/// <param name="user">The user.</param>
/// <param name="itemId">The item id.</param>
/// <param name="wasPlayed">if set to <c>true</c> [was played].</param>
2013-09-21 19:24:50 +00:00
/// <param name="datePlayed">The date played.</param>
2013-02-21 01:33:05 +00:00
/// <returns>Task.</returns>
2013-09-21 19:24:50 +00:00
private async Task < UserItemDataDto > UpdatePlayedStatus ( User user , string itemId , bool wasPlayed , DateTime ? datePlayed )
2013-02-21 01:33:05 +00:00
{
2014-04-25 20:15:50 +00:00
var item = _libraryManager . GetItemById ( itemId ) ;
2013-02-21 01:33:05 +00:00
2013-09-21 19:24:50 +00:00
if ( wasPlayed )
{
await item . MarkPlayed ( user , datePlayed , _userDataRepository ) . ConfigureAwait ( false ) ;
}
else
{
await item . MarkUnplayed ( user , _userDataRepository ) . ConfigureAwait ( false ) ;
}
2013-08-22 21:56:19 +00:00
2013-09-04 17:02:19 +00:00
return _dtoService . GetUserItemDataDto ( _userDataRepository . GetUserData ( user . Id , item . GetUserDataKey ( ) ) ) ;
2013-02-21 01:33:05 +00:00
}
}
}