예제 #1
0
 /// <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 {
     }
 }
예제 #2
0
 /// <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 {
     }
 }
예제 #3
0
        /// <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);
        }
예제 #4
0
 /// <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 {
     }
 }
예제 #5
0
 /// <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 {
     }
 }
예제 #6
0
        /// <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);
        }
예제 #7
0
        /// <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);
        }