Example #1
0
        public TvShowDetailsViewModel(Guid tvShowId)
        {
            _ctx = new MediaCatalogueEntities();


            _tvShow = (from media in _ctx.Media_Item
                       where media.id == tvShowId
                       select media).FirstOrDefault();

            Title       = _tvShow.Title;
            Description = _tvShow.Description;


            var segmentIds = from seg in _ctx.Media_Segment
                             where seg.Media_Item.id == tvShowId
                             orderby seg.SectionOffset
                             select seg.id;

            Segments = new ObservableCollection <TvShowSegment>();

            foreach (var seg in segmentIds)
            {
                Segments.Add(new TvShowSegment(seg));
            }
        }
Example #2
0
        protected override CommandResult Update()
        {
            if (_ctx == null)
            {
                _ctx = new MediaCatalogueEntities();
            }

            if (_tvShow == null)
            {
                _tvShow    = new Media_Item();
                _tvShow.id = ID;
                _ctx.AddToMedia_Item(_tvShow);
            }

            // Update the various Entity objects with changes made and save them.
            _tvShow.Title       = Title;
            _tvShow.Description = Description;

            // Find/create a TV SeriesMedia link

            if (SeriesID != Guid.Empty)
            {
                if ((from seriesMedia in _ctx.TV_SeriesMedia
                     .Include("TV_Series")
                     .Include("Media_Item")
                     where seriesMedia.Media_Item.id == _tvShow.id &&
                     seriesMedia.TV_Series.id == SeriesID
                     select seriesMedia.id).Count() == 0)
                {
                    // No TV_SeriesMedia record exists yet - create one
                    var tvSeriesMedia = new TV_SeriesMedia
                    {
                        id         = Guid.NewGuid(),
                        Media_Item = _tvShow,
                    };

                    tvSeriesMedia.TV_Series = (from series in _ctx.TV_Series
                                               where series.id == SeriesID
                                               select series).FirstOrDefault();
                }
            }

            try
            {
                _ctx.SaveChanges();
            }
            catch (Exception)
            {
                return(CommandResult.Failed);
            }

            return(CommandResult.Successful);
        }
        private void ImportSongs()
        {
            var musicVidType = MediaCatalogueHelper.GetMusicVideoType(_ctx);

            //List<Media_Item> songItems = new List<Media_Item>();

            foreach (var song in Items)
            {
                var songFileInfo = new Media_File
                {
                    id           = Guid.NewGuid(),
                    Filename     = song.Filename,
                    ModifiedDate = song.FileLastModified,
                    Size         = song.FileSize
                };

                var songItem = new Media_Item()
                {
                    id          = Guid.NewGuid(),
                    Title       = song.SongName,
                    Description = "by " + song.ArtistName,
                    Media_Type  = musicVidType
                };



                // Check for duplicates...

                var existingFile = (from mf in _ctx.Media_File
                                    where mf.Filename == songFileInfo.Filename &&
                                    //mf.ModifiedDate.Value == songFileInfo.ModifiedDate //&&
                                    mf.Size == songFileInfo.Size
                                    select mf).Count();

                if (existingFile == 0)
                {
                    songFileInfo.Media_Item.Add(songItem);
                    _ctx.AddToMedia_File(songFileInfo);
                }
            }

            _ctx.SaveChanges();
        }
Example #4
0
        /// <summary>
        /// Creates a new instance of the TvShowViewModel, loading the Media_Item entity
        /// with the specified id.
        /// </summary>
        /// <param name="id"></param>
        public TvShow(Guid id)
        {
            _ctx = new MediaCatalogueEntities();

            _tvShow = (from mi in _ctx.Media_Item
                       .Include("TV_SeriesMedia")
                       where mi.id == id
                       select mi).FirstOrDefault();

            if (_tvShow.TV_SeriesMedia != null)
            {
                var seriesMediaId = _tvShow.TV_SeriesMedia.FirstOrDefault().id;

                SeriesID = (from seriesMedia in _ctx.TV_SeriesMedia
                            .Include("TV_Series")
                            where seriesMedia.id == seriesMediaId
                            select seriesMedia.TV_Series.id).FirstOrDefault();
            }

            ID          = id;
            Title       = _tvShow.Title;
            Description = _tvShow.Description;
            IsDirty     = false;
        }