19 de enero 2023

main
unknown 2 years ago
parent a476780fef
commit 66aafcd7fd
  1. 25
      Controllers/DetallesController.cs
  2. 10
      Controllers/FacturaController.cs
  3. 2
      Models/Factura.cs
  4. 110
      Repositorio/Repositoriooo.cs
  5. BIN
      bin/Debug/net6.0/MyFirstAPI.dll
  6. BIN
      bin/Debug/net6.0/MyFirstAPI.pdb
  7. BIN
      obj/Debug/net6.0/MyFirstAPI.dll
  8. BIN
      obj/Debug/net6.0/MyFirstAPI.pdb
  9. BIN
      obj/Debug/net6.0/ref/MyFirstAPI.dll
  10. BIN
      obj/Debug/net6.0/refint/MyFirstAPI.dll

@ -44,21 +44,34 @@ namespace MyFirstAPI.Controllers
public async Task<IActionResult> Create(Detalles deta) public async Task<IActionResult> Create(Detalles deta)
{ {
await repositoriooo.Create(deta); await repositoriooo.Create(deta);
return Ok(); return Ok();
} }
// ACTUALIZAR DATOS EN LA TABLA DETALLES
[HttpPut]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> 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<IActionResult> Delete( int id )
{
await repositoriooo.Delete(id );
return Ok();
}
}
}
} }

@ -40,6 +40,16 @@ namespace MyFirstAPI.Controllers
} }
// ACTUALIZAR DATOS EN LA TABLA Factura
[HttpPut]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Put(Factura fac)
{
await repositoriooo.UpdateF(fac);
return Ok();
}

@ -85,7 +85,7 @@
public int Idf { get; set; } public int Idf { get; set; }
public DateTime Fecha { get; set; } public DateTime Fecha = DateTime.Now;
public string? NumberFactura { get; set; } public string? NumberFactura { get; set; }
public string? Metodopago { get; set; } public string? Metodopago { get; set; }
public string? Dirreccion { get; set; } public string? Dirreccion { get; set; }

@ -8,6 +8,7 @@ using Microsoft.VisualBasic;
using MyFirstAPI.Interfaces; using MyFirstAPI.Interfaces;
using MyFirstAPI.Models; using MyFirstAPI.Models;
using System.ComponentModel; using System.ComponentModel;
using System.Security.Cryptography.X509Certificates;
namespace MyFirstAPI.Repositorio namespace MyFirstAPI.Repositorio
{ {
@ -44,7 +45,7 @@ namespace MyFirstAPI.Repositorio
/// METODO POST PARA ENVIAR DATOS EN DETALLES /// METODO POST PARA ENVIAR DATOS EN DETALLES
public async Task Create (Detalles deta) public async Task Create (Detalles deta)
{ {
Detalles D = new Detalles(); //Detalles D = new Detalles();
var ProcedimientoalmacenadoInser = "SpInsert"; var ProcedimientoalmacenadoInser = "SpInsert";
using (var connection = new SqlConnection(cn.CadenaSQL())) using (var connection = new SqlConnection(cn.CadenaSQL()))
{ {
@ -58,54 +59,105 @@ namespace MyFirstAPI.Repositorio
Cantidad = deta.Cantidad, Cantidad = deta.Cantidad,
Precio = deta.Precio Precio = deta.Precio
}, commandType: CommandType.StoredProcedure); }, 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) public async Task CreateF(Factura fac)
{ {
Factura F = new Factura();
var ProcedimientoAlmacenadoInserFactura = "SpInsertarFactura"; var ProcedimientoAlmacenadoInserFactura = "SpInsertarFactura";
using (var connection = new SqlConnection(cn.CadenaSQL())) using (var connection = new SqlConnection(cn.CadenaSQL()))
{ {
var Factura = await connection.ExecuteAsync(ProcedimientoAlmacenadoInserFactura, var Factura = await connection.ExecuteAsync(ProcedimientoAlmacenadoInserFactura,
new new
{ {
Id = F.Idf, Fecha = fac.Fecha,
Fecha = F.Fecha, NumberFactura = fac.NumberFactura,
NumberFactura = F.NumberFactura, MetodoPago = fac.Metodopago,
MetodoPago = F.Metodopago, Dirrecion = fac.Dirreccion,
Dirrecion = F.Dirreccion, Empresa = fac.Empresa,
Empresa = F.Empresa, Subtotal = fac.Subtotal,
Subtotal = F.Subtotal, Total = fac.Total,
Total = F.Total,
Activo = F.Activo,
}, commandType: CommandType.StoredProcedure); }, commandType: CommandType.StoredProcedure);
} }
} }
}
public class DateTimeConverter : JsonConverter<DateTime>
{ //METODO PARA ACTUALIZAR DETALLES
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
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);
}
}
//Metodo Para Actualizar Factura
public async Task UpdateF (Factura fac)
{ {
// You should do some fool proof parsing here var ProcedimientoAlmacendadoUpdateF = "SpUpdateFactura";
var s = reader.GetString(); using (var connection = new SqlConnection(cn.CadenaSQL()))
s = s.Replace("/Date(", "").Replace(")/", ""); {
long epoch = Convert.ToInt64(s); var Factura = await connection.ExecuteAsync(ProcedimientoAlmacendadoUpdateF,
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(epoch); new
return dateTimeOffset.UtcDateTime; {
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);
}
} }
} }
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save