Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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");
            }
        }
Esempio n. 4
0
        public ModalAccion(Juguete ju)
        {
            InitializeComponent();
            oJ = ju;

            ruta = Path.Combine(Environment.GetFolderPath
                                    (Environment.SpecialFolder.LocalApplicationData),
                                this.database);
            this.db = new DBContext(ruta);
        }
Esempio n. 5
0
 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;
        }
Esempio n. 8
0
 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);
 }
Esempio n. 10
0
 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);
     }
 }
Esempio n. 11
0
        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");
            }
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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;
        }
Esempio n. 14
0
        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");
            }
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
 public Juguete Insert(Juguete juguete)
 {
     _context.Juguete.Add(juguete);
     _context.SaveChanges();
     return(juguete);
 }
Esempio n. 19
0
        public async Task <IActionResult> ActualizaTarjeta(int id, Juguete juguete)
        {
            await _servicio.Actualiza(juguete);

            return(null);
        }
Esempio n. 20
0
 public Juguete Update(Juguete juguete)
 {
     _context.Entry(juguete).State = EntityState.Modified;
     _context.SaveChanges();
     return(juguete);
 }