public static E_Respuesta EliminarPersona(int id) { Conexion c = new Conexion(); SqlCommand cmd = new SqlCommand(); E_Respuesta response = new E_Respuesta(); try { cmd.Connection = c.cadena; cmd.Connection.Open(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "sp_DeletePersona"; cmd.Parameters.AddWithValue("@codigo", id); using (SqlDataReader lector = cmd.ExecuteReader()) { while (lector.Read()) { response.id = Convert.ToInt32(lector["id"]); response.mensaje = lector["mensaje"].ToString(); } } } catch (Exception e) { e.ToString(); } finally { cmd.Dispose(); c.cadena.Close(); } return(response); }
public static E_Respuesta RegistrarPersona(E_Persona request) { Conexion c = new Conexion(); SqlCommand cmd = new SqlCommand(); E_Respuesta response = new E_Respuesta(); try { //dar permisos al comando de ejecucion cmd.Connection = c.cadena; //abrir conexion cmd.Connection.Open(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "sp_Registrar"; cmd.Parameters.AddWithValue("@nombres", request.nombres); cmd.Parameters.AddWithValue("@apellidos", request.apellidos); cmd.Parameters.AddWithValue("@edad", request.edad); cmd.Parameters.AddWithValue("@fecha", request.fecha); using (SqlDataReader lector = cmd.ExecuteReader()) { while (lector.Read()) { response.id = Convert.ToInt32(lector["id"]); response.mensaje = lector["mensaje"] as string ?? ""; } } } catch (Exception e) { e.ToString(); } finally { cmd.Dispose(); c.cadena.Close(); } return(response); }
public static E_Respuesta ActualizarPersona(E_Persona p) { Conexion c = new Conexion(); SqlCommand cmd = new SqlCommand(); E_Respuesta response = new E_Respuesta(); try { cmd.Connection = c.cadena; cmd.Connection.Open(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "sp_UpdatePersona"; cmd.Parameters.AddWithValue("@codigo", p.codigo); cmd.Parameters.AddWithValue("@nombres", p.nombres); cmd.Parameters.AddWithValue("@apellidos", p.apellidos); cmd.Parameters.AddWithValue("@edad", p.edad); cmd.Parameters.AddWithValue("@fecha", p.fecha); using (SqlDataReader lector = cmd.ExecuteReader()) { while (lector.Read()) { response.id = Convert.ToInt32(lector["id"]); response.mensaje = lector["mensaje"].ToString(); } } } catch (Exception e) { e.ToString(); } finally { cmd.Dispose(); c.cadena.Close(); } return(response); }