public void IngresarDeportista(Entidades.Deportista deportista) { using (SqlConnection conexion = new SqlConnection(ConfigurationManager. ConnectionStrings["LigaNatacion"].ConnectionString)) { conexion.Open(); SqlTransaction tran = conexion.BeginTransaction(); try { SqlCommand comando = new SqlCommand(); comando.CommandType = CommandType.StoredProcedure; comando.Connection = conexion; comando.Transaction = tran; comando.CommandText = "IngresarDeportista"; comando.Parameters.Add("@PrimerNombre", SqlDbType.VarChar).Value = deportista.PrimerNombre; comando.Parameters.Add("@SegundoNombre", SqlDbType.VarChar).Value = deportista.SegundoNombre; comando.Parameters.Add("@PrimerApellido", SqlDbType.VarChar).Value = deportista.PrimerApellido; comando.Parameters.Add("@SegundoApellido", SqlDbType.VarChar).Value = deportista.SegundoApellido; comando.Parameters.Add("@Documento", SqlDbType.BigInt).Value = deportista.NumeroDocumento; comando.Parameters.Add("@FechaNacimiento", SqlDbType.DateTime).Value = deportista.FechaNacimiento; comando.Parameters.Add("@IdSexo", SqlDbType.SmallInt).Value = deportista.Sexo.Id; comando.Parameters.Add("@IdTipoDocumento", SqlDbType.SmallInt).Value = deportista.TipoDocumento.Id; comando.ExecuteNonQuery(); tran.Commit(); } catch { tran.Rollback(); throw; } } }
public ActionResult Crear(Deportista deportista) { var tiposDocumento = new List <SelectListItem>(); tiposDocumento.Add(new SelectListItem() { Text = "Cédula de Ciudadanía", Value = "1" }); tiposDocumento.Add(new SelectListItem() { Text = "Tarjeta de Identidad", Value = "2" }); ViewBag.TiposDocumento = tiposDocumento; DeportistaNegocio deportistaNegocio = new DeportistaNegocio(); Entidades.Deportista nuevoDeportista = new Entidades.Deportista() { FechaNacimiento = deportista.FechaNacimiento.Value, NumeroDocumento = deportista.NumeroDocumento, PrimerApellido = deportista.PrimerApellido, PrimerNombre = deportista.PrimerNombre, SegundoNombre = deportista.SegundoNombre, SegundoApellido = deportista.SegundoApellido, Sexo = new Entidades.Sexo() { Id = deportista.Genero == "M" ? 1 : 2 }, TipoDocumento = new Entidades.TipoDocumento() { Id = int.Parse(deportista.TipoDocumento) } }; try { deportistaNegocio.IngresarDeportista(nuevoDeportista); ViewBag.Mensaje = "Se ingresó el deportista"; } catch (Exception exc) { ViewBag.Mensaje = "No se pudo ingresar el deportista"; //Log.Error(exc); } return(View()); }
public List <Entidades.Deportista> ObtenerDeportistas(string numeroDocumento, string primerNombre, string segundoNombre, string primerApellido, string segundoApellido) { List <Entidades.Deportista> deportistas = new List <Entidades.Deportista>(); using (SqlConnection conexion = new SqlConnection(ConfigurationManager.ConnectionStrings["LigaNatacion"].ConnectionString)) { conexion.Open(); SqlCommand comando = new SqlCommand(); comando.CommandType = CommandType.StoredProcedure; comando.Connection = conexion; comando.CommandText = "ConsultarDeportistas"; comando.Parameters.Add("@PrimerNombre", SqlDbType.VarChar).Value = primerNombre; comando.Parameters.Add("@SegundoNombre", SqlDbType.VarChar).Value = segundoNombre; comando.Parameters.Add("@PrimerApellido", SqlDbType.VarChar).Value = primerApellido; comando.Parameters.Add("@SegundoApellido", SqlDbType.VarChar).Value = segundoApellido; comando.Parameters.Add("@Documento", SqlDbType.BigInt).Value = numeroDocumento; using (SqlDataReader reader = comando.ExecuteReader()) { while (reader.Read()) { Entidades.Deportista deportista = new Entidades.Deportista(); deportista.Id = Convert.ToInt64(reader["IdDeportista"]); deportista.PrimerNombre = reader["PrimerNombre"].ToString(); deportista.SegundoNombre = reader["SegundoNombre"].ToString(); deportista.PrimerApellido = reader["PrimerApellido"].ToString(); deportista.SegundoApellido = reader["SegundoApellido"].ToString(); deportista.NumeroDocumento = reader["Documento"].ToString(); deportista.FechaNacimiento = (DateTime)reader["FechaNacimiento"]; deportista.TipoDocumento = new Entidades.TipoDocumento() { Id = Convert.ToInt32(reader["IdTipoDocumento"]), Nombre = reader["NombreTipoDocumento"].ToString() }; deportistas.Add(deportista); } } } return(deportistas); }