Beispiel #1
0
        private void buttonDeleteGenre_Click(object sender, RoutedEventArgs e)
        {
            if (listBoxGenres.SelectedIndex != -1)
            {
                Genre selectedGenre = (Genre)listBoxGenres.SelectedItem;
                var   window        = new DeleteGenreWindow(selectedGenre);
                if (window.ShowDialog().Value)
                {
                    int originalId    = selectedGenre.Id;
                    int replacementId = window.Replacement.Id;

                    Data.ReadGenresData();
                    foreach (Movie movie in Data.Movies)
                    {
                        if (movie.GenreId == originalId)
                        {
                            movie.GenreId = replacementId;
                        }
                    }

                    Data.Genres.RemoveAll(genre => genre.Id == originalId);
                    Data.UpdateGenresData();
                    RefreshListBoxGenres();
                    textBoxSearchGenres.Text = "";
                    Logger.Log($"Удалён жанр \"{selectedGenre.Name}\" с заменой на \"{window.Replacement.Name}\"");
                }
            }
        }
Beispiel #2
0
        private void buttonAddGenre_Click(object sender, RoutedEventArgs e)
        {
            var window = new AddGenreWindow();

            if (window.ShowDialog().Value)
            {
                Data.ReadGenresData();
                Data.Genres.Add(window.NewGenre);
                Data.UpdateGenresData();
                Data.IsSearched = false;
                UpdateButtonsGenres();
                RefreshListBoxGenres();
                Logger.Log($"Добавлен новый жанр: \"{window.NewGenre.Name}\"");
            }
        }
Beispiel #3
0
        private void buttonChangeGenre_Click(object sender, RoutedEventArgs e)
        {
            if (listBoxGenres.SelectedIndex != -1)
            {
                Genre selectedGenre     = (Genre)listBoxGenres.SelectedItem;
                int   selectedListIndex = Data.Genres.FindIndex(genre => genre.Id == selectedGenre.Id);

                var window = new ChangeGenreWindow(Data.Genres[selectedListIndex]);
                if (window.ShowDialog().Value)
                {
                    string oldName = Data.Genres[selectedListIndex].Name;
                    Data.Genres[selectedListIndex].Name = window.ChangedName;
                    Data.UpdateGenresData();
                    RefreshListBoxGenres();
                    Logger.Log(oldName == window.ChangedName ?
                               $"Изменён жанр: \"{window.ChangedName}\"" :
                               $"Изменён жанр: \"{oldName}\" -> \"{window.ChangedName}\"");
                }
            }
        }