19 de enero 2023

main
unknown 2 years ago
parent a476780fef
commit 66aafcd7fd
  1. 31
      Controllers/DetallesController.cs
  2. 10
      Controllers/FacturaController.cs
  3. 2
      Models/Factura.cs
  4. 112
      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

@ -41,24 +41,37 @@ namespace MyFirstAPI.Controllers
// ENVIAR DATOS EN LA TABLA DETALLES
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Create(Detalles deta)
public async Task<IActionResult> 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<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,8 +40,18 @@ 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 DateTime Fecha { get; set; }
public DateTime Fecha = DateTime.Now;
public string? NumberFactura { get; set; }
public string? Metodopago { get; set; }
public string? Dirreccion { get; set; }

@ -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<DateTime>
{
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);
}
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save