public async Task <IActionResult> FinalizarVenta([FromBody] VentaVM VentaVM)
        {
            try
            {
                var resultado = await _VentasServices.FinalizarVenta(VentaVM);

                return(Ok(resultado));
            }
            catch (Exception ex)
            {
                var mensaje = ex.Message.ToString();
                return(BadRequest());
            }
        }
Exemplo n.º 2
0
        public async Task <ResultViewModel> FinalizarVenta(VentaVM ventaVM)
        {
            using (var Conexion = new SqlConnection(Helpers.ContextConfiguration.ConexionString))
            {
                //var resultado = new FacturasAlmacenVM() { Exito = false, Mensaje = "Existe un error en Servidor" };
                try
                {
                    var resultado = new ResultViewModel();
                    var comando   = new SqlCommand();
                    comando.Connection  = Conexion;
                    comando.CommandText = "[Almacen].[Ventas]";
                    comando.CommandType = System.Data.CommandType.StoredProcedure;
                    /*Agregando los parametros*/
                    comando.Parameters.AddWithValue("@Opcion", "FinalizarVenta");
                    comando.Parameters.AddWithValue("@IdVenta", ventaVM.IdVenta);
                    comando.Parameters.AddWithValue("@TotalaPagar", ventaVM.TotalAPagar);
                    comando.Parameters.AddWithValue("@PagarCon", ventaVM.PagarCon);
                    comando.Parameters.AddWithValue("@Descuento", ventaVM.Descuento);
                    comando.Parameters.AddWithValue("@FechaVenta", ventaVM.Fecha);

                    Conexion.Open();
                    var Lectura = await comando.ExecuteReaderAsync();

                    if (Lectura.HasRows)
                    {
                        while (Lectura.Read())
                        {
                            resultado.Exito   = Lectura.GetBoolean(0);
                            resultado.Mensaje = Lectura.GetString(1);
                        }
                    }
                    Conexion.Close();
                    return(resultado);
                }
                catch (Exception e)
                {
                    var m = e.Message.ToString();
                    throw e;
                }
            }
        }