diff --git a/Controllers/DetallesController.cs b/Controllers/DetallesController.cs index f088ff6..987fe4d 100644 --- a/Controllers/DetallesController.cs +++ b/Controllers/DetallesController.cs @@ -41,24 +41,37 @@ namespace MyFirstAPI.Controllers // ENVIAR DATOS EN LA TABLA DETALLES [HttpPost] [ProducesResponseType(StatusCodes.Status200OK)] - public async Task Create(Detalles deta) + public async Task Create(Detalles deta) { - await repositoriooo.Create(deta); - return Ok(); - - } - - - + await repositoriooo.Create(deta); + return Ok(); + } + // ACTUALIZAR DATOS EN LA TABLA DETALLES + [HttpPut] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task Put(Detalles deta) + { + await repositoriooo.UPDATED(deta); + return Ok(); + } + // Elimar datos de la tabla detalles + [HttpDelete] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public async Task Delete( int id ) + { + await repositoriooo.Delete(id ); + return Ok(); - } + } + } } diff --git a/Controllers/FacturaController.cs b/Controllers/FacturaController.cs index 733dd52..4fb175e 100644 --- a/Controllers/FacturaController.cs +++ b/Controllers/FacturaController.cs @@ -40,8 +40,18 @@ namespace MyFirstAPI.Controllers } + // ACTUALIZAR DATOS EN LA TABLA Factura + [HttpPut] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task Put(Factura fac) + { + await repositoriooo.UpdateF(fac); + return Ok(); + + } + diff --git a/Models/Factura.cs b/Models/Factura.cs index b66adb0..9a066a9 100644 --- a/Models/Factura.cs +++ b/Models/Factura.cs @@ -85,7 +85,7 @@ public int Idf { get; set; } - public DateTime Fecha { get; set; } + public DateTime Fecha = DateTime.Now; public string? NumberFactura { get; set; } public string? Metodopago { get; set; } public string? Dirreccion { get; set; } diff --git a/Repositorio/Repositoriooo.cs b/Repositorio/Repositoriooo.cs index a61b300..67b06c0 100644 --- a/Repositorio/Repositoriooo.cs +++ b/Repositorio/Repositoriooo.cs @@ -8,6 +8,7 @@ using Microsoft.VisualBasic; using MyFirstAPI.Interfaces; using MyFirstAPI.Models; using System.ComponentModel; +using System.Security.Cryptography.X509Certificates; namespace MyFirstAPI.Repositorio { @@ -44,7 +45,7 @@ namespace MyFirstAPI.Repositorio /// METODO POST PARA ENVIAR DATOS EN DETALLES public async Task Create (Detalles deta) { - Detalles D = new Detalles(); + //Detalles D = new Detalles(); var ProcedimientoalmacenadoInser = "SpInsert"; using (var connection = new SqlConnection(cn.CadenaSQL())) { @@ -58,54 +59,105 @@ namespace MyFirstAPI.Repositorio 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 ) "; - + } } + // METODO PARA ENVIAR FACTURA 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, + Fecha = fac.Fecha, + NumberFactura = fac.NumberFactura, + MetodoPago = fac.Metodopago, + Dirrecion = fac.Dirreccion, + Empresa = fac.Empresa, + Subtotal = fac.Subtotal, + Total = fac.Total, + + }, commandType: CommandType.StoredProcedure); + } + } - }, commandType: CommandType.StoredProcedure); + //METODO PARA ACTUALIZAR DETALLES + + public async Task UPDATED (Detalles deta) + { + var ProcedimientoAlmacenadoUpdate = "SpUpdateDetalles"; + using (var connection = new SqlConnection(cn.CadenaSQL())) + { + var Detalles = await connection.ExecuteAsync(ProcedimientoAlmacenadoUpdate, new + { + Idfactura = deta.IdFactura, + Nfactura = deta.Nfactura, + ArticuloNumber = deta.ArticuloNumber, + Articulo = deta.Articulo, + Cantidad = deta.Cantidad, + Precio = deta.Precio, + Total =deta.TotalId + + }, commandType: CommandType.StoredProcedure); + } } - } - public class DateTimeConverter : JsonConverter - { - public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + + + + //Metodo Para Actualizar Factura + public async Task UpdateF (Factura fac) { - // 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; + var ProcedimientoAlmacendadoUpdateF = "SpUpdateFactura"; + using (var connection = new SqlConnection(cn.CadenaSQL())) + { + var Factura = await connection.ExecuteAsync(ProcedimientoAlmacendadoUpdateF, + new + { + Fecha = fac.Fecha, + NumberFactura = fac.NumberFactura, + MetodoPago = fac.Metodopago, + Dirrecion = fac.Dirreccion, + Empresa = fac.Empresa, + Subtotal = fac.Subtotal, + TotalF = fac.Total + + }, commandType: CommandType.StoredProcedure); + + } + } - public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) + + + + // METODO PARA ELIMINAR DETALLES + + public async Task Delete (int id) { - // Do some conversion here + + var ProcedimientoAlmacenadoDelete = "SpEliminarDetalles"; + using (var connection = new SqlConnection(cn.CadenaSQL())) + { + var detalles = await connection.ExecuteAsync(ProcedimientoAlmacenadoDelete , + + new { ArticuloNumber = id }, + commandType: CommandType.StoredProcedure); + + + + } + } + + + + } + } diff --git a/bin/Debug/net6.0/MyFirstAPI.dll b/bin/Debug/net6.0/MyFirstAPI.dll index 474d2f2..96c6759 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 e28c667..d3ea371 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.dll b/obj/Debug/net6.0/MyFirstAPI.dll index 474d2f2..96c6759 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 e28c667..d3ea371 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 c4b9cd9..3fdaa90 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 c4b9cd9..3fdaa90 100644 Binary files a/obj/Debug/net6.0/refint/MyFirstAPI.dll and b/obj/Debug/net6.0/refint/MyFirstAPI.dll differ