public static MaterialDTOA Convert(MaterialEN en, NHibernate.ISession session = null) { MaterialDTOA dto = null; MaterialRESTCAD materialRESTCAD = null; MaterialCEN materialCEN = null; MaterialCP materialCP = null; if (en != null) { dto = new MaterialDTOA(); materialRESTCAD = new MaterialRESTCAD(session); materialCEN = new MaterialCEN(materialRESTCAD); materialCP = new MaterialCP(session); // // Attributes dto.Id = en.Id; dto.Nombre = en.Nombre; dto.Contenedor = en.Contenedor; dto.EsValido = en.EsValido; // // TravesalLink // // Service } return(dto); }
public HttpResponseMessage Modificar(int idMaterial, [FromBody] MaterialDTO dto) { // CAD, CEN, returnValue MaterialRESTCAD materialRESTCAD = null; MaterialCEN materialCEN = null; MaterialDTOA 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); materialRESTCAD = new MaterialRESTCAD(session); materialCEN = new MaterialCEN(materialRESTCAD); // Modify materialCEN.Modificar(idMaterial, dto.Nombre , dto.Contenedor , dto.EsValido ); // Return modified object returnValue = MaterialAssembler.Convert(materialRESTCAD.ReadOIDDefault(idMaterial), 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 BuscarPorId(int idMaterial) { // CAD, CEN, EN, returnValue MaterialRESTCAD materialRESTCAD = null; MaterialCEN materialCEN = null; MaterialEN materialEN = null; MaterialDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); materialRESTCAD = new MaterialRESTCAD(session); materialCEN = new MaterialCEN(materialRESTCAD); // Data materialEN = materialCEN.BuscarPorId(idMaterial); // Convert return if (materialEN != null) { returnValue = MaterialAssembler.Convert(materialEN, 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)); } }
public HttpResponseMessage Crear([FromBody] MaterialDTO dto) { // CAD, CEN, returnValue, returnOID MaterialRESTCAD materialRESTCAD = null; MaterialCEN materialCEN = null; MaterialDTOA 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); materialRESTCAD = new MaterialRESTCAD(session); materialCEN = new MaterialCEN(materialRESTCAD); // Create returnOID = materialCEN.Crear( //Atributo Primitivo: p_nombre dto.Nombre, //Atributo Primitivo: p_contenedor dto.Contenedor, //Atributo OID: p_usuario // attr.estaRelacionado: true dto.Usuario_oid // association role ); SessionCommit(); // Convert return returnValue = MaterialAssembler.Convert(materialRESTCAD.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("GetOIDMaterial", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage CrearCP([FromBody] MaterialDTO dto) { // CAD, CEN, returnValue, returnOID MaterialRESTCAD materialRESTCAD = null; MaterialCEN materialCEN = null; MaterialDTOA returnValue = null; MaterialCP materialCP = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); materialRESTCAD = new MaterialRESTCAD(session); materialCEN = new MaterialCEN(materialRESTCAD); materialCP = new MaterialCP(session); // Create returnOID = materialCEN.Crear(dto.Nombre, dto.Contenedor, dto.Usuario_oid); materialCP.CrearAccionMaterial(returnOID); SessionCommit(); // Convert return returnValue = MaterialAssembler.Convert(materialRESTCAD.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); }