From 8fc828361e6e6019bc833ffba1d5ef8fc8605ac9 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Fri, 7 Sep 2012 12:17:39 -0400 Subject: Updated authentication --- MediaBrowser.Api/ApiService.cs | 84 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 4 deletions(-) (limited to 'MediaBrowser.Api/ApiService.cs') diff --git a/MediaBrowser.Api/ApiService.cs b/MediaBrowser.Api/ApiService.cs index ca76d5c5c..ab12a350f 100644 --- a/MediaBrowser.Api/ApiService.cs +++ b/MediaBrowser.Api/ApiService.cs @@ -1,10 +1,10 @@ -using System; +using MediaBrowser.Controller; +using MediaBrowser.Model.DTO; +using MediaBrowser.Model.Entities; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using MediaBrowser.Controller; -using MediaBrowser.Model.DTO; -using MediaBrowser.Model.Entities; namespace MediaBrowser.Api { @@ -13,6 +13,9 @@ namespace MediaBrowser.Api /// public static class ApiService { + /// + /// Gets an Item by Id, or the root item if none is supplied + /// public static BaseItem GetItemById(string id) { Guid guid = string.IsNullOrEmpty(id) ? Guid.Empty : new Guid(id); @@ -20,6 +23,52 @@ namespace MediaBrowser.Api return Kernel.Instance.GetItemById(guid); } + /// + /// Gets a User by Id + /// + /// Whether or not to update the user's LastActivityDate + public static User GetUserById(string id, bool logActivity) + { + Guid guid = new Guid(id); + + User user = Kernel.Instance.Users.FirstOrDefault(u => u.Id == guid); + + if (logActivity) + { + LogUserActivity(user); + } + + return user; + } + + /// + /// Gets the default User + /// + /// Whether or not to update the user's LastActivityDate + public static User GetDefaultUser(bool logActivity) + { + User user = Kernel.Instance.GetDefaultUser(); + + if (logActivity) + { + LogUserActivity(user); + } + + return user; + } + + /// + /// Updates LastActivityDate for a given User + /// + public static void LogUserActivity(User user) + { + user.LastActivityDate = DateTime.UtcNow; + Kernel.Instance.SaveUser(user); + } + + /// + /// Converts a BaseItem to a DTOBaseItem + /// public async static Task GetDTOBaseItem(BaseItem item, User user, bool includeChildren = true, bool includePeople = true) @@ -52,6 +101,9 @@ namespace MediaBrowser.Api return dto; } + /// + /// Sets simple property values on a DTOBaseItem + /// private static void AttachBasicFields(DTOBaseItem dto, BaseItem item, User user) { dto.AspectRatio = item.AspectRatio; @@ -168,6 +220,9 @@ namespace MediaBrowser.Api } } + /// + /// Attaches Studio DTO's to a DTOBaseItem + /// private static async Task AttachStudios(DTOBaseItem dto, BaseItem item) { // Attach Studios by transforming them into BaseItemStudio (DTO) @@ -191,6 +246,9 @@ namespace MediaBrowser.Api } } + /// + /// Attaches child DTO's to a DTOBaseItem + /// private static async Task AttachChildren(DTOBaseItem dto, BaseItem item, User user) { var folder = item as Folder; @@ -203,6 +261,9 @@ namespace MediaBrowser.Api } } + /// + /// Attaches trailer DTO's to a DTOBaseItem + /// private static async Task AttachLocalTrailers(DTOBaseItem dto, BaseItem item, User user) { if (item.LocalTrailers != null && item.LocalTrailers.Any()) @@ -211,6 +272,9 @@ namespace MediaBrowser.Api } } + /// + /// Attaches People DTO's to a DTOBaseItem + /// private static async Task AttachPeople(DTOBaseItem dto, BaseItem item) { // Attach People by transforming them into BaseItemPerson (DTO) @@ -238,6 +302,9 @@ namespace MediaBrowser.Api } } + /// + /// If an item does not any backdrops, this can be used to find the first parent that does have one + /// private static Guid? GetParentBackdropItemId(BaseItem item, out int backdropCount) { backdropCount = 0; @@ -258,6 +325,9 @@ namespace MediaBrowser.Api return null; } + /// + /// If an item does not have a logo, this can be used to find the first parent that does have one + /// private static Guid? GetParentLogoItemId(BaseItem item) { var parent = item.Parent; @@ -275,6 +345,9 @@ namespace MediaBrowser.Api return null; } + /// + /// Gets an ImagesByName entity along with the number of items containing it + /// public static IBNItem GetIBNItem(BaseEntity entity, int itemCount) { return new IBNItem() @@ -286,6 +359,9 @@ namespace MediaBrowser.Api }; } + /// + /// Converts a User to a DTOUser + /// public static DTOUser GetDTOUser(User user) { return new DTOUser() -- cgit v1.2.3