private void buttonInsertMusician_Click(object sender, EventArgs e) { if (textBoxFirstName.Text == "" || textBoxSurname.Text == "" || textBoxDiscription.Text == "") { MessageBox.Show("Wrong input!"); return; } IMusiciansRepository musRep = new MusiciansRepository(); bool flag = musRep.AddMusician(textBoxFirstName.Text, textBoxSurname.Text, textBoxBand.Text, textBoxDiscription.Text); if (flag) { MessageBox.Show("Posted!"); } else { MessageBox.Show("Error!"); } textBoxFirstName.Text = ""; textBoxSurname.Text = ""; textBoxBand.Text = ""; textBoxDiscription.Text = ""; }
private void buttonDeleteMusician_Click(object sender, EventArgs e) { if (textBoxFirstNameDelete.Text == "" || textBoxSurnameDelete.Text == "") { MessageBox.Show("Wrong input!"); return; } IMusiciansRepository musRep = new MusiciansRepository(); bool flag = musRep.DeleteMusician(textBoxFirstNameDelete.Text, textBoxSurnameDelete.Text); if (flag) { MessageBox.Show("Deleted!"); } else { MessageBox.Show("Error!"); } textBoxFirstNameDelete.Text = ""; textBoxSurnameDelete.Text = ""; }
private void buttonSeeMusicians_Click(object sender, EventArgs e) { IMusiciansRepository musRep = new MusiciansRepository(); List <MusicianModel> musicians = musRep.GetAllMusicians().ToList(); listMusicians.Items.Clear(); foreach (MusicianModel musician in musicians) { string toList = "Musician id:" + musician.MusicianId + ", First name: " + musician.FirstName + ", Second name:" + musician.Surname + ", Role description:" + musician.DiscriptionOfRole + ", Current band:"; if (musician.BandName == null) { toList += "none"; } else { toList += musician.BandName; } listMusicians.Items.Add(toList); } }
public static void Main(string[] args) { // Connecting to database and pulling data var musiciansRepository = new MusiciansRepository(); var albumsRepository = new AlbumsRepository(); var songsRepository = new SongsRepository(); var albumsSongsRepository = new AlbumsSongsRepository(); const string connectionString = "Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=Music;Integrated Security=true;MultipleActiveResultSets=true;"; using (var connection = new SqlConnection(connectionString)) { musiciansRepository.AddList(connection.Query <Musician>("SELECT * FROM Musician").ToList()); albumsRepository.AddList(connection.Query <Album>("SELECT * FROM Album").ToList()); songsRepository.AddList(connection.Query <Song>("SELECT * FROM Song").ToList()); albumsSongsRepository.AddList(connection.Query <AlbumSong>("SELECT * FROM AlbumSong").ToList()); } musiciansRepository.CreateRelations(); albumsRepository.CreateRelations(); // Task 1 NewTask("Task 1"); Console.WriteLine("All musicians ordered by name: "); musiciansRepository.GetAll() .OrderBy(musician => musician.Name) .ToList() .ForEach(musician => Console.WriteLine(musician.ToString())); // Task 2 NewTask("Task 2"); Console.Write("Choose nationality (0-1): "); var selectedNationality = (Nationalities)int.Parse(Console.ReadLine()); musiciansRepository.GetAll() .Where(musician => musician.Nationality == selectedNationality) .ToList() .ForEach(musician => Console.WriteLine(musician.ToString())); // Task 3 NewTask("Task 3"); var groupedAlbumsRepository = albumsRepository.GetAll() .GroupBy(album => album.ReleaseDate.Year) .ToList(); groupedAlbumsRepository.ForEach(albumGroup => { Console.WriteLine($"{albumGroup.Key}:"); albumGroup.ToList().ForEach(album => Console.WriteLine(album.ToString())); }); // Task 4 NewTask("Task 4"); Console.Write("Input album name: "); var selectedText = Console.ReadLine(); Console.WriteLine("All albums containing selected text: "); albumsRepository.GetAll() .Where(album => selectedText != null && album.Name.Contains(selectedText)) .ToList() .ForEach(album => Console.WriteLine(album.ToString())); // Task 5 NewTask("Task 5"); Console.WriteLine("Duration of all albums: "); albumsRepository.GetAll() .ForEach(album => Console.WriteLine($"{album.Name}: {album.Duration() / 60} minutes and {album.Duration() % 60} seconds")); // Task 6 NewTask("Task 6"); Console.Write("Input name of the song: "); var selectedSong = Console.ReadLine(); var selectedSongAsSong = songsRepository.GetAll().FirstOrDefault(song => selectedSong != null && song.Name.Contains(selectedSong)); Console.WriteLine("All albums with selected song: "); albumsRepository.GetAll() .Where(album => album.SongsList.Contains(selectedSongAsSong)) .ToList() .ForEach(album => Console.WriteLine(album.ToString())); // Task 7 NewTask("Task 7"); Console.Write("Input musician name: "); var selectedMusician = Console.ReadLine(); Console.Write("Input release year: "); var selectedReleaseYear = int.Parse(Console.ReadLine()); albumsRepository.GetAll() .Where(album => selectedMusician != null && (album.Musician.Name.Contains(selectedMusician) && album.ReleaseDate.Year > selectedReleaseYear)) .ToList() .ForEach(album => album.SongsList.ForEach(song => Console.WriteLine(song.ToString()))); }