public static AccessModeDTOA Convert(AccessModeEN en, NHibernate.ISession session = null) { AccessModeDTOA dto = null; AccessModeRESTCAD accessModeRESTCAD = null; AccessModeCEN accessModeCEN = null; AccessModeCP accessModeCP = null; if (en != null) { dto = new AccessModeDTOA(); accessModeRESTCAD = new AccessModeRESTCAD(session); accessModeCEN = new AccessModeCEN(accessModeRESTCAD); accessModeCP = new AccessModeCP(session); // // Attributes dto.Id = en.Id; dto.TypeAccessMode = en.TypeAccessMode; dto.Description = en.Description; dto.Name = en.Name; // // TravesalLink /* Rol: AccessMode o--> AdaptationRequest */ dto.AdaptationRequest = null; List <AdaptationRequestEN> AdaptationRequest = accessModeRESTCAD.AdaptationRequest(en.Id).ToList(); if (AdaptationRequest != null) { dto.AdaptationRequest = new List <AdaptationRequestDTOA>(); foreach (AdaptationRequestEN entry in AdaptationRequest) { dto.AdaptationRequest.Add(AdaptationRequestAssembler.Convert(entry, session)); } } /* Rol: AccessMode o--> AdaptationTypeRequired */ dto.AdaptationType = null; List <AdaptationTypeRequiredEN> AdaptationType = accessModeRESTCAD.AdaptationType(en.Id).ToList(); if (AdaptationType != null) { dto.AdaptationType = new List <AdaptationTypeRequiredDTOA>(); foreach (AdaptationTypeRequiredEN entry in AdaptationType) { dto.AdaptationType.Add(AdaptationTypeRequiredAssembler.Convert(entry, session)); } } /* Rol: AccessMode o--> AdaptationDetailRequired */ dto.AdaptationDetail = null; List <AdaptationDetailRequiredEN> AdaptationDetail = accessModeRESTCAD.AdaptationDetail(en.Id).ToList(); if (AdaptationDetail != null) { dto.AdaptationDetail = new List <AdaptationDetailRequiredDTOA>(); foreach (AdaptationDetailRequiredEN entry in AdaptationDetail) { dto.AdaptationDetail.Add(AdaptationDetailRequiredAssembler.Convert(entry, session)); } } // // Service } return(dto); }
public HttpResponseMessage New_([FromBody] AccessModeDTO dto) { // CAD, CEN, returnValue, returnOID AccessModeRESTCAD accessModeRESTCAD = null; AccessModeCEN accessModeCEN = null; AccessModeDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); accessModeRESTCAD = new AccessModeRESTCAD(session); accessModeCEN = new AccessModeCEN(accessModeRESTCAD); // Create returnOID = accessModeCEN.New_( //Atributo OID: p_patient // attr.estaRelacionado: true dto.Patient_oid // association role , dto.TypeAccessMode //Atributo Primitivo: p_typeAccessMode , dto.Description //Atributo Primitivo: p_description , //Atributo OID: p_disability // attr.estaRelacionado: true dto.Disability_oid // association role , dto.Name //Atributo Primitivo: p_name ); SessionCommit(); // Convert return returnValue = AccessModeAssembler.Convert(accessModeRESTCAD.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("GetOIDAccessMode", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage Modify(int idAccessMode, [FromBody] AccessModeDTO dto) { // CAD, CEN, returnValue AccessModeRESTCAD accessModeRESTCAD = null; AccessModeCEN accessModeCEN = null; AccessModeDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); accessModeRESTCAD = new AccessModeRESTCAD(session); accessModeCEN = new AccessModeCEN(accessModeRESTCAD); // Modify accessModeCEN.Modify(idAccessMode, dto.TypeAccessMode , dto.Description , dto.Name ); // Return modified object returnValue = AccessModeAssembler.Convert(accessModeRESTCAD.ReadOIDDefault(idAccessMode), 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 idAccessMode) { // CAD, CEN, EN, returnValue AccessModeRESTCAD accessModeRESTCAD = null; AccessModeCEN accessModeCEN = null; AccessModeEN accessModeEN = null; AccessModeDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); accessModeRESTCAD = new AccessModeRESTCAD(session); accessModeCEN = new AccessModeCEN(accessModeRESTCAD); // Data accessModeEN = accessModeCEN.ReadOID(idAccessMode); // Convert return if (accessModeEN != null) { returnValue = AccessModeAssembler.Convert(accessModeEN, 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)); } }