agregado procesos y bd clases
This commit is contained in:
82
bdAsegasa/Extensiones/municipios.cs
Normal file
82
bdAsegasa/Extensiones/municipios.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using bdAsegasa.dbcontext;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace bdAsegasa.db
|
||||
{
|
||||
public partial class municipios
|
||||
{
|
||||
private static List<municipios> _listaPoblaciones;
|
||||
|
||||
public string PoblacionYProvincia
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.Nombre == this.CodigoProvinciaNavigation?.Nombre)
|
||||
{
|
||||
return this.Nombre;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"{this.Nombre} ({this.CodigoProvinciaNavigation?.Nombre})";
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string ObtienePoblacion(string codigoPoblacion)
|
||||
{
|
||||
EnsureCache();
|
||||
var pob = _listaPoblaciones.FirstOrDefault(x => x.CodigoMunicipio == codigoPoblacion);
|
||||
if (pob != null) return pob.Nombre;
|
||||
|
||||
using (var bd = tscgestionasegasa.NuevoContexto())
|
||||
{
|
||||
pob = bd.municipios.Include(x => x.CodigoProvinciaNavigation).FirstOrDefault(x => x.CodigoMunicipio == codigoPoblacion);
|
||||
if (pob != null)
|
||||
{
|
||||
_listaPoblaciones.Add(pob);
|
||||
return pob.Nombre;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static string ObtieneProvincia(string codigoPoblacion)
|
||||
{
|
||||
EnsureCache();
|
||||
var pob = _listaPoblaciones.FirstOrDefault(x => x.CodigoMunicipio == codigoPoblacion);
|
||||
if (pob != null) return pob.CodigoProvinciaNavigation?.Nombre ?? "";
|
||||
|
||||
using (var bd = tscgestionasegasa.NuevoContexto())
|
||||
{
|
||||
pob = bd.municipios.Include(x => x.CodigoProvinciaNavigation).FirstOrDefault(x => x.CodigoMunicipio == codigoPoblacion);
|
||||
if (pob != null)
|
||||
{
|
||||
_listaPoblaciones.Add(pob);
|
||||
return pob.CodigoProvinciaNavigation?.Nombre ?? "";
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static void EnsureCache()
|
||||
{
|
||||
if (_listaPoblaciones == null)
|
||||
{
|
||||
using (var bd = tscgestionasegasa.NuevoContexto())
|
||||
{
|
||||
_listaPoblaciones = bd.municipios.Include(x => x.CodigoProvinciaNavigation).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user