private void btnButton_Click(object sender, EventArgs e) { UserBC userBC = new UserBC(); var guid = Guid.NewGuid(); try { var user = new UserBE(); user.Birthday = Convert.ToDateTime(dtpBirthday.Text); user.DNI = txtDNI.Text; user.Email = txtEmail.Text; user.Gener = ((KeyValuePair <string, string>)cmbGener.SelectedItem).Value; user.LastName = txtLastName.Text; user.Name = txtNombre.Text; user.Password = txtPassword.Text; user.PhoneNumber = txtTelefono.Text; user.Status = ((KeyValuePair <string, string>)cmbStatus.SelectedItem).Value; user.username = txtUsername.Text; user.IdUser = guid.ToString(); user.User_Role = (cmbRol.Text == "ADM") ? 1 : (cmbRol.Text == "DOC") ? 2 : (cmbRol.Text == "PCT") ? 3 : 4; var result = userBC.CreateUser(user); if (result) { if (cmbRol.Text == "PCT") { var idBlood = cmbTipoSangre.SelectedIndex + 1; var paciente = context.Patients.Add(new Patients { UserId = guid, BloodType = idBlood, Policy = txtPoliza.Text, Date_Creation = DateTime.Now, Date_Update = DateTime.Now, }); } else if (cmbRol.Text == "DOC" || cmbRol.Text == "ENF") { var idSpecility = cmbEspecialidad.SelectedIndex + 1; var doc = context.Doctor.Add(new Doctor { Userid = guid, CMP = txtCMP.Text, SpecialityId = idSpecility }); } context.SaveChanges(); frmusers.udpateDataGridView(); MessageBox.Show("Se registro satisfactoriamente."); this.Close(); } else { MessageBox.Show("Ocurrio un error vuelva a intentar"); } //var birthday = Convert.ToDateTime(dtpBirthday.Text); //var gener = ((KeyValuePair<string, string>)cmbGener.SelectedItem).Value; //var pass = PasswordSC.PasswordEncriptarSHA512(txtPassword.Text); //var status = ((KeyValuePair<string, string>)cmbStatus.SelectedItem).Value; //var guid = Guid.NewGuid(); //var role = (cmbRol.Text == "ADM") ? 1 : (cmbRol.Text == "DOC") ? 2 : (cmbRol.Text == "PCT") ? 3 : 4; //var user = context.Users.Add(new Users { // Name = txtNombre.Text, // LastName = txtLastName.Text, // Birthday = birthday, // DNI = txtDNI.Text, // Email = txtEmail.Text, // Gener = gener, // Password = pass, // PhoneNumber = txtTelefono.Text, // Status = status, // username = txtUsername.Text, // IdUser = guid, // User_Role = role, //}); } catch (Exception ex) { MessageBox.Show(ex.Message); } }