Ejemplo n.º 1
0
        /// <summary>
        /// Selects the Single object of TipoCambioModel table.
        /// </summary>
        public TipoCambioModel GetTipoCambioModel(int aID)
        {
            TipoCambioModel TipoCambioModel = null;

            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();

                    command.Parameters.AddWithValue("@ID", aID);


                    command.CommandType = CommandType.StoredProcedure;

                    command.CommandText = "TipoCambioModelSelect";

                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            int      ID                  = (int)(reader["ID"]);
                            DateTime Fecha               = (DateTime)(reader["Fecha"]);
                            int      MonedaOrigen        = (int)(reader["MonedaOrigen"]);
                            int      MonedaObjetivo      = (int)(reader["MonedaObjetivo"]);
                            decimal  MontoCompra         = (decimal)(reader["MontoCompra"]);
                            decimal  MontoVenta          = (decimal)(reader["MontoVenta"]);
                            string   USUARIO_CREADOR     = (string)(reader["USUARIO_CREADOR"]);
                            DateTime FECHA_CREACION      = (DateTime)(reader["FECHA_CREACION"]);
                            string   USUARIO_MODIFICADOR = (string)(reader["USUARIO_MODIFICADOR"]);
                            DateTime?FECHA_MODIFICACION  = reader["FECHA_MODIFICACION"] as DateTime?;

                            TipoCambioModel = new TipoCambioModel
                            {
                                Id                  = ID,
                                Fecha               = Fecha,
                                Monedaorigen        = MonedaOrigen,
                                Monedaobjetivo      = MonedaObjetivo,
                                Montocompra         = MontoCompra,
                                Montoventa          = MontoVenta,
                                Usuario_creador     = USUARIO_CREADOR,
                                Fecha_creacion      = FECHA_CREACION,
                                Usuario_modificador = USUARIO_MODIFICADOR,
                                Fecha_modificacion  = FECHA_MODIFICACION,
                            };
                        }
                    }
                }

                return(TipoCambioModel);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <TipoCambioModel> > Get(string moneda)
        {
            TipoCambioModel tipoCambio = new TipoCambioModel()
            {
                Moneda = "No definido",
                Precio = "N/A"
            };

            switch (moneda.ToLower())
            {
            case  nameof(CurrencyNameEnum.dolar):
                tipoCambio = await new Quote(new QuoteDolar()).GetCotizacion();
                break;

            case nameof(CurrencyNameEnum.euro):
                tipoCambio = await new Quote(new QuoteEuro()).GetCotizacion();
                break;

            case nameof(CurrencyNameEnum.real):
                tipoCambio = await new Quote(new QuoteReal()).GetCotizacion();
                break;

            default:
                break;
            }

            return(Ok(tipoCambio));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates a record to the TipoCambioModel table.
        /// returns True if value saved successfully else false
        /// Throw exception with message value EXISTS if the data is duplicate
        /// </summary>
        public bool Update(TipoCambioModel aTipoCambioModel)
        {
            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlTransaction sqlTran = connection.BeginTransaction();

                    SqlCommand command = connection.CreateCommand();

                    command.Transaction = sqlTran;

                    command.Parameters.AddWithValue("@ID", aTipoCambioModel.Id);
                    command.Parameters.AddWithValue("@Fecha", aTipoCambioModel.Fecha);
                    command.Parameters.AddWithValue("@MonedaOrigen", aTipoCambioModel.Monedaorigen);
                    command.Parameters.AddWithValue("@MonedaObjetivo", aTipoCambioModel.Monedaobjetivo);
                    command.Parameters.AddWithValue("@MontoCompra", aTipoCambioModel.Montocompra);
                    command.Parameters.AddWithValue("@MontoVenta", aTipoCambioModel.Montoventa);
                    command.Parameters.AddWithValue("@USUARIO_CREADOR", aTipoCambioModel.Usuario_creador);
                    command.Parameters.AddWithValue("@FECHA_CREACION", aTipoCambioModel.Fecha_creacion);
                    command.Parameters.AddWithValue("@USUARIO_MODIFICADOR", aTipoCambioModel.Usuario_modificador == null ? (object)DBNull.Value : aTipoCambioModel.Usuario_modificador);
                    command.Parameters.AddWithValue("@FECHA_MODIFICACION", aTipoCambioModel.Fecha_modificacion == null ? (object)DBNull.Value : aTipoCambioModel.Fecha_modificacion);


                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "TipoCambioModelUpdate";

                    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);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Selects the Single object of TipoCambioModel table.
        /// </summary>
        public TipoCambioModel GetTipoCambioModel(short aID)
        {
            TipoCambioModel TipoCambioModel = null;

            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();

                    command.Parameters.AddWithValue("@ID", aID);


                    command.CommandType = CommandType.StoredProcedure;

                    command.CommandText = "TipoCambioModelSelect";

                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            short    ID                  = (short)(reader["ID"]);
                            string   Nombre              = (string)(reader["Nombre"]);
                            DateTime FECHA_CREACION      = (DateTime)(reader["FECHA_CREACION"]);
                            DateTime?FECHA_MODIFICACION  = reader["FECHA_MODIFICACION"] as DateTime?;
                            string   USUARIO_CREADOR     = (string)(reader["USUARIO_CREADOR"]);
                            string   USUARIO_MODIFICADOR = (string)(reader["USUARIO_MODIFICADOR"]);

                            TipoCambioModel = new TipoCambioModel
                            {
                                Id = ID,
                                //Nombre = Nombre,
                                Fecha_creacion      = FECHA_CREACION,
                                Fecha_modificacion  = FECHA_MODIFICACION,
                                Usuario_creador     = USUARIO_CREADOR,
                                Usuario_modificador = USUARIO_MODIFICADOR,
                            };
                        }
                    }
                }

                return(TipoCambioModel);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// obtiene la cotizacion del dolar del repositorio
        /// </summary>
        /// <returns></returns>
        public async Task <TipoCambioModel> GetCotizacion()
        {
            TipoCambioModel tipoCambio = new TipoCambioModel();

            // obtengo del repositorio la cotizacion actual de la moneda en dolares
            QuoteModel cotizacionActual = await new ApiCambioToday().GetCotizacionActual(CurrencyCodeEnum.USD);

            bool statusOk = cotizacionActual.Status.Equals("OK");

            tipoCambio.Moneda = statusOk ? nameof(CurrencyNameEnum.dolar): "sin cotizacion";
            tipoCambio.Precio = statusOk ? cotizacionActual.Result.Amount: "S/N";

            return(tipoCambio);
        }
Ejemplo n.º 6
0
        private bool setItem()
        {
            try
            {
                m_tipocambio = new TipoCambioModel();

                if (this.tipoMoneda1.CboMoneda.SelectedValue != null)
                {
                    m_tipocambio.Monedaorigen = (int)this.tipoMoneda1.CboMoneda.SelectedValue;
                }
                else
                {
                    return(false);
                }

                if (this.tipoMoneda2.CboMoneda.SelectedValue != null)
                {
                    m_tipocambio.Monedaorigen = (int)this.tipoMoneda2.CboMoneda.SelectedValue;
                }
                else
                {
                    return(false);
                }

                if (!string.IsNullOrEmpty(this.monto1.TBMonto.Text.Trim()))
                {
                    m_tipocambio.Montocompra = Convert.ToDecimal(this.monto1.TBMonto.Text.Trim());
                }
                else
                {
                    return(false);
                }

                if (!string.IsNullOrEmpty(this.txtConversion.Text.Trim()))
                {
                    m_tipocambio.Montoventa = Convert.ToDecimal(this.txtConversion.Text.Trim());
                }
                else
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 7
0
        private void BTProceder_Click(object sender, EventArgs e)
        {
            int      id_moneda_origen  = (int)this.tipoMoneda1.CboMoneda.SelectedValue;
            int      id_moneda_destino = (int)this.tipoMoneda2.CboMoneda.SelectedValue;
            DateTime fecha_cambio      = fecha1.DtFecha.Value.Date;
            decimal  monto_compra      = Convert.ToDecimal(this.monto1.TBMonto.Text);
            decimal  monto_venta       = Convert.ToDecimal(this.conversion2.TBConversion.Text);

            if (id_moneda_origen == id_moneda_destino)
            {
                MessageBox.Show("no tiene sentido esa conversion");
                return;
            }

            this.gTipoCambioModel = new TipoCambioModel()
            {
                Montocompra     = monto_compra,
                Montoventa      = monto_venta,
                Usuario_creador = this.gUsuario,
                Fecha           = fecha_cambio.Date,
                Monedaorigen    = id_moneda_origen,
                Monedaobjetivo  = id_moneda_destino,
            };
        }