Last active
August 29, 2015 14:22
-
-
Save 4riel/db516da25729ed91bf33 to your computer and use it in GitHub Desktop.
Fluent NHibernate .NET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using GestionDeExcepciones.Clases; | |
using NHibernate; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using BibliotecaGITDatos.Catalogos.Genericos; | |
using BibliotecaGITDatos.Clases.Publicidad; | |
namespace BibliotecaGITDatos.Catalogos.Publicidad | |
{ | |
/// <summary> | |
/// Catalogo de Los Tipos de Puntos de Interes que pueden poseer un punto de interes | |
/// Por ejemplo -> Hotel, Casino, Farmacia, Estudio Juridico, etc. | |
/// </summary> | |
public class CatalogoTipoPuntoInteres : CatalogoIAC<TipoPuntoInteres> | |
{ | |
/// <summary> | |
/// Devuelve Todos los Tipos de Puntos de Interes que tenga una empresa | |
/// </summary> | |
/// <param name="codigoEmpresa">Codigo de Identificacion de la Empresa</param> | |
/// <param name="nhSesion">Sesion Activa del Fluent Nhibernate wachin</param> | |
/// <returns>EJ => Hotel, Casino, Farmacia, etc.</returns> | |
public static List<TipoPuntoInteres> RecuperarTodosPorEmpresa(int codigoEmpresa, ISession nhSesion) | |
{ | |
try | |
{ | |
IList<TipoPuntoInteres> listaTipoDePuntos = nhSesion.QueryOver<TipoPuntoInteres>().Where(x => x.Empresa.Codigo == codigoEmpresa).List().ToList(); | |
return listaTipoDePuntos.OrderBy(x => x.Codigo).ToList(); | |
} | |
catch (ADOException adoex) | |
{ | |
ExcepcionBaseDeDatos exdb = new ExcepcionBaseDeDatos("RecuperarTodos", string.Empty, adoex); | |
throw exdb.Excepcion; | |
} | |
catch (Exception ex) | |
{ | |
ExcepcionCatalogo ec = new ExcepcionCatalogo("RecuperarTodos", string.Empty, ex); | |
throw ec.Excepcion; | |
} | |
} | |
public static TipoPuntoInteres RecuperarPorCodigoPorEmpresa(int codigoTipoPunto, int codigoEmpresa, ISession nhSesion) | |
{ | |
try | |
{ | |
TipoPuntoInteres TipoPunto = RecuperarPor(x => x.Codigo == codigoTipoPunto && x.Empresa.Codigo == codigoEmpresa, nhSesion); | |
return TipoPunto; | |
} | |
catch (ADOException adoex) | |
{ | |
var exdb = new ExcepcionBaseDeDatos("RecuperarPorCodigo", string.Format("codigoTipoPunto={0};codigoEmpresa={1}", codigoTipoPunto, codigoEmpresa), adoex); | |
throw exdb.Excepcion; | |
} | |
catch (Exception ex) | |
{ | |
ExcepcionCatalogo ec = new ExcepcionCatalogo("RecuperarPorCodigo", string.Empty, ex); | |
throw ec.Excepcion; | |
} | |
} | |
public static TipoPuntoInteres RecuperarPorDescripcionPorEmpresa(int CodigoEmpresa, string descripcion, ISession nhSesion) | |
{ | |
try | |
{ | |
TipoPuntoInteres TipoPunto = RecuperarPor(x => x.Descripcion == descripcion && x.Empresa.Codigo == CodigoEmpresa, nhSesion); | |
return TipoPunto; | |
} | |
catch (ADOException adoex) | |
{ | |
var exdb = new ExcepcionBaseDeDatos("RecuperarPorDescripcion", string.Format("descripcion={0};codigoEmpresa{1}", descripcion, CodigoEmpresa), adoex); | |
throw exdb.Excepcion; | |
} | |
catch (Exception ex) | |
{ | |
ExcepcionCatalogo exc = new ExcepcionCatalogo("RecuperarPorDescripcion", string.Format("descripcion={0};codigoEmpresa{1}", descripcion, CodigoEmpresa), ex); | |
throw exc.Excepcion; | |
} | |
} | |
public static void EliminarPorCodigoPorEmpresa(TipoPuntoInteres tipoPunto, ISession nhSesion) | |
{ | |
try | |
{ | |
if (tipoPunto != null) | |
{ | |
nhSesion.Delete(tipoPunto); | |
nhSesion.Flush(); | |
} | |
} | |
catch (ADOException adoex) | |
{ | |
var exdb = new ExcepcionBaseDeDatos("EliminarPorCodigoPorEmpresa", string.Format("codigoEmpresa{0};codigoTipoPuntoInteres{1}", tipoPunto.Empresa.Codigo, tipoPunto.Codigo), adoex); | |
throw exdb.Excepcion; | |
} | |
catch (Exception ex) | |
{ | |
ExcepcionCatalogo exc = new ExcepcionCatalogo("EliminarPorCodigoPorEmpresa", string.Format("codigoEmpresa{0};codigoTipoPuntoInteres", tipoPunto.Empresa.Codigo,tipoPunto.Codigo), ex); | |
throw exc.Excepcion; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using BibliotecaGITDatos.Clases; | |
using BibliotecaGITDatos.Clases.Configuracion; | |
using BibliotecaGITDatos.ClasesComplementarias; | |
using BibliotecaGITDatos.Catalogos.Publicidad; | |
namespace BibliotecaGITDatos.Clases.Publicidad | |
{ | |
public class TipoPuntoInteres | |
{ | |
public TipoPuntoInteres() | |
{ | |
this.PuntosInteres = new List<PuntoInteres>(); | |
} | |
public virtual int Codigo { get; set; } | |
public virtual string Descripcion { get; set; } | |
public virtual string RutaIcono { get; set; } | |
public virtual Empresa Empresa { get; set; } | |
public virtual IList<PuntoInteres> PuntosInteres { get; set; } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FluentNHibernate.Mapping; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using BibliotecaGITDatos.Clases.Publicidad; | |
namespace BibliotecaGITDatos.Mapeos.Publicidad | |
{ | |
public class TipoPuntoInteresMap : ClassMap<TipoPuntoInteres> | |
{ | |
public TipoPuntoInteresMap() | |
{ | |
Table("PUB_TiposPuntosInteres"); | |
Id(x => x.Codigo).Column("codigoTipoPuntoInteres").GeneratedBy.Identity(); | |
Map(x => x.Descripcion).Column("descripcion"); | |
Map(x => x.RutaIcono).Column("rutaIcono"); | |
//Referencia FK a Empresa que pertenece | |
References(x => x.Empresa).Column("codigoEmpresa").Cascade.None().LazyLoad(Laziness.Proxy).Not.Nullable(); | |
//Uno a muchos hacia sus Puntos de Interes, pero no se si hace falta hacerlo porque no hay que traerlo | |
HasMany<PuntoInteres>(x => x.PuntosInteres).KeyColumn("codigoTipoPuntoInteres").Not.KeyNullable().Cascade.None(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BibliotecaGITDatos.Catalogos; | |
using BibliotecaGITDatos.Catalogos.Auditoria; | |
using BibliotecaGITDatos.Catalogos.Configuracion; | |
using BibliotecaGITDatos.Catalogos.Publicidad; | |
using BibliotecaGITDatos.Clases.Publicidad; | |
using BibliotecaGITDatos.ClasesComplementarias; | |
using BibliotecaGITLogica.Controladores.Configuracion; | |
using GestionDeExcepciones.Clases; | |
using NHibernate; | |
using System; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace BibliotecaGITLogica.Controladores.Publicidad | |
{ | |
public class ControladorPuntoInteresGIT | |
{ | |
#region Tipo de Puntos | |
/// <summary> | |
/// Recuperar todos los Tipos de Puntos de Interes que corresponden a una determinada Empresa | |
/// </summary> | |
/// <param name="codigoEntidad">Id. Entidad</param> | |
/// <param name="codigoEmpresa">Id. Empresa</param> | |
/// <returns>Listado de Tipos de Puntos</returns> | |
public static DataTable RecuperarTipoDePuntosPorEmpresa(int codigoEntidad, int codigoEmpresa) | |
{ | |
ISession nhSesion = ManejoDeNHibernate.IniciarSesion(codigoEntidad); | |
try | |
{ | |
DataTable tablaTipoPuntos = new DataTable(); | |
tablaTipoPuntos.Columns.Add("codigoTipoPuntoInteres"); | |
tablaTipoPuntos.Columns.Add("descripcion"); | |
tablaTipoPuntos.Columns.Add("rutaIcono"); | |
List<TipoPuntoInteres> listaTipoPuntos = new List<TipoPuntoInteres>(); | |
listaTipoPuntos = CatalogoTipoPuntoInteres.RecuperarTodosPorEmpresa(codigoEmpresa, nhSesion).OrderBy(x => x.Descripcion).ToList(); | |
(from x in listaTipoPuntos select x).Aggregate(tablaTipoPuntos, (dt, r) => | |
{ | |
dt.Rows.Add(r.Codigo,r.Descripcion,r.RutaIcono); | |
return dt; | |
}); | |
return tablaTipoPuntos; | |
} | |
catch (Exception ex) | |
{ | |
ExcepcionControlador ec = new ExcepcionControlador("RecuperarTipoDePuntosPorEmpresa", "codigoEmpresa=" + codigoEmpresa, ex); | |
throw ec.Excepcion; | |
} | |
finally | |
{ | |
nhSesion.Close(); | |
nhSesion.Dispose(); | |
} | |
} | |
/// <summary> | |
/// Insertar o Actualizar un Tipo de Punto de Interes a la BD. | |
/// </summary> | |
/// <param name="codigoEntidad">Id. Entidad</param> | |
/// <param name="codigoEmpresa">Id. de Empresa</param> | |
/// <param name="descripcion">Descripcion del Tipo de Punto de Interes (max 50 caracteres)</param> | |
/// <param name="rutaIcono">Ruta de ubicacion del Icono del Tipo de Punto (max 200 caracteres)</param> | |
/// <param name="codigoTipoPunto">Id. del tipo de punto de interes, predeterminadamente es 0 (Es decir cuando se agrega un nuevo)</param> | |
/// <returns>ok -> Operacion Correcta....</returns> | |
public static string InsertarActualizarTipoPuntoInteres(int codigoEntidad, int codigoEmpresa, string descripcion, string rutaIcono, int codigoTipoPunto = 0) | |
{ | |
ISession nhSesion = ManejoDeNHibernate.IniciarSesion(codigoEntidad); | |
TipoPuntoInteres tipoPunto; | |
try | |
{ | |
string rta = "ok"; | |
tipoPunto = (codigoTipoPunto == 0) ? | |
new TipoPuntoInteres() : CatalogoTipoPuntoInteres.RecuperarPorCodigo(codigoTipoPunto, nhSesion); | |
tipoPunto.Descripcion = descripcion; | |
tipoPunto.Empresa = CatalogoEmpresa.RecuperarPorCodigo(codigoEmpresa, nhSesion); | |
tipoPunto.RutaIcono = rutaIcono; | |
rta = ValidarInsertarActualizarTipoPuntoInteres(tipoPunto, nhSesion); | |
if (rta == "ok") | |
{ | |
CatalogoTipoPuntoInteres.InsertarActualizar(tipoPunto, nhSesion); | |
} | |
return rta; | |
} | |
catch (Exception ex) | |
{ | |
ExcepcionControlador ec = new ExcepcionControlador("InsertarActualizarTipoPuntoInteres", string.Format("codigoEmpresa={0};codigoTipoPuntoInteres={1}",codigoEmpresa, codigoTipoPunto), ex); | |
throw ec.Excepcion; | |
} | |
finally | |
{ | |
nhSesion.Close(); | |
nhSesion.Dispose(); | |
} | |
} | |
public static string EliminarTipoPuntoInteres(int codigoEntidad, int codigoEmpresa, int codigoTipoPunto) | |
{ | |
ISession nhSesion = ManejoDeNHibernate.IniciarSesion(codigoEntidad); | |
try | |
{ | |
TipoPuntoInteres tipoPunto; | |
string rta = ValidarEliminarTipoPuntoInteres(codigoEmpresa, codigoTipoPunto, out tipoPunto, nhSesion); | |
if (rta == "ok") | |
{ | |
CatalogoTipoPuntoInteres.EliminarPorCodigoPorEmpresa(tipoPunto, nhSesion); | |
//Realizar Baja pasando tipoPunto | |
} | |
return rta; | |
} | |
catch (Exception ex) | |
{ | |
ExcepcionControlador ec = new ExcepcionControlador("EliminarTipoPuntoInteres", "codigoEmpresa=" + codigoEmpresa + ";codigoTipoPuntoInteres=" + codigoTipoPunto, ex); | |
throw ec.Excepcion; | |
} | |
finally | |
{ | |
nhSesion.Close(); | |
nhSesion.Dispose(); | |
} | |
} | |
#region Validaciones | |
private static string ValidarInsertarActualizarTipoPuntoInteres(TipoPuntoInteres tipoPunto, ISession nhSesion) | |
{ | |
try | |
{ | |
string rta = "ok"; | |
TipoPuntoInteres tipoPuntoTemp = CatalogoTipoPuntoInteres.RecuperarPorDescripcionPorEmpresa(tipoPunto.Empresa.Codigo, tipoPunto.Descripcion, nhSesion); | |
//Verificacion Por Descripcion Existente | |
if (tipoPuntoTemp != null && tipoPuntoTemp.Codigo != tipoPunto.Codigo) | |
{ | |
rta = "DescripcionExistente"; | |
} | |
// | |
return rta; | |
} | |
catch (Exception ex) | |
{ | |
ExcepcionControlador ec = new ExcepcionControlador("InsertartActualizarTipoPuntoInteres", "codigoTipoPuntoInteres=" + tipoPunto.Codigo + ";codigoEmpresa=" + tipoPunto.Empresa.Codigo, ex); | |
throw ec.Excepcion; | |
} | |
} | |
private static string ValidarEliminarTipoPuntoInteres(int codigoEmpresa, int codigoTipoPunto, out TipoPuntoInteres TipoPuntoSalida, ISession nhSesion) | |
{ | |
try | |
{ | |
string rta = "ok"; | |
TipoPuntoSalida = CatalogoTipoPuntoInteres.RecuperarPorCodigoPorEmpresa(codigoTipoPunto, codigoEmpresa, nhSesion); | |
//Verificar si Existe | |
if (TipoPuntoSalida == null) | |
{ | |
rta = "TipoDePuntoInexistente"; | |
} | |
//Verificacion Si tiene Puntos de Interes asociados | |
return rta; | |
} | |
catch (Exception ex) | |
{ | |
ExcepcionControlador ec = new ExcepcionControlador("ValidarEliminarTipoPuntoInteres", string.Format("codigoEmpresa={0}codigoTipoPuntoInteres={1}",codigoEmpresa,codigoTipoPunto), ex); | |
throw ec.Excepcion; | |
} | |
} | |
#endregion | |
#endregion | |
#region Punto de Interes | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment