public ActionResult Post([FromBody] TarjetasModel tarjetam) { int result = 0; string msj = "¡Error al guardar tarjeta intente más tarde!"; try { if (tarjetam.agregarTarjeta()) { result = 1; msj = "¡Tarjeta guardada!"; } else { result = 0; if (!string.IsNullOrEmpty(tarjetam.ERROR) && !tarjetam.ERROR.Equals("Error al hacer el cargo.")) { msj = tarjetam.ERROR; } } } catch { result = 0; msj = "¡Error al guardar tarjeta intente más tarde!"; } return(Ok(new { resultado = result, mensaje = msj, tarjeta = tarjetam.card })); }
/// <summary> /// Selects the Single object of TarjetasModel table. /// </summary> public TarjetasModel GetTarjetasModel(int aNumero) { TarjetasModel TarjetasModel = null; try { using (var connection = Util.ConnectionFactory.conexion()) { connection.Open(); SqlCommand command = connection.CreateCommand(); command.Parameters.AddWithValue("@Numero", aNumero); command.CommandType = CommandType.StoredProcedure; command.CommandText = "TarjetasModelSelect"; SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { int Numero = (int)(reader["Numero"]); short? Password = reader["Password"] as short?; byte CodControl = (byte)(reader["CodControl"]); DateTime?FechaVencimiento = reader["FechaVencimiento"] as DateTime?; DateTime FechaVinculacion = (DateTime)(reader["FechaVinculacion"]); bool Estado = (bool)(reader["Estado"]); DateTime?FECHA_MODIFICACION = reader["FECHA_MODIFICACION"] as DateTime?; int USUARIO_CREADOR = (int)(reader["USUARIO_CREADOR"]); int? USUARIO_MODIFICADOR = reader["USUARIO_MODIFICADOR"] as int?; DateTime FECHA_CREACION = (DateTime)(reader["FECHA_CREACION"]); TarjetasModel = new TarjetasModel { Numero = Numero, Password = Password, Codcontrol = CodControl, Fechavencimiento = FechaVencimiento, Fechavinculacion = FechaVinculacion, Estado = Estado, Fecha_modificacion = FECHA_MODIFICACION, Usuario_creador = USUARIO_CREADOR, Usuario_modificador = USUARIO_MODIFICADOR, Fecha_creacion = FECHA_CREACION, }; } } } return(TarjetasModel); } catch (Exception) { return(null); } }
public ActionResult Post([FromBody] TarjetasModel tarjetam) { int result = 0; string msj = "¡Error al obtener tarjetas intente más tarde!"; List <Card> listatar = new List <Card>(); try { listatar = tarjetam.obneterTargetasPorPkCliente1(); result = 1; msj = "¡Tarjetas obtenidas!"; } catch { result = 0; msj = "¡Error al obtener tarjetas intente más tarde!"; } return(Ok(new { resultado = result, mensaje = msj, tarjetas = listatar })); }
/// <summary> /// Updates a record to the TarjetasModel table. /// returns True if value saved successfully else false /// Throw exception with message value EXISTS if the data is duplicate /// </summary> public bool Update(TarjetasModel aTarjetasModel) { try { using (var connection = Util.ConnectionFactory.conexion()) { connection.Open(); SqlTransaction sqlTran = connection.BeginTransaction(); SqlCommand command = connection.CreateCommand(); command.Transaction = sqlTran; command.Parameters.AddWithValue("@Numero", aTarjetasModel.Numero); command.Parameters.AddWithValue("@Password", aTarjetasModel.Password == null ? (object)DBNull.Value : aTarjetasModel.Password); command.Parameters.AddWithValue("@CodControl", aTarjetasModel.Codcontrol); command.Parameters.AddWithValue("@FechaVencimiento", aTarjetasModel.Fechavencimiento == null ? (object)DBNull.Value : aTarjetasModel.Fechavencimiento); command.Parameters.AddWithValue("@FechaVinculacion", aTarjetasModel.Fechavinculacion); command.Parameters.AddWithValue("@Estado", aTarjetasModel.Estado); command.Parameters.AddWithValue("@FECHA_MODIFICACION", aTarjetasModel.Fecha_modificacion == null ? (object)DBNull.Value : aTarjetasModel.Fecha_modificacion); command.Parameters.AddWithValue("@USUARIO_CREADOR", aTarjetasModel.Usuario_creador); command.Parameters.AddWithValue("@USUARIO_MODIFICADOR", aTarjetasModel.Usuario_modificador == null ? (object)DBNull.Value : aTarjetasModel.Usuario_modificador); command.Parameters.AddWithValue("@FECHA_CREACION", aTarjetasModel.Fecha_creacion); command.CommandType = CommandType.StoredProcedure; command.CommandText = "TarjetasModelUpdate"; int afectados = command.ExecuteNonQuery(); // Commit the transaction. sqlTran.Commit(); connection.Close(); connection.Dispose(); if (afectados > 0) { return(true); } else { return(false); } } } catch (Exception) { return(false); } }