Exemple #1
0
 private void ButtonConfirm_Click(object sender, RoutedEventArgs e)
 {
     using (MusicContext db = new MusicContext())
     {
         Album album = db.Albums.Find(editableAlbum.Id);
         if (album != null)
         {
             if (editableAlbum.Songs.Count == 0)
             {
                 album.Songs.Clear();
             }
             else
             {
                 album.Songs.Clear();
                 album.Songs = editableAlbum.Songs;
             }
         }
         db.SaveChanges();
     }
     this.Close();
 }
Exemple #2
0
 private void ConfirmButton_Click(object sender, RoutedEventArgs e)
 {
     if (titleTextBox.Text != "" && urlTextBox.Text != "" && genreComboBox.SelectedIndex != -1 && authorComboBox.SelectedIndex != -1 && lengthTextBox.Text != "" && datePublishCalendar.SelectedDate != null && newAlbum.Image != null && songsExist == true)
     {
         using (MusicContext db = new MusicContext())
         {
             newAlbum.Title = titleTextBox.Text;
             string authName  = (authorComboBox.SelectedItem as Author).Name.ToString();
             string authGenre = (genreComboBox.SelectedItem as Genre).Name;
             newAlbum.Author  = db.Authors.FirstOrDefault(x => x.Name == authName);
             newAlbum.Genre   = db.Genres.FirstOrDefault(x => x.Name == authGenre);
             newAlbum.Length  = StringToSeconds(lengthTextBox.Text);
             newAlbum.Price   = decimal.Parse(priceTextBox.Text);
             newAlbum.ShopUrl = urlTextBox.Text;
         }
         using (MusicContext db = new MusicContext())
         {
             db.Albums.Add(newAlbum);
             db.SaveChanges();
             songsExist = false;
             this.ShowMessageAsync("Alert", "Song successfully added");
         }
     }
 }