protected override CommandResult Update() { if (_ctx == null) { _ctx = new MediaCatalogueEntities(); } if (IsNew) { var tvSeries = (from series in _ctx.TV_Series where series.id == SeriesId select series).FirstOrDefault(); _presenter = new TV_Presenter { id = this.ID, TV_Series = tvSeries }; } _presenter.Name = Name; try { _ctx.SaveChanges(); } catch (Exception) { return(CommandResult.Failed); } return(CommandResult.Successful); }
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); }
protected override CommandResult Update() { if (_ctx == null) { _ctx = new MediaCatalogueEntities(); } if (IsNew) { var tvSeries = (from series in _ctx.TV_Series where series.id == SeriesID select series).FirstOrDefault(); // Note: Because we are attaching a Series to the SeriesCategory, the SeriesCategory // is automatically associated with the DataContext we are using - no need to manually add it. _category = new TV_SeriesCategory { id = this.ID, TV_Series = tvSeries }; } _category.Title = Title; _category.Description = Description; 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(); }
private void Save() { _series.Description = Description; _ctx.SaveChanges(); }
protected override CommandResult Update() { if (_ctx == null) { _ctx = new MediaCatalogueEntities(); } if (IsNew) { _segment = new Media_Segment { id = this.ID }; _segment.Media_Item = (from media in _ctx.Media_Item where media.id == ParentID select media).FirstOrDefault(); _ctx.AddToMedia_Segment(_segment); } _segment.Title = this.Title; _segment.Description = this.Description; _segment.SectionOffset = this.StartOffset; _segment.SectionLength = this.SectionLength; //var seg = (from segment in _ctx.Media_Segment // where segment.id == ID // select segment).FirstOrDefault(); //if (seg == null) //{ // // Add as a new segment // seg = new Media_Segment // { // id = ID, // Title = this.Title, // Description = this.Description, // SectionOffset = this.StartOffset, // SectionLength = this.SectionLength, // }; // seg.Media_Item = (from media in _ctx.Media_Item // where media.id == ParentID // select media).FirstOrDefault(); // ctx.AddToMedia_Segment(seg); //} //else //{ // seg.Title = this.Title; // seg.Description = this.Description; // seg.SectionOffset = this.StartOffset; // seg.SectionLength = this.SectionLength; //} // Update Presenter if (Presenter == null) { _segment.TV_Presenter = null; } else { _segment.TV_Presenter = (from pres in _ctx.TV_Presenter where pres.id == Presenter.ID select pres).FirstOrDefault(); } // Update SeriesCategory if (Category == null) { _segment.TV_SeriesCategory = null; } else { _segment.TV_SeriesCategory = (from cat in _ctx.TV_SeriesCategory where cat.id == Category.ID select cat).FirstOrDefault(); } try { _ctx.SaveChanges(); } catch (Exception) { return(CommandResult.Failed); } return(CommandResult.Successful); }