예제 #1
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _context.Dispose();
     }
 }
예제 #2
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
예제 #3
0
        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";
                }
            }
        }
예제 #4
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (GameDbContext != null)
         {
             GameDbContext.Dispose();
         }
     }
 }
예제 #5
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_context != null)
         {
             _context.Dispose();
             _context = null;
         }
     }
 }
예제 #6
0
        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();
                }
            }
        }
예제 #7
0
        public virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                _db.Dispose();
            }

            _disposed = true;
        }
예제 #8
0
        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();
                }
            }
        }