private void btnSave_Click(object sender, EventArgs e) { try { if (esNuevoUsuario) { user = new User(); } user = ValidarDetallesPersona(user); Rol rolSeleccionado = (Rol)cbxRoles.SelectedItem; if (esNuevoUsuario) { user.UserName = user.DetallesPersona.DNI.ToString(); user.UserID = _userManager.InsertarUsuario(user); _detallesManager.AgregarDetalles(user.DetallesPersona, user.UserID); } else { _detallesManager.ModificarDetalles(user.DetallesPersona, user.UserID); } if (perfil.Nombre == "Afiliado") { _afiliado = ((AfiliadoUserControl)afiliadoUserControl).devolverCampos(); _afiliado.UserID = user.UserID; _afiliado.grupoFamiliar = _grupoFamiliar; _afiliado.DetallesPersona = user.DetallesPersona; _afiliado.tipoAfiliado = _tipoAfiliado; _afiliado.RoleID = rolSeleccionado.ID; _afiliado = _afiliadoManager.GuardarAfiliado(_afiliado); user = _afiliado as User; } else if (perfil.Nombre == "Profesional") { _profesional = ((ProfesionalUserControl)profesionalUserControl).GetProfesional(); _profesional.DetallesPersona = user.DetallesPersona; _profesional.UserID = user.UserID; _profesional.RoleID = rolSeleccionado.ID; _profesionalManager.GuardarProfesional(_profesional); user = _profesional as User; } else { throw new Exception("Error en Perfiles"); } OnUserSaved(this, new UserSavedEventArgs() { User = user, grupoFamiliar = _grupoFamiliar }); this.Close(); } catch (System.Exception excep) { MessageBox.Show(excep.Message); return; } }
private void btnSave_Click(object sender, EventArgs e) { long telefono; long dni; Session.Errores = null; if (!long.TryParse(txtTelefono.Text.Trim().Replace("-", ""), out telefono)) { throw new Exception(" El teléfono debe ser numérico!"); } if (!long.TryParse(txtDNI.Text, out dni)) { throw new Exception(" El DNI debe ser numérico!"); } if (string.IsNullOrEmpty(txtNombre.Text.Trim())) { throw new Exception(" El Nombre es obligatorio!"); } if (string.IsNullOrEmpty(txtApellido.Text.Trim())) { throw new Exception(" El Apellido es obligatorio!"); } if (string.IsNullOrEmpty(txtMail.Text.Trim())) { throw new Exception(" El Email es obligatorio!"); } user.DetallesPersona.Apellido = txtApellido.Text.Trim(); user.DetallesPersona.Nombre = txtNombre.Text.Trim(); user.DetallesPersona.DNI = dni; user.DetallesPersona.FechaNacimiento = dtFechaNacimiento.Value; user.DetallesPersona.Direccion = txtDireccion.Text.Trim(); user.DetallesPersona.Telefono = telefono; user.DetallesPersona.Email = txtMail.Text.Trim(); Rol rolSeleccionado = (Rol)cbxRoles.SelectedItem; if (Session.Errores != null) { MessageBox.Show(Session.Errores); } else { if (perfil.Nombre == "Afiliado") { _afiliado = ((AfiliadoUserControl)afiliadoUserControl).devolverCampos(); _afiliado.UserName = user.DetallesPersona.DNI.ToString(); var manager = new AfiliadoManager(); _afiliado.DetallesPersona = user.DetallesPersona; _afiliado.RoleID = rolSeleccionado.ID; try { manager.GuardarAfiliado(_afiliado); user = _afiliado; this.Close(); } catch (System.Exception excep) { MessageBox.Show(excep.Message); } } else if (perfil.Nombre == "Profesional") { _profesional = ((ProfesionalUserControl)profesionalUserControl).GetProfesional(); _profesional.DetallesPersona = user.DetallesPersona; _profesional.UserName = user.DetallesPersona.DNI.ToString(); var manager = new ProfesionalManager(); _profesional.RoleID = rolSeleccionado.ID; try { manager.GuardarProfesional(_profesional); user = _profesional; this.Close(); } catch (System.Exception excep) { MessageBox.Show(excep.Message); } } else { throw new Exception("Error en Perfiles"); } } // OnUserSaved(this, new UserSavedEventArgs() { Username = this.txtUsername.Text, User = user }); }