|
|
@ -1,44 +1,22 @@ |
|
|
|
using System.Data; |
|
|
|
using System.Data; |
|
|
|
|
|
|
|
using System.Text.Json.Serialization; |
|
|
|
|
|
|
|
using System.Text.Json; |
|
|
|
using Dapper; |
|
|
|
using Dapper; |
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.Data.SqlClient; |
|
|
|
using Microsoft.Data.SqlClient; |
|
|
|
using Microsoft.VisualBasic; |
|
|
|
using Microsoft.VisualBasic; |
|
|
|
using MyFirstAPI.Interfaces; |
|
|
|
using MyFirstAPI.Interfaces; |
|
|
|
using MyFirstAPI.Models; |
|
|
|
using MyFirstAPI.Models; |
|
|
|
|
|
|
|
using System.ComponentModel; |
|
|
|
|
|
|
|
|
|
|
|
namespace MyFirstAPI.Repositorio |
|
|
|
namespace MyFirstAPI.Repositorio |
|
|
|
{ |
|
|
|
{ |
|
|
|
public class Repositoriooo |
|
|
|
public class Repositoriooo : DateTimeConverter |
|
|
|
{ |
|
|
|
{ |
|
|
|
SqlConexion cn = new SqlConexion(); |
|
|
|
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() |
|
|
|
public async Task<IEnumerable<Detalles>> GetDetalles() |
|
|
|
{ |
|
|
|
{ |
|
|
|
using (var connection = new SqlConnection(cn.CadenaSQL())) |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// 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 IEnumerable<Detalles> GetDetalles() |
|
|
|
} |
|
|
|
//{ |
|
|
|
} |
|
|
|
// using (IDbConnection dbConnection = connection) |
|
|
|
|
|
|
|
// { |
|
|
|
|
|
|
|
// string sQuerry = @"select * from detalles "; |
|
|
|
|
|
|
|
// dbConnection.Open(); |
|
|
|
|
|
|
|
// return dbConnection.Query<Detalles>(sQuerry); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|