-19 enero 2023

main
unknown 2 years ago
parent 82321d0cb9
commit a476780fef
  1. 41
      Controllers/DetallesController.cs
  2. 49
      Controllers/FacturaController.cs
  3. 19
      Interfaces/Csql.cs
  4. 127
      Repositorio/Repositoriooo.cs
  5. BIN
      bin/Debug/net6.0/MyFirstAPI.dll
  6. BIN
      bin/Debug/net6.0/MyFirstAPI.pdb
  7. 2
      obj/Debug/net6.0/MyFirstAPI.csproj.CoreCompileInputs.cache
  8. BIN
      obj/Debug/net6.0/MyFirstAPI.dll
  9. BIN
      obj/Debug/net6.0/MyFirstAPI.pdb
  10. BIN
      obj/Debug/net6.0/ref/MyFirstAPI.dll
  11. BIN
      obj/Debug/net6.0/refint/MyFirstAPI.dll

@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Components.Forms;
using System.ComponentModel;
using System.Security.Cryptography;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Formatters;
using MyFirstAPI.DATA;
@ -11,6 +13,7 @@ namespace MyFirstAPI.Controllers
[Route("Api/Detalles")]
public class DetallesController : ControllerBase
{
// crud para la tavla detalles
private readonly Repositoriooo repositoriooo;
public DetallesController()
{
@ -19,32 +22,38 @@ namespace MyFirstAPI.Controllers
}
//[HttpGet]
//public IEnumerable<Detalles> Get()
//{
// return repositoriooo.GetDetalles();
//}
//GET PARA LEER LA TABLA DETALLES
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult> Get()
{
return Ok(await repositoriooo.GetDetalles());
var lista = await repositoriooo.GetDetalles();
return Ok(lista.ToList());
}
// ENVIAR DATOS EN LA TABLA DETALLES
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Create(Detalles deta)
{
await repositoriooo.Create(deta);
return Ok();
}
//[HttpGet]
//public async Task<ActionResult<List<Detalles>>> Get()
//{
// var funcion = new Repositoriooo();
// var lista = await funcion.GetDetalles();
// return lista.ToList();
//}

@ -0,0 +1,49 @@
using Microsoft.AspNetCore.Mvc;
using MyFirstAPI.Models;
using MyFirstAPI.Repositorio;
namespace MyFirstAPI.Controllers
{
[ApiController]
[Route("Api/Factura")]
public class FacturaController : ControllerBase
{
// crud para la tabla factura
private readonly Repositoriooo repositoriooo;
public FacturaController()
{
repositoriooo = new Repositoriooo();
}
/// get para leer la tabla factura
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult> Getf()
{
return Ok(await repositoriooo.GetFactura());
}
// ENVIAR DATOS EN LA TABAL FACTURA
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Create(Factura fac)
{
await repositoriooo.CreateF(fac);
return Ok();
}
}
}

@ -12,24 +12,11 @@ namespace MyFirstAPI.Interfaces
public interface IConexionSql
{
//private string connectionsString = string.Empty;
//public string GetConnectionsString()
//{
// var contructor = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build();
// connectionsString = contructor.GetSection("ConnectionStrings:MyBaseDeDatos").Value;
// return connectionsString;
//}
Task<Detalles> GetDetalles();
Task<Detalles> GetDetalles();
Task<Factura> GetFactura();

@ -1,44 +1,22 @@
using System.Data;
using System.Text.Json.Serialization;
using System.Text.Json;
using Dapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.SqlClient;
using Microsoft.VisualBasic;
using MyFirstAPI.Interfaces;
using MyFirstAPI.Models;
using System.ComponentModel;
namespace MyFirstAPI.Repositorio
{
public class Repositoriooo
public class Repositoriooo : DateTimeConverter
{
SqlConexion cn = new SqlConexion();
//private string connectionsString = string.Empty;
//public void Repositorio(IConfiguration configuration)
//{
// //connectionsString = configuration.GetConnectionString("MyBaseDeDatos");
// var contructor = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build();
// connectionsString = contructor.GetSection("ConnectionStrings:MyBaseDeDatos").Value;
//}
//public IDbConnection connection
//{
// get
// {
// return new SqlConnection(connectionsString);
// }
//}
///Repositorio /
// dapper para leer detalles
public async Task<IEnumerable<Detalles>> GetDetalles()
{
using (var connection = new SqlConnection(cn.CadenaSQL()))
@ -51,24 +29,83 @@ namespace MyFirstAPI.Repositorio
}
}
// dapper para leer factura
public async Task<IEnumerable<Factura>> GetFactura()
{
using (var connection = new SqlConnection(cn.CadenaSQL()))
{
var sql = @"Select * from Factura";
var factura = await connection.QueryAsync<Factura>(sql);
return factura;
}
//public IEnumerable<Detalles> GetDetalles()
//{
// using (IDbConnection dbConnection = connection)
// {
// string sQuerry = @"select * from detalles ";
// dbConnection.Open();
// return dbConnection.Query<Detalles>(sQuerry);
// }
//}
}
/// METODO POST PARA ENVIAR DATOS EN DETALLES
public async Task Create (Detalles deta)
{
Detalles D = new Detalles();
var ProcedimientoalmacenadoInser = "SpInsert";
using (var connection = new SqlConnection(cn.CadenaSQL()))
{
var detalles = await connection.ExecuteAsync(ProcedimientoalmacenadoInser,
new
{
Idfactura = deta.IdFactura,
Nfactura = deta.Nfactura,
ArticuloNumber = deta.ArticuloNumber,
Articulo = deta.Articulo,
Cantidad = deta.Cantidad,
Precio = deta.Precio
}, commandType: CommandType.StoredProcedure);
//var sql = @"insert into Detalles( IdFactura , Nfactura , ArticuloNumber , Articulo , Cantidad, Precio)
// values ( @Idfactura , @Nfactura, @ArticuloNumber, @Articulo, @Cantidad, @Precio)
// update Detalles set TotalId = Cantidad * Precio from factura where IdFactura = Idf
// update FACTURA set Subtotal =(SELECT IIF(SUM(TotalId) IS NULL,0,SUM(TotalId) ) from Detalles where IdFactura = idf )
// update FACTURA set Total = ( SELECT IIF(SUM(TotalId) IS NULL ,0,SUM(TotalId + TotalID * 0.15 )) FROM Detalles WHERE IdFactura = Idf ) ";
}
}
public async Task CreateF(Factura fac)
{
Factura F = new Factura();
var ProcedimientoAlmacenadoInserFactura = "SpInsertarFactura";
using (var connection = new SqlConnection(cn.CadenaSQL()))
{
var Factura = await connection.ExecuteAsync(ProcedimientoAlmacenadoInserFactura,
new
{
Id = F.Idf,
Fecha = F.Fecha,
NumberFactura = F.NumberFactura,
MetodoPago = F.Metodopago,
Dirrecion = F.Dirreccion,
Empresa = F.Empresa,
Subtotal = F.Subtotal,
Total = F.Total,
Activo = F.Activo,
}, commandType: CommandType.StoredProcedure);
}
}
}
public class DateTimeConverter : JsonConverter<DateTime>
{
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
// You should do some fool proof parsing here
var s = reader.GetString();
s = s.Replace("/Date(", "").Replace(")/", "");
long epoch = Convert.ToInt64(s);
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(epoch);
return dateTimeOffset.UtcDateTime;
}
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
// Do some conversion here
}
}
}

Binary file not shown.

Binary file not shown.

@ -1 +1 @@
17f75dc6001f4f48e9565f9b6894a203b7f06f7d
c6dfb80b0039b072decc8c171abd1e494c782a76

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save