public static IMAdaptationRequestDTOA Convert(EntityAttributesEN en, NHibernate.ISession session = null) { IMAdaptationRequestDTOA dto = null; IMAdaptationRequestRESTCAD iMAdaptationRequestRESTCAD = null; IMAdaptationRequestCEN iMAdaptationRequestCEN = null; IMAdaptationRequestCP iMAdaptationRequestCP = null; if (en != null) { dto = new IMAdaptationRequestDTOA(); iMAdaptationRequestRESTCAD = new IMAdaptationRequestRESTCAD(session); iMAdaptationRequestCEN = new IMAdaptationRequestCEN(iMAdaptationRequestRESTCAD); iMAdaptationRequestCP = new IMAdaptationRequestCP(session); IMAdaptationRequestEN enHijo = iMAdaptationRequestRESTCAD.ReadOIDDefault(en.Id); // // Attributes dto.Id = en.Id; dto.Name = en.Name; dto.Description = en.Description; // // TravesalLink /* Rol: IMAdaptationRequest o--> AdaptationRequest */ dto.ValueAdaption = AdaptationRequestAssembler.Convert((AdaptationRequestEN)enHijo.AdaptationRequest, session); // // Service } return(dto); }
public HttpResponseMessage New_([FromBody] IMAdaptationRequestDTO dto) { // CAD, CEN, returnValue, returnOID IMAdaptationRequestRESTCAD iMAdaptationRequestRESTCAD = null; IMAdaptationRequestCEN iMAdaptationRequestCEN = null; IMAdaptationRequestDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); iMAdaptationRequestRESTCAD = new IMAdaptationRequestRESTCAD(session); iMAdaptationRequestCEN = new IMAdaptationRequestCEN(iMAdaptationRequestRESTCAD); // Create returnOID = iMAdaptationRequestCEN.New_( dto.Name //Atributo Primitivo: p_name , dto.Type //Atributo Primitivo: p_type , dto.IsOID //Atributo Primitivo: p_isOID , dto.IsWritable //Atributo Primitivo: p_isWritable , dto.Description //Atributo Primitivo: p_description , //Atributo OID: p_entity // attr.estaRelacionado: true dto.Entity_oid // association role , dto.Value //Atributo Primitivo: p_value , //Atributo OID: p_adaptationRequest // attr.estaRelacionado: true dto.AdaptationRequest_oid // association role ); SessionCommit(); // Convert return returnValue = IMAdaptationRequestAssembler.Convert(iMAdaptationRequestRESTCAD.ReadOIDDefault(returnOID), session); } catch (Exception e) { SessionRollBack(); if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.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("GetOIDIMAdaptationRequest", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage Modify(int idIMAdaptationRequest, [FromBody] IMAdaptationRequestDTO dto) { // CAD, CEN, returnValue IMAdaptationRequestRESTCAD iMAdaptationRequestRESTCAD = null; IMAdaptationRequestCEN iMAdaptationRequestCEN = null; IMAdaptationRequestDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); iMAdaptationRequestRESTCAD = new IMAdaptationRequestRESTCAD(session); iMAdaptationRequestCEN = new IMAdaptationRequestCEN(iMAdaptationRequestRESTCAD); // Modify iMAdaptationRequestCEN.Modify(idIMAdaptationRequest, dto.Name , dto.Type , dto.IsOID , dto.IsWritable , dto.Description , dto.Value ); // Return modified object returnValue = IMAdaptationRequestAssembler.Convert(iMAdaptationRequestRESTCAD.ReadOIDDefault(idIMAdaptationRequest), session); SessionCommit(); } catch (Exception e) { SessionRollBack(); if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.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 ReadOID(int idIMAdaptationRequest) { // CAD, CEN, EN, returnValue IMAdaptationRequestRESTCAD iMAdaptationRequestRESTCAD = null; IMAdaptationRequestCEN iMAdaptationRequestCEN = null; IMAdaptationRequestEN iMAdaptationRequestEN = null; IMAdaptationRequestDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); iMAdaptationRequestRESTCAD = new IMAdaptationRequestRESTCAD(session); iMAdaptationRequestCEN = new IMAdaptationRequestCEN(iMAdaptationRequestRESTCAD); // Data iMAdaptationRequestEN = iMAdaptationRequestCEN.ReadOID(idIMAdaptationRequest); // Convert return if (iMAdaptationRequestEN != null) { returnValue = IMAdaptationRequestAssembler.Convert(iMAdaptationRequestEN, session); } } catch (Exception e) { if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.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)); } }