public void QueryInsertPlayer(Player player) { if (player != null) { player.PlayerID = QueryCountPlayers(); //This application does not have delete, if so this code needs to manage nextKey dbContext.Players.Local.Insert(player.PlayerID, player); dbContext.SaveChanges(); QueryPlayers(); } }
private void btn_add_Click(object sender, RoutedEventArgs e) { int pID = int.Parse(txt_playerID.Text); String fname = txt_fname.Text; String lname = txt_lname1.Text; decimal bav = decimal.Parse(txt_battingAverage.Text); Player p = new Player(); p.PlayerID = pID; p.FirstName = fname; p.LastName = lname; p.BattingAverage = bav; dbContent = new BaseballEntities(); dbContent.Players.Load(); dbContent.Players.Add(p); dbContent.SaveChanges(); dtGrid.ItemsSource = dbContent.Players.ToList(); }
private void btn_modify_Click(object sender, RoutedEventArgs e) { decimal battingAverage = decimal.Parse(txt_modifyAverage.Text); dbContent = new BaseballEntities(); dbContent.Players.Load(); (from item in dbContent.Players where item.LastName == txt_lname.Text select item).ToList().ForEach(x => x.BattingAverage = battingAverage);; dbContent.SaveChanges(); //dtGrid.ItemsSource = query.ToList(); var query = from item in dbContent.Players where item.LastName == txt_lname.Text select item; dtGrid.ItemsSource = query.ToList(); }