public IActionResult Guardar(CompraViewModel compra)
        {
            using (var transaction = _dbContext.Database.BeginTransaction())
            {
                try
                {
                    Comprar comprar = new Comprar {
                        UsuarioId = "x", Total = compra.Total
                    };

                    _dbContext.Add(comprar);
                    _dbContext.SaveChanges();

                    foreach (Producto item in compra.Productos)
                    {
                        ComprarProducto comprarProducto = new ComprarProducto
                        {
                            ProductoId = item.ProductoId,
                            ComprarId  = comprar.CompraId
                        };
                        _dbContext.Add(comprarProducto);
                    }
                    _dbContext.SaveChanges();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                }
            }
            return(RedirectToAction());
        }
        private void SpImg_MouseDown(object sender, MouseButtonEventArgs e)
        {
            ComprarProducto cp = new ComprarProducto();

            this.Close();
            cp.Show();
        }
Пример #3
0
        private void pictureBox5_Click(object sender, EventArgs e)
        {
            ComprarProductoService service         = new ComprarProductoService();
            ComprarProducto        comprarProducto = MapearCompra();
            string mensaje = service.Guardar(comprarProducto);

            MessageBox.Show(mensaje, "MENSAJE DE GUARDADO", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
        }
Пример #4
0
 private ComprarProducto MapearCompra()
 {
     comprarProducto                    = new ComprarProducto();
     comprarProducto.Cantidad           = int.Parse(TxtCantidad.Text);
     comprarProducto.CodigoCompra       = TxtCodigoCompra.Text;
     comprarProducto.CodigoProducto     = TxtCodigoProducto.Text;
     comprarProducto.CodigoProveedor    = TxtCodigoProveedor.Text;
     comprarProducto.FechaCompra        = DtaFechaRegistro.Value.Date;
     comprarProducto.NombreProducto     = TxtNombreProducto.Text;
     comprarProducto.PrecioCompra       = float.Parse(TxtPrecioCompra.Text);
     comprarProducto.Proveedor          = TxtProveedor.Text;
     comprarProducto.PorcentajeGanancia = float.Parse(TxtPorcentajeGanancia.Text);
     return(comprarProducto);
 }
Пример #5
0
 public string Guardar(ComprarProducto comprarProducto)
 {
     try
     {
         connection.Open();
         repositorio.Guardar(comprarProducto);
         return("SE GUARDO CORRECTAMENTE");
     }
     catch (Exception ex)
     {
         return(" ERROR EN LOS DATOS: " + ex.Message);
     }
     finally
     {
         connection.Close();
     }
 }
 public void Guardar(ComprarProducto producto)
 {
     using (var command = connection.CreateCommand())
     {
         command.CommandText = "INSERT INTO ComprarProducto (CodigoCompra, CodigoProducto, NombreProducto, FechaCompra, Proveedor, CodigoProveedor, TotalCompra, TotalVenta, Ganancia, Cantidad, PrecioCompra, PrecioVenta, PorcentajeGanancia) VALUES (@CodigoCompra, @CodigoProducto, @NombreProducto, @FechaCompra, @Proveedor, @CodigoProveedor, @TotalCompra, @TotalVenta, @Ganancia, @Cantidad, @PrecioCompra, @PrecioVenta, @PorcentajeGanancia)";
         command.Parameters.AddWithValue("@CodigoCompra", producto.CodigoCompra);
         command.Parameters.AddWithValue("@CodigoProducto", producto.CodigoProducto);
         command.Parameters.AddWithValue("@NombreProducto", producto.NombreProducto);
         command.Parameters.AddWithValue("@FechaCompra", producto.FechaCompra);
         command.Parameters.AddWithValue("@Proveedor", producto.Proveedor);
         command.Parameters.AddWithValue("@CodigoProveedor", producto.CodigoProveedor);
         command.Parameters.AddWithValue("@TotalCompra", producto.totalPrecioCompra);
         command.Parameters.AddWithValue("@TotalVenta", producto.totalPrecioVenta);
         command.Parameters.AddWithValue("@Ganancia", producto.gananciaTotal);
         command.Parameters.AddWithValue("@Cantidad", producto.Cantidad);
         command.Parameters.AddWithValue("@PrecioCompra", producto.PrecioCompra);
         command.Parameters.AddWithValue("@PrecioVenta", producto.PrecioVenta);
         command.Parameters.AddWithValue("@PorcentajeGanancia", producto.PorcentajeGanancia);
         command.ExecuteNonQuery();
     }
 }