Esempio n. 1
0
        public void Create(ReservasDTO reservas)
        {
            //Genero el siguiente ID de reservas
            int id = DAOHelper.GetNextId("Reservas");
            //.ToString("yyyy-MM-dd HH:mm:ss")

            string SQL_Nuevareserva = "insert into Reservas values (" + id + ", " + reservas.IdCancha + ", '" + reservas.FechaHora + "' , " + reservas.IdUsuario + ", " + reservas.Precio + ", '" + reservas.Estado + "', " + reservas.IdCanchasHorario + ")";


            using (SqlConnection con = new SqlConnection())
            {
                con.ConnectionString = connectionString;
                con.Open();

                using (SqlCommand cmd = new SqlCommand(SQL_Nuevareserva, con))
                {
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
            }

            //SqlConnection con = new SqlConnection();
            //con.ConnectionString = connectionString;
            //con.Open();
            //SqlCommand cmd = new SqlCommand(SQL_Nuevareserva, con);
            //cmd.ExecuteNonQuery();
            //con.Close();
        }
Esempio n. 2
0
        public static ReservasDTO Create(ReservasDTO reserva)
        {
            using (SqlConnection con = new SqlConnection(DAOHelper.connectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    if (con.State != ConnectionState.Open)
                    {
                        con.Open();
                    }

                    cmd.Connection  = con;
                    cmd.CommandText = "INSERT INTO Reservas (Id, IdCancha, FechaHora, IdUsuario, Precio, Estado) VALUES ([id], [idCancha], '[fechaHora]', 1, [precio], 'CONFIRMADO')";

                    int id = DAOHelper.GetNextId("Reservas");
                    cmd.CommandText = cmd.CommandText.Replace("[id]", id.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[idCancha]", reserva.IdCancha.ToString());
                    cmd.CommandText = cmd.CommandText.Replace("[fechaHora]", reserva.FechaHora.ToString("yyyy-MM-dd HH:mm:ss"));
                    cmd.CommandText = cmd.CommandText.Replace("[precio]", reserva.Precio.ToString(System.Globalization.CultureInfo.InvariantCulture));

                    cmd.ExecuteNonQuery();

                    reserva.Id = id;
                    return(reserva);
                }
            }
        }