Beispiel #1
0
 private void btnAdd_Click(object sender, RoutedEventArgs e)
 {
     using (var ctx = new MusicStoreContext())
     {
         Order order = new Order();
         order.Music = ctx.Musics.Where(m => m.id == musicId).FirstOrDefault();
         order.User  = ctx.Users.Where(u => u.Id == loginUserId).FirstOrDefault();
         ctx.Orders.Add(order);
         ctx.SaveChanges();
         MessageBox.Show("One Music Added to Cart");
     }
 }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            dynamic row             = dataGrid.SelectedItem;
            int     selectedOrderId = row.Id;

            using (var ctx = new MusicStoreContext())
            {
                Order order = ctx.Orders.Where(o => o.Id == selectedOrderId).FirstOrDefault();
                ctx.Orders.Remove(order);
                ctx.SaveChanges();
                bindData();
            }
        }
Beispiel #3
0
 private void btSave_Click(object sender, RoutedEventArgs e)
 {
     using (var ctx = new MusicStoreContext())
     {
         Music m1 = ctx.Musics.Where(m => m.id == id).FirstOrDefault();
         m1.id        = id;
         m1.musicName = tbName.Text;
         m1.album     = tbAlbum.Text;
         m1.artist    = tbArtist.Text;
         m1.available = bool.Parse(tbAvailable.Text);
         ctx.SaveChanges();
         MessageBox.Show("Edited Successful");
         ManageMusic manageMusic = new ManageMusic();
         manageMusic.Show();
         this.Close();
     }
 }
 private void btSave_Click(object sender, RoutedEventArgs e)
 {
     using (var ctx = new MusicStoreContext())
     {
         Music m1 = new Music()
         {
             musicName = tbName.Text,
             album     = tbAlbum.Text,
             artist    = tbArtist.Text,
             available = bool.Parse(tbAvailable.Text)
         };
         ctx.Musics.Add(m1);
         ctx.SaveChanges();
         MessageBox.Show("Add to Database Successful");
         tbName.Clear();
         tbAlbum.Clear();
         tbArtist.Clear();
         tbAvailable.Clear();
     }
 }