private void Button_Click(object sender, RoutedEventArgs e) { if (account.Money < decimal.Parse(tbValueBet.Text)) { MessageBox.Show("Not enough money to make bet"); return; } if (decimal.Parse(tbValueBet.Text) < 3) { MessageBox.Show("Minimal value of bet = 3"); return; } using (MainDB db = new MainDB()) { db.Accounts.Attach(account); account.Money -= decimal.Parse(tbValueBet.Text); var coefID = (dgMatchCoefs.SelectedItem as Coeficient).ID; Coeficient cf = db.Coefs.FirstOrDefault(x => x.ID == coefID); // db.Entry(cf).State = System.Data.Entity.EntityState.Unchanged; UserBet ub = new UserBet() { Accounts = account, Coef = cf, Price = double.Parse(tbValueBet.Text) }; db.UserBets.Add(ub); db.SaveChanges(); } MessageBox.Show("Bet made!"); this.Close(); }
private void Reg_btn_OnClick(object sender, RoutedEventArgs e) { Accounts acc = new Accounts() { Email = tbLogin.Text, Password = pbPass.Password, Money = decimal.Parse(tbMoney.Text) }; db.Accounts.Add(acc); db.SaveChanges(); MessageBox.Show("New account created. Please input data"); this.Close(); }