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 static AccessModeEN Convert(AccessModeDTO dto) { AccessModeEN newinstance = null; try { if (dto != null) { newinstance = new AccessModeEN(); if (dto.Patient_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IPatientProfileCAD patientProfileCAD = new MoSIoTGenNHibernate.CAD.MosIoT.PatientProfileCAD(); newinstance.Patient = patientProfileCAD.ReadOIDDefault(dto.Patient_oid); } newinstance.Id = dto.Id; newinstance.TypeAccessMode = dto.TypeAccessMode; if (dto.AdaptationDetailRequired != null) { MoSIoTGenNHibernate.CAD.MosIoT.IAdaptationDetailRequiredCAD adaptationDetailRequiredCAD = new MoSIoTGenNHibernate.CAD.MosIoT.AdaptationDetailRequiredCAD(); newinstance.AdaptationDetailRequired = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.AdaptationDetailRequiredEN>(); foreach (AdaptationDetailRequiredDTO entry in dto.AdaptationDetailRequired) { newinstance.AdaptationDetailRequired.Add(AdaptationDetailRequiredAssemblerDTO.Convert(entry)); } } if (dto.DeviceTemplate_oid != null) { MoSIoTGenNHibernate.CAD.MosIoT.IDeviceTemplateCAD deviceTemplateCAD = new MoSIoTGenNHibernate.CAD.MosIoT.DeviceTemplateCAD(); newinstance.DeviceTemplate = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.DeviceTemplateEN>(); foreach (int entry in dto.DeviceTemplate_oid) { newinstance.DeviceTemplate.Add(deviceTemplateCAD.ReadOIDDefault(entry)); } } newinstance.Description = dto.Description; if (dto.AdaptationTypeRequired != null) { MoSIoTGenNHibernate.CAD.MosIoT.IAdaptationTypeRequiredCAD adaptationTypeRequiredCAD = new MoSIoTGenNHibernate.CAD.MosIoT.AdaptationTypeRequiredCAD(); newinstance.AdaptationTypeRequired = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.AdaptationTypeRequiredEN>(); foreach (AdaptationTypeRequiredDTO entry in dto.AdaptationTypeRequired) { newinstance.AdaptationTypeRequired.Add(AdaptationTypeRequiredAssemblerDTO.Convert(entry)); } } if (dto.AdaptationRequest != null) { MoSIoTGenNHibernate.CAD.MosIoT.IAdaptationRequestCAD adaptationRequestCAD = new MoSIoTGenNHibernate.CAD.MosIoT.AdaptationRequestCAD(); newinstance.AdaptationRequest = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.AdaptationRequestEN>(); foreach (AdaptationRequestDTO entry in dto.AdaptationRequest) { newinstance.AdaptationRequest.Add(AdaptationRequestAssemblerDTO.Convert(entry)); } } if (dto.Disability_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IDisabilityCAD disabilityCAD = new MoSIoTGenNHibernate.CAD.MosIoT.DisabilityCAD(); newinstance.Disability = disabilityCAD.ReadOIDDefault(dto.Disability_oid); } newinstance.Name = dto.Name; } } catch (Exception ex) { throw ex; } return(newinstance); }