public static int ActualizarJugueteId(Juguete juguete) { int resultado = 0; using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { SqlCommand sqlCommand = new SqlCommand(null, sqlConnection); sqlCommand.CommandText = "Update Juguete SET nombre = @nombre,marca = @marca, precioUnit=@precioUnit where id_juguete = @id_juguete"; sqlCommand.Parameters.AddWithValue("@nombre", juguete.nombre); sqlCommand.Parameters.AddWithValue("@marca", juguete.marca); sqlCommand.Parameters.AddWithValue("@precioUnit", juguete.precioUnit); sqlCommand.Parameters.AddWithValue("@id_juguete", juguete.id_juguete); try { sqlConnection.Open(); resultado = sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(resultado); }
public static int AgregarJuguete(Juguete juguete) { int filasAfectadas = 0; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand sqlCommand = new SqlCommand(null, connection); sqlCommand.CommandText = "Insert into Juguete (nombre,marca,precioUnit) values (@nombre,@marca,@precioUnit)"; sqlCommand.Parameters.AddWithValue("@nombre", juguete.nombre); sqlCommand.Parameters.AddWithValue("@marca", juguete.nombre); sqlCommand.Parameters.AddWithValue("@precioUnit", juguete.precioUnit); try { connection.Open(); filasAfectadas = sqlCommand.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(filasAfectadas); }
private void Button_Clicked(object sender, EventArgs e) { Juguete j = new Juguete(this.db); j.Nombre = txtNombre.Text; j.Tipo = txtTipo.Text; j.Precio = double.Parse(txtPrecio.Text); var res = j.Agregar(j).Result; if (res) { DisplayAlert( "Notificacion", "Se ha agregado el Juguete " + txtNombre.Text, "OK"); } else { DisplayAlert( "Notificacion", "No se pudo agregar", "OK"); } }
public ModalAccion(Juguete ju) { InitializeComponent(); oJ = ju; ruta = Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData), this.database); this.db = new DBContext(ruta); }
public IActionResult Post([FromBody] Juguete juguete) { try { var j = _jugueteRepository.Insert(juguete); return(Ok(j)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <ActionResult <Juguete> > Edit(int id, [Bind("Id,Nombre,Descripcion,RestriccionEdad,Compañia,Precio")] Juguete juguete) { if (id != juguete.Id) { return(NotFound()); } if (ModelState.IsValid) { juguete = await _servicio.Actualiza(juguete); } return(juguete); }
public ModalActualizar(Juguete ju) { this.oJ = ju; InitializeComponent(); ruta = Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData), this.database); this.db = new DBContext(ruta); IDJ = oJ.IdJuguete; txtNombre.Text = oJ.Nombre; txtPrecio.Text = oJ.Precio.ToString(); txtTipo.Text = oJ.Tipo; }
private static List <Juguete> LLenadoJuguete(DataTable dataTable) { juguetes = new List <Juguete>(); for (int i = 0; i < dataTable.Rows.Count; i++) { Juguete juguete = new Juguete(); juguete.id_juguete = int.Parse(dataTable.Rows[i]["id_juguete"].ToString()); juguete.nombre = dataTable.Rows[i]["nombre"].ToString(); juguete.marca = dataTable.Rows[i]["marca"].ToString(); juguete.precioUnit = int.Parse(dataTable.Rows[i]["precioUnit"].ToString()); juguetes.Add(juguete); } return(juguetes); }
public async Task <ActionResult <Juguete> > Create([Bind("Id,Nombre,Descripcion,RestriccionEdad,Compañia,Precio")] Juguete juguete) { if (ModelState.IsValid) { try { await _servicio.Agrega(juguete); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(juguete); }
private static Juguete CreacionJuguete(DataTable dataTable) { if (dataTable != null && dataTable.Rows.Count > 0) { Juguete juguete = new Juguete(); juguete.id_juguete = int.Parse(dataTable.Rows[0]["id_juguete"].ToString()); juguete.nombre = dataTable.Rows[0]["nombre"].ToString(); juguete.marca = dataTable.Rows[0]["marca"].ToString(); juguete.precioUnit = int.Parse(dataTable.Rows[0]["precioUnit"].ToString()); return(juguete); } else { return(null); } }
private async void btn_eliminar(object sender, EventArgs e) { var accion = await DisplayAlert( "Notificacion", "Desea eliminar este item", "Si", "No"); if (accion) { Juguete ju = new Juguete(this.db); await ju.Eliminar(oJ); await DisplayAlert( "Notificacion", "Se ha eliminado el item" + oJ.Nombre, "OK"); } else { await DisplayAlert( "Notificacion", "No se ha eliminado", "OK"); } }
public void TestAgregarPlanta() { //Arrange int resultadoEsperado = 1; int resultadoObtenido = 0; Juguete juguete = new Juguete(); juguete.nombre = "barbi"; juguete.marca = "matel"; juguete.precioUnit = 5000; //Act resultadoObtenido = JugueteAzure.AgregarJuguete(juguete); //Assert Assert.Equal(resultadoEsperado, resultadoObtenido); }
public void CargarLista() { Juguete j = new Juguete(this.db); this.oLista = new ObservableCollection <Juguete>(); var resultado = j.Query("SELECT * FROM [Juguete]").Result; if (!(resultado is null)) { foreach (var item in resultado) { oLista.Add(item); } } listadoJuguetes.ItemsSource = oLista; }
public IActionResult Put(int id, [FromBody] Juguete juguete) { try { if (id != juguete.id) { return(NotFound()); } _jugueteRepository.Update(juguete); return(Ok(new { message = $"El Juguete {juguete.Nombre} fue actualizado correctamente" })); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
private async void btn_actualizar(object sender, EventArgs e) { Juguete nj = new Juguete(this.db); nj.IdJuguete = IDJ; nj.Nombre = txtNombre.Text; nj.Tipo = txtTipo.Text; nj.Precio = double.Parse(txtPrecio.Text); var res = await nj.Actualizar(nj); if (res) { await DisplayAlert( "Notificacion", "Se ha actualizado el elemento", "OK"); } else { await DisplayAlert( "Notificacion", "No se pudo actualizar", "OK"); } }
public void TestActualizarPlantaPorId() { //Arrange int resultadoEsperado = 1; int resultadoObtenido = 0; Juguete juguete = new Juguete(); juguete.id_juguete = 1; juguete.nombre = "Melissa officinalis"; juguete.marca = "Toronjil"; juguete.precioUnit = 500; //Act resultadoObtenido = JugueteAzure.ActualizarJugueteId(juguete); juguete.nombre = "Melisa"; JugueteAzure.ActualizarJugueteId(juguete); //Assert Assert.Equal(resultadoEsperado, resultadoObtenido); }
public void TestEliminarJuguetePorID() { //Arrange Juguete juguete = new Juguete(); juguete.nombre = "ddd"; juguete.marca = "doo"; juguete.precioUnit = 52000; int IdJugueteEliminar = 2; int resultadoEsperado = 1; int resultadoObtenido = 0; JugueteAzure.AgregarJuguete(juguete); //Act resultadoObtenido = JugueteAzure.EliminarJugueteporId(IdJugueteEliminar); //Assert Assert.Equal(resultadoEsperado, resultadoObtenido); }
public Juguete Insert(Juguete juguete) { _context.Juguete.Add(juguete); _context.SaveChanges(); return(juguete); }
public async Task <IActionResult> ActualizaTarjeta(int id, Juguete juguete) { await _servicio.Actualiza(juguete); return(null); }
public Juguete Update(Juguete juguete) { _context.Entry(juguete).State = EntityState.Modified; _context.SaveChanges(); return(juguete); }