/// <summary> /// Remove slideshow /// </summary> /// <param name="id"></param> public static void RemoveSlideShow(int id) { try { using (var db = new MediaPlayerContext()) { SlideShowMapper slideShowMapper = db.SlideShowMapper.Single(x => x.Id == id); db.SlideShowMapper.Remove(slideShowMapper); db.SaveChanges(); } } catch { } }
/// <summary> /// Remove entry /// </summary> /// <param name="id"></param> public static void RemoveMediaData(int id) { try { using (var db = new MediaPlayerContext()) { MediaDataMapper mediaDataMapper = db.MediaDataMapper.Single(x => x.Id == id); db.MediaDataMapper.Remove(mediaDataMapper); db.SaveChanges(); } } catch { } }
/// <summary> /// Update last used time /// </summary> /// <param name="id"></param> public static void UpdateLastUsed(int id) { try { using (var db = new MediaPlayerContext()) { AlbumMapper albumMapper = db.AlbumMapper.Single(x => x.Id == id); albumMapper.LastUsed = DateTime.Now; db.SaveChanges(); } } catch { } }
/// <summary> /// Remove album from table /// </summary> /// <param name="id"></param> public static void RemoveAlbum(int id) { try { using (var db = new MediaPlayerContext()) { AlbumMapper albumMapper = db.AlbumMapper.Single(x => x.Id == id); db.AlbumMapper.Remove(albumMapper); db.SaveChanges(); } } catch { } }
/// <summary> /// Retrive slideshow data /// </summary> /// <param name="id"></param> /// <returns></returns> public static SlideShowMapper GetSlideShow(int id) { SlideShowMapper slideShowMapper; try { using (var db = new MediaPlayerContext()) { slideShowMapper = db.SlideShowMapper.Single(x => x.Id == id); } return(slideShowMapper); } catch { return(null); } }
/// <summary> /// Update name of album /// </summary> /// <param name="id"></param> /// <param name="name"></param> public static void UpdateName(int id, string name) { try { using (var db = new MediaPlayerContext()) { // Get data and update field AlbumMapper albumMapper = db.AlbumMapper.Single(x => x.Id == id); albumMapper.Name = name; albumMapper.LastUsed = DateTime.Now; db.SaveChanges(); } } catch { } }
/// <summary> /// Return last used time of album /// Allow sorting albums by last used /// </summary> /// <param name="id"></param> /// <returns></returns> public static DateTime GetLastUsedTime(int id) { DateTime lastUsed; try { using (var db = new MediaPlayerContext()) { AlbumMapper albumMapper = db.AlbumMapper.Single(x => x.Id == id); lastUsed = albumMapper.LastUsed; } } catch { } return(DateTime.MinValue); }
/// <summary> /// Retrive album data /// </summary> /// <param name="id"></param> /// <returns></returns> public static AlbumMapper GetAlbum(int id) { AlbumMapper albumMapper; try { using (var db = new MediaPlayerContext()) { albumMapper = db.AlbumMapper.Single(x => x.Id == id); } return(albumMapper); } catch { return(null); } }
/// <summary> /// Retrive data /// </summary> /// <param name="id"></param> /// <returns></returns> public static MediaDataMapper GetMediaData(int id) { MediaDataMapper mediaDataMapper; try { using (var db = new MediaPlayerContext()) { mediaDataMapper = db.MediaDataMapper.Single(x => x.Id == id); } return(mediaDataMapper); } catch { return(null); } }
/// <summary> /// Remove slideshow from album /// </summary> /// <param name="id"></param> /// <param name="slideShowId"></param> public static void RemoveSlideShow(int id, int slideShowId) { try { using (var db = new MediaPlayerContext()) { // Get data and update field SlideShowMapper slideShowMapper = db.SlideShowMapper.Single(x => x.Id == slideShowId); AlbumMapper albumMapper = db.AlbumMapper.Single(x => x.Id == id); albumMapper.SlideShowMappers.Remove(slideShowMapper); albumMapper.LastUsed = DateTime.Now; db.SaveChanges(); } } catch { } }
/// <summary> /// Update name of slideshow /// </summary> /// <param name="id"></param> /// <param name="name"></param> public static void UpdateName(int id, string name) { try { SlideShowMapper slideShowMapper; using (var db = new MediaPlayerContext()) { // Get data and update field slideShowMapper = db.SlideShowMapper.Single(x => x.Id == id); slideShowMapper.Name = name; db.SaveChanges(); } AlbumQuery.UpdateLastUsed(slideShowMapper.AlbumMapper.Id); } catch { } }
/// <summary> /// Add new entry /// </summary> /// <param name="mediaDataMapper"></param> /// <returns></returns> public static int NewMediaData(MediaDataMapper mediaDataMapper) { int id = -1; try { using (var db = new MediaPlayerContext()) { // Get id (max+1) and add to table id = db.MediaDataMapper.Select(x => x.Id).DefaultIfEmpty(0).Max() + 1; mediaDataMapper.Id = id; db.MediaDataMapper.Add(mediaDataMapper); db.SaveChanges(); } } catch { } return(id); }
/// <summary> /// Remove mediadata /// </summary> /// <param name="id"></param> /// <param name="mediaDataId"></param> public static void RemoveMediaData(int id, int mediaDataId) { try { int albumId = 0; using (var db = new MediaPlayerContext()) { // Get data and update field MediaDataMapper mediaDataMapper = db.MediaDataMapper.Single(x => x.Id == mediaDataId); SlideShowMapper slideShowMapper = db.SlideShowMapper.Single(x => x.Id == id); slideShowMapper.MediaDataMappers.Remove(mediaDataMapper); albumId = slideShowMapper.AlbumMapper.Id; db.SaveChanges(); } AlbumQuery.UpdateLastUsed(albumId); } catch { } }
/// <summary> /// Retrive all ids and media data type /// </summary> /// <param name="slideShowId"></param> /// <returns></returns> public static Dictionary <int, MediaDataType> GetMediaDatas(int slideShowId) { // Create dictonary with id and corresponding mediadata type Dictionary <int, MediaDataType> mediaData = new Dictionary <int, MediaDataType>(); try { using (var db = new MediaPlayerContext()) { List <MediaDataMapper> mediaDataMappers = db.MediaDataMapper.Where(x => x.SlideShowMapper.Id == slideShowId).ToList(); foreach (MediaDataMapper mediaDataMapper in mediaDataMappers) { mediaData.Add(mediaDataMapper.Id, mediaDataMapper.MediaDataType); } } } catch { } return(mediaData); }
/// <summary> /// Add slideshow to table /// </summary> /// <param name="name"></param> /// <returns></returns> public static int NewSlideShow(string name) { SlideShowMapper slideShowMapper = new SlideShowMapper(name); int id = -1; try { using (var db = new MediaPlayerContext()) { // Get id (max+1) and add to table id = db.SlideShowMapper.Select(x => x.Id).DefaultIfEmpty(0).Max() + 1; slideShowMapper.Id = id; db.SlideShowMapper.Add(slideShowMapper); db.SaveChanges(); } } catch { } return(id); }
/// <summary> /// Get all albums ids /// </summary> /// <returns></returns> public static List <int> GetAlbums() { List <int> ints = new List <int>(); try { using (var db = new MediaPlayerContext()) { List <AlbumMapper> albumMappers = db.AlbumMapper.ToList(); if (albumMappers.Count > 0) { for (int i = 0; i < albumMappers.Count; i++) { ints.Add(albumMappers[i].Id); } } } } catch { } return(ints); }
/// <summary> /// Add album to table /// </summary> /// <param name="name"></param> /// <returns></returns> public static int NewAlbum(string name, out DateTime lastUsed) { // create new entity AlbumMapper albumMapper = new AlbumMapper(name); int id = 0; try { using (var db = new MediaPlayerContext()) { // Get new id (max)+1 and set parameteres id = db.AlbumMapper.Select(x => x.Id).DefaultIfEmpty(0).Max() + 1; albumMapper.Id = id; lastUsed = DateTime.Now; albumMapper.LastUsed = lastUsed; db.AlbumMapper.Add(albumMapper); db.SaveChanges(); } } catch { lastUsed = DateTime.MinValue; } return(id); }
/// <summary> /// Returns the key information of the last used album /// </summary> /// <param name="id"></param> /// <param name="name"></param> public static void GetLastUsed(ref int id, ref string name) { AlbumMapper albumMapper; try { using (var db = new MediaPlayerContext()) { // Order by last used, and set to current time (as it is being used now) albumMapper = db.AlbumMapper.OrderBy(x => x.LastUsed).FirstOrDefault(); albumMapper.LastUsed = DateTime.Now; db.SaveChanges(); } if (albumMapper != null) { id = albumMapper.Id; name = albumMapper.Name; return; } } catch { } id = -1; name = string.Empty; }
/// <summary> /// Retrive all slideshow ids for a album /// </summary> /// <param name="albumId"></param> /// <returns></returns> public static List <int> GetSlideShows(int albumId) { List <int> ints = new List <int>(); try { using (var db = new MediaPlayerContext()) { // Get list from album AlbumMapper albumMapper = db.AlbumMapper.Single(x => x.Id == albumId); List <SlideShowMapper> slideShowMappers = db.SlideShowMapper.Where(x => x.AlbumMapper.Id == albumId).ToList(); // Return as ids if (slideShowMappers.Count > 0) { foreach (SlideShowMapper slideShowMapper in slideShowMappers) { ints.Add(slideShowMapper.Id); } } } } catch { } return(ints); }
/// <summary> /// Update thumbnail image /// </summary> /// <param name="id"></param> /// <param name="thumbNailImage"></param> public static void UpdateThumbNail(int id, byte[] thumbNailImage) { int albumId = -1; try { using (var db = new MediaPlayerContext()) { // Get data and update field MediaDataMapper mediaDataMapper = db.MediaDataMapper.Single(x => x.Id == id); mediaDataMapper.ThumbNailImage = thumbNailImage; SlideShowMapper slideShowMapper = mediaDataMapper.SlideShowMapper; if (slideShowMapper != null) { albumId = slideShowMapper.AlbumMapper.Id; } db.SaveChanges(); } if (albumId >= 0) { AlbumQuery.UpdateLastUsed(albumId); } } catch { } }
/// <summary> /// Change order field /// </summary> /// <param name="id"></param> /// <param name="order"></param> public static void UpdateOrder(int id, int order) { int albumId = 0; try { using (var db = new MediaPlayerContext()) { // Get data and update field MediaDataMapper mediaDataMapper = db.MediaDataMapper.Single(x => x.Id == id); mediaDataMapper.Order = order; SlideShowMapper slideShowMapper = mediaDataMapper.SlideShowMapper; if (slideShowMapper != null) { albumId = slideShowMapper.AlbumMapper.Id; } db.SaveChanges(); } if (albumId >= 0) { AlbumQuery.UpdateLastUsed(albumId); } } catch { } }