// Modify default (Update all attributes of the class) public void ModifyDefault(PlantaEN planta) { try { SessionInitializeTransaction(); PlantaEN plantaEN = (PlantaEN)session.Load(typeof(PlantaEN), planta.Id); plantaEN.Planta = planta.Planta; session.Update(plantaEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is ReciclaUAGenNHibernate.Exceptions.ModelException) { throw ex; } throw new ReciclaUAGenNHibernate.Exceptions.DataLayerException("Error in PlantaCAD.", ex); } finally { SessionClose(); } }
public void Borrar(int id ) { try { SessionInitializeTransaction(); PlantaEN plantaEN = (PlantaEN)session.Load(typeof(PlantaEN), id); session.Delete(plantaEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is ReciclaUAGenNHibernate.Exceptions.ModelException) { throw ex; } throw new ReciclaUAGenNHibernate.Exceptions.DataLayerException("Error in PlantaCAD.", ex); } finally { SessionClose(); } }
public PlantaEN ReadOIDDefault(int id ) { PlantaEN plantaEN = null; try { SessionInitializeTransaction(); plantaEN = (PlantaEN)session.Get(typeof(PlantaEN), id); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is ReciclaUAGenNHibernate.Exceptions.ModelException) { throw ex; } throw new ReciclaUAGenNHibernate.Exceptions.DataLayerException("Error in PlantaCAD.", ex); } finally { SessionClose(); } return(plantaEN); }
public static PlantaDTOA Convert(PlantaEN en, NHibernate.ISession session = null) { PlantaDTOA dto = null; PlantaRESTCAD plantaRESTCAD = null; PlantaCEN plantaCEN = null; PlantaCP plantaCP = null; if (en != null) { dto = new PlantaDTOA(); plantaRESTCAD = new PlantaRESTCAD(session); plantaCEN = new PlantaCEN(plantaRESTCAD); plantaCP = new PlantaCP(session); // // Attributes dto.Id = en.Id; dto.Planta = en.Planta; // // TravesalLink // // Service } return(dto); }
public int Crear(PlantaEN planta) { try { SessionInitializeTransaction(); if (planta.Edificio != null) { // Argumento OID y no colección. planta.Edificio = (ReciclaUAGenNHibernate.EN.ReciclaUA.EdificioEN)session.Load(typeof(ReciclaUAGenNHibernate.EN.ReciclaUA.EdificioEN), planta.Edificio.Id); planta.Edificio.Plantas .Add(planta); } session.Save(planta); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is ReciclaUAGenNHibernate.Exceptions.ModelException) { throw ex; } throw new ReciclaUAGenNHibernate.Exceptions.DataLayerException("Error in PlantaCAD.", ex); } finally { SessionClose(); } return(planta.Id); }
public PlantaEN BuscarPorId(int id ) { PlantaEN plantaEN = null; plantaEN = _IPlantaCAD.BuscarPorId(id); return(plantaEN); }
public void Modificar(int p_Planta_OID, ReciclaUAGenNHibernate.Enumerated.ReciclaUA.PlantaEnum p_planta) { PlantaEN plantaEN = null; //Initialized PlantaEN plantaEN = new PlantaEN(); plantaEN.Id = p_Planta_OID; plantaEN.Planta = p_planta; //Call to PlantaCAD _IPlantaCAD.Modificar(plantaEN); }
public static PlantaEN Convert(PlantaDTO dto) { PlantaEN newinstance = null; try { if (dto != null) { newinstance = new PlantaEN(); newinstance.Id = dto.Id; newinstance.Planta = dto.Planta; if (dto.Estancias_oid != null) { ReciclaUAGenNHibernate.CAD.ReciclaUA.IEstanciaCAD estanciaCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.EstanciaCAD(); newinstance.Estancias = new System.Collections.Generic.List <ReciclaUAGenNHibernate.EN.ReciclaUA.EstanciaEN>(); foreach (string entry in dto.Estancias_oid) { newinstance.Estancias.Add(estanciaCAD.ReadOIDDefault(entry)); } } if (dto.Edificio_oid != -1) { ReciclaUAGenNHibernate.CAD.ReciclaUA.IEdificioCAD edificioCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.EdificioCAD(); newinstance.Edificio = edificioCAD.ReadOIDDefault(dto.Edificio_oid); } } } catch (Exception ex) { throw ex; } return(newinstance); }
public int Crear(ReciclaUAGenNHibernate.Enumerated.ReciclaUA.PlantaEnum p_planta, int p_edificio) { PlantaEN plantaEN = null; int oid; //Initialized PlantaEN plantaEN = new PlantaEN(); plantaEN.Planta = p_planta; if (p_edificio != -1) { // El argumento p_edificio -> Property edificio es oid = false // Lista de oids id plantaEN.Edificio = new ReciclaUAGenNHibernate.EN.ReciclaUA.EdificioEN(); plantaEN.Edificio.Id = p_edificio; } //Call to PlantaCAD oid = _IPlantaCAD.Crear(plantaEN); return(oid); }
public PlantaEN PlantaEstancia(string id) { PlantaEN result = null; try { SessionInitializeTransaction(); String sql = @"select self.Planta FROM EstanciaEN self " + "where self.Id = :p_Id"; IQuery query = session.CreateQuery(sql).SetParameter("p_Id", id); result = query.UniqueResult <PlantaEN>(); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is ReciclaUAGenNHibernate.Exceptions.ModelException) { throw ex; } throw new ReciclaUAGenNHibernate.Exceptions.DataLayerException("Error in EstanciaRESTCAD.", ex); } finally { SessionClose(); } return(result); }
public HttpResponseMessage BuscarPorId(int idPlanta) { // CAD, CEN, EN, returnValue PlantaRESTCAD plantaRESTCAD = null; PlantaCEN plantaCEN = null; PlantaEN plantaEN = null; PlantaDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); plantaRESTCAD = new PlantaRESTCAD(session); plantaCEN = new PlantaCEN(plantaRESTCAD); // Data plantaEN = plantaCEN.BuscarPorId(idPlanta); // Convert return if (plantaEN != null) { returnValue = PlantaAssembler.Convert(plantaEN, session); } } catch (Exception e) { if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.DataLayerException)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } else { throw new HttpResponseException(HttpStatusCode.InternalServerError); } } finally { SessionClose(); } // Return 404 - Not found if (returnValue == null) { return(this.Request.CreateResponse(HttpStatusCode.NotFound)); } // Return 200 - OK else { return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue)); } }