Example #1
0
        // Tests GestionCompteJoueur
        private void BtnCompteJoueur_Click(object sender, EventArgs e)
        {
            txtTestes.Clear();
            GestionCompteJoueur gestionCompteJoueur = new GestionCompteJoueur();

            string Message = gestionCompteJoueur.CréerCompteJoueur("LinkTheHero", "*****@*****.**", "Link", "The Hero", 1, "Abc1234!");

            txtTestes.Text += "Test création CompteJoueur...\r\n";
            txtTestes.Text += "\r\n";
            txtTestes.Text += Message + "\r\n";

            txtTestes.Text += "\r\nTest modification CompteJoueur...\r\n";
            txtTestes.Text += "\r\n";

            CompteJoueur compteJoueur = new CompteJoueur()
            {
                NomJoueur       = "Ganon",
                Courriel        = "*****@*****.**",
                Prenom          = "Ganon",
                Nom             = "Bad",
                TypeUtilisateur = 1
            };
            string MotDePasse = "Toto";

            using (EntitiesGEDEquipe1 contexte = new EntitiesGEDEquipe1())
            {
                List <CompteJoueur> compteJoueurs = contexte.CompteJoueurs.ToList();
                compteJoueur.Id = compteJoueurs.Last().Id;
                gestionCompteJoueur.ModifierCompteJoueur(compteJoueur, MotDePasse);
            }
            txtTestes.Text += "SUCCESS\r\n";

            txtTestes.Text += "\r\nTest connexion CompteJoueur...\r\n";
            txtTestes.Text += "\r\n";

            string       testConnexion = "ERROR";
            CompteJoueur compte        = gestionCompteJoueur.ConnexionCompteJoueur("Ganon", "Toto");

            if (compte != null)
            {
                testConnexion = "SUCCESS";
            }

            txtTestes.Text += testConnexion + "\r\n";

            txtTestes.Text += "\r\nTest supression CompteJoueur...\r\n";
            txtTestes.Text += "\r\n";

            using (EntitiesGEDEquipe1 contexte = new EntitiesGEDEquipe1())
            {
                List <CompteJoueur> compteJoueurs = contexte.CompteJoueurs.ToList();
                compteJoueur = compteJoueurs.Last();
                gestionCompteJoueur.SupprimerCompteJoueur(compteJoueur);
            }
            txtTestes.Text += "SUCCESS\r\n";
        }
Example #2
0
        // Triger the user's creation
        private void btnCreateUser_Click(object sender, EventArgs e)
        {
            // Clear error messages
            lblErrUserName.Text        = "";
            lblErrFirstName.Text       = "";
            lblErrLastName.Text        = "";
            lblErrEmail.Text           = "";
            lblErrRole.Text            = "";
            lblErrPassword.Text        = "";
            lblErrConfirmPassword.Text = "";

            // Check if is there new error message to show
            Dictionary <string, string> dicErrors = _compteCréation.IsValid();

            foreach (var item in dicErrors)
            {
                switch (item.Value)
                {
                case "UserName":
                    lblErrUserName.Text += "* " + item.Key;
                    break;

                case "FirstName":
                    lblErrFirstName.Text += "* " + item.Key;
                    break;

                case "LastName":
                    lblErrLastName.Text += "* " + item.Key;
                    break;

                case "Email":
                    lblErrEmail.Text += "* " + item.Key;
                    break;

                case "Role":
                    lblErrRole.Text += "* " + item.Key;
                    break;

                case "Password":
                    lblErrPassword.Text += "* " + item.Key;
                    break;

                case "PasswordConfirm":
                    lblErrConfirmPassword.Text += "* " + item.Key;
                    break;

                default:
                    lblErrConfirmPassword.Text += "* " + item.Key;
                    break;
                }
            }

            // Try creation if no error count = 0
            if (dicErrors.Count == 0)
            {
                try
                {
                    string       sCreationState = _gestionCompteJoueur.CréerCompteJoueur(_compteCréation.UserName, _compteCréation.Email, _compteCréation.FirstName, _compteCréation.LastName, (int)_compteCréation.Role, _compteCréation.Password);
                    DialogResult mboxCreation   = MessageBox.Show("Creation state is :\r\n\r\n" + sCreationState, "Creation result");
                    if (mboxCreation == DialogResult.OK)
                    {
                        DialogResult = DialogResult.OK;
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed to create a new user.\r\n\r\nPlease try again or restart the game editor.", "Creation failed!");
                }
            }
        }