public static PuntoReciclajeEN Convert(PuntoReciclajeDTO dto) { PuntoReciclajeEN newinstance = null; try { if (dto != null) { newinstance = new PuntoReciclajeEN(); newinstance.Id = dto.Id; newinstance.Latitud = dto.Latitud; newinstance.Longitud = dto.Longitud; newinstance.EsValido = dto.EsValido; if (dto.Usuario_oid != -1) { ReciclaUAGenNHibernate.CAD.ReciclaUA.IUsuarioCAD usuarioCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.UsuarioCAD(); newinstance.Usuario = usuarioCAD.ReadOIDDefault(dto.Usuario_oid); } if (dto.Contenedores != null) { ReciclaUAGenNHibernate.CAD.ReciclaUA.IContenedorCAD contenedorCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.ContenedorCAD(); newinstance.Contenedores = new System.Collections.Generic.List <ReciclaUAGenNHibernate.EN.ReciclaUA.ContenedorEN>(); foreach (ContenedorDTO entry in dto.Contenedores) { newinstance.Contenedores.Add(ContenedorAssemblerDTO.Convert(entry)); } } if (dto.Estancia_oid != null) { ReciclaUAGenNHibernate.CAD.ReciclaUA.IEstanciaCAD estanciaCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.EstanciaCAD(); newinstance.Estancia = estanciaCAD.ReadOIDDefault(dto.Estancia_oid); } } } catch (Exception ex) { throw ex; } return(newinstance); }
public HttpResponseMessage Crear([FromBody] PuntoReciclajeDTO dto) { // CAD, CEN, returnValue, returnOID PuntoReciclajeRESTCAD puntoReciclajeRESTCAD = null; PuntoReciclajeCEN puntoReciclajeCEN = null; PuntoReciclajeDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); puntoReciclajeRESTCAD = new PuntoReciclajeRESTCAD(session); puntoReciclajeCEN = new PuntoReciclajeCEN(puntoReciclajeRESTCAD); // Create returnOID = puntoReciclajeCEN.Crear( //Atributo Primitivo: p_latitud dto.Latitud, //Atributo Primitivo: p_longitud dto.Longitud, //Atributo OID: p_usuario // attr.estaRelacionado: true dto.Usuario_oid // association role , //Atributo OID: p_estancia // attr.estaRelacionado: true dto.Estancia_oid // association role ); SessionCommit(); // Convert return returnValue = PuntoReciclajeAssembler.Convert(puntoReciclajeRESTCAD.ReadOIDDefault(returnOID), session); } catch (Exception e) { SessionRollBack(); 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 201 - Created response = this.Request.CreateResponse(HttpStatusCode.Created, returnValue); // Location Header /* * Dictionary<string, object> routeValues = new Dictionary<string, object>(); * * // TODO: y rolPaths * routeValues.Add("id", returnOID); * * uri = Url.Link("GetOIDPuntoReciclaje", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage Modificar(int idPuntoReciclaje, [FromBody] PuntoReciclajeDTO dto) { // CAD, CEN, returnValue PuntoReciclajeRESTCAD puntoReciclajeRESTCAD = null; PuntoReciclajeCEN puntoReciclajeCEN = null; PuntoReciclajeDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); puntoReciclajeRESTCAD = new PuntoReciclajeRESTCAD(session); puntoReciclajeCEN = new PuntoReciclajeCEN(puntoReciclajeRESTCAD); // Modify puntoReciclajeCEN.Modificar(idPuntoReciclaje, dto.Latitud , dto.Longitud , dto.EsValido ); // Return modified object returnValue = PuntoReciclajeAssembler.Convert(puntoReciclajeRESTCAD.ReadOIDDefault(idPuntoReciclaje), session); SessionCommit(); } catch (Exception e) { SessionRollBack(); 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 { response = this.Request.CreateResponse(HttpStatusCode.OK, returnValue); return(response); } }
public HttpResponseMessage CrearCP([FromBody] PuntoReciclajeDTO dto) { // CAD, CEN, returnValue, returnOID PuntoReciclajeRESTCAD puntoReciclajeRESTCAD = null; PuntoReciclajeCEN puntoReciclajeCEN = null; PuntoReciclajeDTOA returnValue = null; PuntoReciclajeCP puntoCP = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); puntoReciclajeRESTCAD = new PuntoReciclajeRESTCAD(session); puntoReciclajeCEN = new PuntoReciclajeCEN(puntoReciclajeRESTCAD); puntoCP = new PuntoReciclajeCP(session); // Create returnOID = puntoReciclajeCEN.Crear(dto.Latitud, dto.Longitud, dto.Usuario_oid, dto.Estancia_oid); puntoCP.CrearAccionPunto(returnOID); SessionCommit(); // Convert return returnValue = PuntoReciclajeAssembler.Convert(puntoReciclajeRESTCAD.ReadOIDDefault(returnOID), session); } catch (Exception e) { SessionRollBack(); 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 201 - Created response = this.Request.CreateResponse(HttpStatusCode.Created, returnValue); return(response); }