Пример #1
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     using (var ctx = new MusicStoreContext())
     {
         musicsNumber = ctx.Musics.Where(m => m.available == true).Count();
         Music m1 = ctx.Musics.Where(m => m.available == true).FirstOrDefault();
         tbSong.Text   = m1.musicName;
         tbAlbum.Text  = m1.album;
         tbArtist.Text = m1.artist;
     }
 }
Пример #2
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();
            }
        }
Пример #4
0
 private void btnPrivious_Click(object sender, RoutedEventArgs e)
 {
     if (counter > 0)
     {
         counter--;
         using (var ctx = new MusicStoreContext())
         {
             List <Music> fetchMusicList = ctx.Musics.Where(m => m.available == true).ToList();
             tbSong.Text   = fetchMusicList[counter].musicName;
             tbAlbum.Text  = fetchMusicList[counter].album;
             tbArtist.Text = fetchMusicList[counter].artist;
             musicId       = fetchMusicList[counter].id;
         }
     }
 }
Пример #5
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            using (var ctx = new MusicStoreContext())
            {
                string uName   = tbUserName.Text.Trim();
                string pwd     = tbPassword.Text.Trim();
                bool   isAdmin = rbAdmin.IsChecked ?? false;

                List <User> list1 = ctx.Users.Where(u => u.UserName == uName).ToList();

                if (list1.Count >= 1)
                {
                    User loginUser = ctx.Users.Where(u => u.UserName == uName).FirstOrDefault();
                    loginUserId = loginUser.Id;
                    List <User> list2 = ctx.Users.Where(u => u.UserName == uName && u.PassWord == pwd).ToList();
                    if (list2.Count >= 1)
                    {
                        if (isAdmin == false)
                        {
                            Window1 BuyMusic = new Window1();
                            BuyMusic.loginUserId = loginUserId;
                            this.Close();
                            BuyMusic.Show();
                        }
                        else
                        {
                            ManageMusic manageMusic = new ManageMusic();
                            this.Close();
                            manageMusic.Show();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Either the user name or password entered is incorrect.");
                    }
                }
                else
                {
                    MessageBox.Show("Either the user name or password entered is incorrect.");
                }

                //int howManyUsers = ctx.Users.Count();
                //User u1 = new User() { UserName = "******", PassWord = "******", isAdmin = true };
                //ctx.Users.Add(u1);
                //ctx.SaveChanges();
            }
        }
Пример #6
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();
     }
 }
Пример #7
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     UnityConfig.RegisterComponents();
     Database.SetInitializer(new MigrateDatabaseToLatestVersion <MusicStoreContext, Migrations.Configuration>());
     Database.SetInitializer(new MigrateDatabaseToLatestVersion <AppDbContext, Migrations.UserConfiguration>());
     using (var context = new MusicStoreContext())
     {
         context.Database.Initialize(true);
     }
     using (var context = new AppDbContext())
     {
         context.Database.Initialize(true);
     }
     //Database.SetInitializer<MusicStore.Models.MusicStoreContext>(InitialCreate);
 }
 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();
     }
 }
Пример #9
0
 public MySqlHealthContributor(MusicStoreContext dbContext, ILogger <MySqlHealthContributor> logger)
 {
     _context = dbContext;
     _logger  = logger;
 }