public TvSeriesCategory(Guid categoryId) { _ctx = new MediaCatalogueEntities(); _category = (from cat in _ctx.TV_SeriesCategory where cat.id == categoryId select cat).FirstOrDefault(); ID = _category.id; Title = _category.Title; Description = _category.Description; IsDirty = false; }
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); }