diff --git a/Controllers/DetallesController.cs b/Controllers/DetallesController.cs index b55a1ac..f088ff6 100644 --- a/Controllers/DetallesController.cs +++ b/Controllers/DetallesController.cs @@ -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 Get() - //{ - - // return repositoriooo.GetDetalles(); - //} - + //GET PARA LEER LA TABLA DETALLES [HttpGet] [ProducesResponseType(StatusCodes.Status200OK)] public async Task 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 Create(Detalles deta) + { + + await repositoriooo.Create(deta); + return Ok(); + } - //[HttpGet] - //public async Task>> Get() - //{ - // var funcion = new Repositoriooo(); - // var lista = await funcion.GetDetalles(); - // return lista.ToList(); - //} + + + diff --git a/Controllers/FacturaController.cs b/Controllers/FacturaController.cs new file mode 100644 index 0000000..733dd52 --- /dev/null +++ b/Controllers/FacturaController.cs @@ -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 Getf() + { + return Ok(await repositoriooo.GetFactura()); + + } + + // ENVIAR DATOS EN LA TABAL FACTURA + [HttpPost] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task Create(Factura fac) + { + + await repositoriooo.CreateF(fac); + return Ok(); + + } + + + + + + + } +} diff --git a/Interfaces/Csql.cs b/Interfaces/Csql.cs index 89a4c11..0e60310 100644 --- a/Interfaces/Csql.cs +++ b/Interfaces/Csql.cs @@ -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 GetDetalles(); + + Task GetDetalles(); + Task GetFactura(); diff --git a/Repositorio/Repositoriooo.cs b/Repositorio/Repositoriooo.cs index 24c5476..a61b300 100644 --- a/Repositorio/Repositoriooo.cs +++ b/Repositorio/Repositoriooo.cs @@ -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> GetDetalles() { using (var connection = new SqlConnection(cn.CadenaSQL())) @@ -51,24 +29,83 @@ namespace MyFirstAPI.Repositorio } } + // dapper para leer factura + public async Task> GetFactura() + { + using (var connection = new SqlConnection(cn.CadenaSQL())) + { + var sql = @"Select * from Factura"; + var factura = await connection.QueryAsync(sql); + return factura; + } - - //public IEnumerable GetDetalles() - //{ - // using (IDbConnection dbConnection = connection) - // { - // string sQuerry = @"select * from detalles "; - // dbConnection.Open(); - // return dbConnection.Query(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 + { + 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 + } + } + } diff --git a/bin/Debug/net6.0/MyFirstAPI.dll b/bin/Debug/net6.0/MyFirstAPI.dll index a49f968..474d2f2 100644 Binary files a/bin/Debug/net6.0/MyFirstAPI.dll and b/bin/Debug/net6.0/MyFirstAPI.dll differ diff --git a/bin/Debug/net6.0/MyFirstAPI.pdb b/bin/Debug/net6.0/MyFirstAPI.pdb index 7715acb..e28c667 100644 Binary files a/bin/Debug/net6.0/MyFirstAPI.pdb and b/bin/Debug/net6.0/MyFirstAPI.pdb differ diff --git a/obj/Debug/net6.0/MyFirstAPI.csproj.CoreCompileInputs.cache b/obj/Debug/net6.0/MyFirstAPI.csproj.CoreCompileInputs.cache index 6410470..df13908 100644 --- a/obj/Debug/net6.0/MyFirstAPI.csproj.CoreCompileInputs.cache +++ b/obj/Debug/net6.0/MyFirstAPI.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -17f75dc6001f4f48e9565f9b6894a203b7f06f7d +c6dfb80b0039b072decc8c171abd1e494c782a76 diff --git a/obj/Debug/net6.0/MyFirstAPI.dll b/obj/Debug/net6.0/MyFirstAPI.dll index a49f968..474d2f2 100644 Binary files a/obj/Debug/net6.0/MyFirstAPI.dll and b/obj/Debug/net6.0/MyFirstAPI.dll differ diff --git a/obj/Debug/net6.0/MyFirstAPI.pdb b/obj/Debug/net6.0/MyFirstAPI.pdb index 7715acb..e28c667 100644 Binary files a/obj/Debug/net6.0/MyFirstAPI.pdb and b/obj/Debug/net6.0/MyFirstAPI.pdb differ diff --git a/obj/Debug/net6.0/ref/MyFirstAPI.dll b/obj/Debug/net6.0/ref/MyFirstAPI.dll index 56ff375..c4b9cd9 100644 Binary files a/obj/Debug/net6.0/ref/MyFirstAPI.dll and b/obj/Debug/net6.0/ref/MyFirstAPI.dll differ diff --git a/obj/Debug/net6.0/refint/MyFirstAPI.dll b/obj/Debug/net6.0/refint/MyFirstAPI.dll index 56ff375..c4b9cd9 100644 Binary files a/obj/Debug/net6.0/refint/MyFirstAPI.dll and b/obj/Debug/net6.0/refint/MyFirstAPI.dll differ