public async Task <Declaracion> Get(Gestion gestion, int funcionarioID) { using (IDbConnection db = new SqlConnection(connectionString)) { string declaracionSQL = "SELECT * FROM Declaraciones WHERE Gestion = @Anio AND FuncionarioID = @funcionarioID Order by FechaActualización DESC"; Entities.DeclaracionPatrimonial declaracion = await db .QueryFirstOrDefaultAsync <Entities.DeclaracionPatrimonial>(declaracionSQL, new { gestion.Anio, funcionarioID }); if (declaracion == null) { return(null); } var declaracionID = declaracion.ID; DepositoCollection depositosCollection = await ReadDepositoCollection(declaracionID, db); DeudaBancariaCollection deudasCollection = await ReadDeudasCollection(declaracionID, db); InmuebleCollection inmueblesCollection = await ReadInmueblesCollection(declaracionID, db); OtroIngresoCollection otrosIngresosCollection = await ReadOtrosIngresosCollection(declaracionID, db); ValorNegociableCollection valoresNegociablesCollection = await ReadValoresNegociablesCollection(declaracionID, db); VehiculoCollection vehiculosCollection = await ReadVehiculosCollection(declaracionID, db); Declaracion result = Declaracion.Load(declaracion.ID, declaracion.FuncionarioID, gestion, declaracion.FechaLlenado, (EstadoDeclaracion)Enum.Parse(typeof(EstadoDeclaracion), declaracion.Estado), depositosCollection, deudasCollection, inmueblesCollection, otrosIngresosCollection, valoresNegociablesCollection, vehiculosCollection, null); return(result); } }
public async Task <Declaracion> Get(Guid declaracionID, bool loadDeclaracionAnterior = false) { using (IDbConnection db = new SqlConnection(connectionString)) { string declaracionSQL = "SELECT * FROM Declaraciones WHERE ID = @declaracionID"; var declaracion = await db .QueryFirstOrDefaultAsync <Entities.DeclaracionPatrimonial>(declaracionSQL, new { declaracionID }); if (declaracion == null) { return(null); } var gestion = await db.QueryFirstOrDefaultAsync <Entities.GestionSchema>("SELECT * FROM Gestiones WHERE Gestion = @gestion", new { declaracion.Gestion }); DepositoCollection depositosCollection = await ReadDepositoCollection(declaracionID, db); DeudaBancariaCollection deudasCollection = await ReadDeudasCollection(declaracionID, db); InmuebleCollection inmueblesCollection = await ReadInmueblesCollection(declaracionID, db); OtroIngresoCollection otrosIngresosCollection = await ReadOtrosIngresosCollection(declaracionID, db); ValorNegociableCollection valoresNegociablesCollection = await ReadValoresNegociablesCollection(declaracionID, db); VehiculoCollection vehiculosCollection = await ReadVehiculosCollection(declaracionID, db); Declaracion declaracionAnterior = null; if (loadDeclaracionAnterior && declaracion.DeclaracionAnteriorID != Guid.Empty) { var declaracionAnteriorID = declaracion.DeclaracionAnteriorID; DepositoCollection depositosAnteriorCollection = await ReadDepositoCollection(declaracionAnteriorID, db); DeudaBancariaCollection deudasAnteriorCollection = await ReadDeudasCollection(declaracionAnteriorID, db); InmuebleCollection inmueblesAnteriorCollection = await ReadInmueblesCollection(declaracionAnteriorID, db); OtroIngresoCollection otrosAnteriorIngresosCollection = await ReadOtrosIngresosCollection(declaracionAnteriorID, db); ValorNegociableCollection valoresAnteriorNegociablesCollection = await ReadValoresNegociablesCollection(declaracionAnteriorID, db); VehiculoCollection vehiculosAnteriorCollection = await ReadVehiculosCollection(declaracionAnteriorID, db); declaracionAnterior = Declaracion.Load(declaracionAnteriorID, declaracion.FuncionarioID, Gestion.For(gestion.Gestion, gestion.FechaInicio, gestion.FechaFinal, gestion.Vigente), declaracion.FechaLlenado, (EstadoDeclaracion)Enum.Parse(typeof(EstadoDeclaracion), declaracion.Estado), depositosAnteriorCollection, deudasAnteriorCollection, inmueblesAnteriorCollection, otrosAnteriorIngresosCollection, valoresAnteriorNegociablesCollection, vehiculosAnteriorCollection, null); } Declaracion result = Declaracion.Load(declaracion.ID, declaracion.FuncionarioID, Gestion.For(gestion.Gestion, gestion.FechaInicio, gestion.FechaFinal, gestion.Vigente), declaracion.FechaLlenado, (EstadoDeclaracion)Enum.Parse(typeof(EstadoDeclaracion), declaracion.Estado), depositosCollection, deudasCollection, inmueblesCollection, otrosIngresosCollection, valoresNegociablesCollection, vehiculosCollection, declaracionAnterior); return(result); } }
private static async Task <VehiculoCollection> ReadVehiculosCollection(Guid declaracionID, IDbConnection db) { var vehiculosCollection = new VehiculoCollection(); var vehiculosSQL = "SELECT * FROM Vehiculos WHERE DeclaracionID = @declaracionID"; var vehiculos = await db.QueryAsync <Entities.Vehiculo>(vehiculosSQL, new { declaracionID }); foreach (var item in vehiculos.ToList()) { vehiculosCollection.AddItem(Vehiculo.Load(item.ID, item.DeclaracionID, item.Marca, item.TipoVehiculo, Convert.ToString(item.Anio), item.ValorAproximado, item.SaldoDeudor, item.Banco)); } return(vehiculosCollection); }