protected virtual void Dispose(bool disposing) { if (disposing) { _context.Dispose(); } }
protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); }
private async void btn_register_Click(object sender, EventArgs e) { RegisterModel model = new RegisterModel { Name = txbx_name.Text, Surname = txbx_surname.Text, BirthDate = dtp_datebirth.Value, Password = txbx_pwd.Text, ConfirmPassword = txbx_cpwd.Text, Email = txbx_email.Text, RoleId = 2 }; Tuple <bool, List <ValidationResult> > results = this.CustomValidator(model); if (results.Item1) { try { Player user = model; db = new GameDbContext(); Player findedUser = await db.Players.GetUserByEmailAsync(user.Email); if (findedUser != null) { MessageBox.Show("There is profile with this email"); } else { db.Players.Add(user); await db.SaveChangesAsync(); } } catch (SqlException ex) { MessageBox.Show("Database Error :" + " " + ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (db != null) { db.Dispose(); } } } else { lbl_errors.Text = ""; foreach (ValidationResult item in results.Item2) { lbl_errors.Text = item.ErrorMessage + "\n"; } } }
protected virtual void Dispose(bool disposing) { if (disposing) { if (GameDbContext != null) { GameDbContext.Dispose(); } } }
protected virtual void Dispose(bool disposing) { if (disposing) { if (_context != null) { _context.Dispose(); _context = null; } } }
private async void AdminPanel_Load(object sender, EventArgs e) { try { db = new GameDbContext(); freePlayers = await db.Players.GetFreePlayersAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (db != null) { db.Dispose(); } } try { db = new GameDbContext(); foreach (Player player in freePlayers) { playerModels.Add(new PlayerModel { Id = player.Id, FullName = player.Name + " " + player.Surname, Position = player.Postion, Age = this.CalculateAge(player.BirthDate) }); } foreach (PlayerModel model in playerModels) { model.Skills = db.Players.GetPlayerSkills(model.Id); } ; CreatePlayerControl(playerModels, 0, 3); Session.SetValue("PlayerCount", 3); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (db != null) { db.Dispose(); } } }
public virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { _db.Dispose(); } _disposed = true; }
private async void btn_login_Click(object sender, EventArgs e) { LoginModel model = new LoginModel { Email = txbx_email.Text, Password = txbx_pwd.Text }; try { db = new GameDbContext(); Player findedUser = await db.Players.GetUserByEmailAsync(model.Email); if (findedUser != null) { Close(); if (findedUser.RoleId == 0) { new AdminPanel().Show(); } else { new PlayerPanel().Show(); } } else { MessageBox.Show("Your email or password is incorrect"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (db != null) { db.Dispose(); } } }