Example #1
0
        public override void Create(Torre entity)
        {
            int columnasAfectadas = 0;

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    Madera bufferMaderaPrincipal = entity.MaderaPrincipal;
                    Madera bufferMaderaColumna   = entity.MaderaColumna;
                    Tela   bufferTelaPrincipal   = entity.TelaProducto;


                    maderasRepo.Create(bufferMaderaPrincipal);
                    bufferMaderaPrincipal = maderasRepo.GetById(maderasRepo.GetMaxId());
                    maderasRepo.Create(bufferMaderaColumna);
                    bufferMaderaColumna = maderasRepo.GetById(maderasRepo.GetMaxId());
                    telasRepo.Create(bufferTelaPrincipal);
                    bufferTelaPrincipal = telasRepo.GetById(telasRepo.GetMaxId());

                    connection.Open();

                    SqlCommand command = new SqlCommand();
                    command.CommandType = System.Data.CommandType.Text;
                    command.Connection  = connection;

                    command.CommandText = $"INSERT INTO [{table}] ([estadoProducto], [idMaderaPrincipal], [idTelaProducto], [idMaderaColumna], [metrosYute], [modelo], [yuteInstalado])" + "Values (@estadoProducto, @idMaderaPrincipal, @idTelaProducto, @idMaderaColumna, @metrosYute, @modelo, @YuteInstalado)";
                    command.Parameters.AddWithValue("@estadoProducto", entity.EstadoProducto);
                    command.Parameters.AddWithValue("@idMaderaPrincipal", bufferMaderaPrincipal.Id);
                    command.Parameters.AddWithValue("@idTelaProducto", bufferTelaPrincipal.Id);
                    command.Parameters.AddWithValue("@idMaderaColumna", bufferMaderaColumna.Id);
                    command.Parameters.AddWithValue("@metrosYute", entity.MetrosYute);
                    command.Parameters.AddWithValue("@modelo", entity.Modelo);
                    command.Parameters.AddWithValue("@yuteInstalado", entity.YuteInstalado);
                    columnasAfectadas = command.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                throw new Exception();
            }
        }
Example #2
0
        /// <summary>
        /// Inserta en la BD un Producto del tipo Estante
        /// </summary>
        /// <param name="entity"></param>
        public override void Create(Estante entity)
        {
            int columnasAfectadas = 0;

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    Madera bufferMaderaPrincipal = entity.MaderaPrincipal;
                    Tela   bufferTelaPrincipal   = entity.TelaProducto;

                    maderasRepo.Create(bufferMaderaPrincipal);
                    telasRepo.Create(bufferTelaPrincipal);

                    bufferMaderaPrincipal = maderasRepo.GetById(maderasRepo.GetMaxId());
                    bufferTelaPrincipal   = telasRepo.GetById(telasRepo.GetMaxId());

                    connection.Open();

                    SqlCommand command = new SqlCommand();
                    command.CommandType = System.Data.CommandType.Text;
                    command.Connection  = connection;

                    command.CommandText = $"INSERT INTO [{table}] ([estadoProducto], [idMaderaProducto], [idTelaProducto], [cantidadEstantes])" + "Values (@estadoProducto, @idMaderaProducto, @idTelaProducto, @cantidadEstantes)";
                    command.Parameters.AddWithValue("@estadoProducto", entity.EstadoProducto);
                    command.Parameters.AddWithValue("@idMaderaProducto", bufferMaderaPrincipal.Id);
                    command.Parameters.AddWithValue("@idTelaProducto", bufferTelaPrincipal.Id);
                    command.Parameters.AddWithValue("@cantidadEstantes", entity.CantidadEstantes);
                    columnasAfectadas = command.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                throw new Exception();
            }
        }