/// <summary> /// Добавить Сезон в список /// </summary> public void AddSeason() { var count = Seasons.Count + 1; var newSeason = new CartoonSeason { CartoonId = GlobalIdList.CartoonId, Number = count, Checked = true, CartoonEpisodes = new List <CartoonEpisode>() }; Seasons.Add(newSeason); NotifyOfPropertyChange(() => Seasons); ((CartoonsEditorViewModel)Parent).Seasons.Add(newSeason); NotifyOfPropertyChange(() => ((CartoonsEditorViewModel)Parent).Seasons); using (var ctx = new CVDbContext(AppDataPath)) { ctx.CartoonSeasons.Add(Seasons.Last()); ctx.SaveChanges(); Seasons.Last().CartoonSeasonId = ctx.CartoonSeasons.ToList().Last().CartoonSeasonId; } SelectedSeason = Seasons.Count > 0 ? Seasons.Last() : null; }
/// <summary> /// Удалить выбранный сезон /// </summary> public void RemoveSeason() { if (CanRemoveSeason is false) { return; } using (var ctx = new CVDbContext(AppDataPath)) { var temp = ctx.CartoonSeasons.Find(SelectedSeason.CartoonSeasonId); ctx.Entry(temp).State = EntityState.Deleted; ctx.SaveChanges(); } var tempList = ((CartoonsEditorViewModel)Parent).Seasons; ((CartoonsEditorViewModel)Parent) .Seasons.Remove(tempList.First(s => s.CartoonSeasonId == SelectedSeason.CartoonSeasonId)); Seasons.Remove(SelectedSeason); NotifyOfPropertyChange(() => Seasons); SelectedSeason = Seasons.Count > 0 ? Seasons.Last() : null; }