public static PatientProfileEN Convert(PatientProfileDTO dto) { PatientProfileEN newinstance = null; try { if (dto != null) { newinstance = new PatientProfileEN(); if (dto.AccessMode != null) { MoSIoTGenNHibernate.CAD.MosIoT.IAccessModeCAD accessModeCAD = new MoSIoTGenNHibernate.CAD.MosIoT.AccessModeCAD(); newinstance.AccessMode = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.AccessModeEN>(); foreach (AccessModeDTO entry in dto.AccessMode) { newinstance.AccessMode.Add(AccessModeAssemblerDTO.Convert(entry)); } } newinstance.PreferredLanguage = dto.PreferredLanguage; newinstance.Region = dto.Region; newinstance.HazardAvoidance = dto.HazardAvoidance; if (dto.Disability != null) { MoSIoTGenNHibernate.CAD.MosIoT.IDisabilityCAD disabilityCAD = new MoSIoTGenNHibernate.CAD.MosIoT.DisabilityCAD(); newinstance.Disability = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.DisabilityEN>(); foreach (DisabilityDTO entry in dto.Disability) { newinstance.Disability.Add(DisabilityAssemblerDTO.Convert(entry)); } } newinstance.Id = dto.Id; if (dto.Diseases != null) { MoSIoTGenNHibernate.CAD.MosIoT.IConditionCAD conditionCAD = new MoSIoTGenNHibernate.CAD.MosIoT.ConditionCAD(); newinstance.Diseases = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.ConditionEN>(); foreach (ConditionDTO entry in dto.Diseases) { newinstance.Diseases.Add(ConditionAssemblerDTO.Convert(entry)); } } newinstance.Name = dto.Name; newinstance.Description = dto.Description; } } catch (Exception ex) { throw ex; } return(newinstance); }
public HttpResponseMessage Modify(int idPatientProfile, [FromBody] PatientProfileDTO dto) { // CAD, CEN, returnValue PatientProfileRESTCAD patientProfileRESTCAD = null; PatientProfileCEN patientProfileCEN = null; PatientProfileDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); patientProfileRESTCAD = new PatientProfileRESTCAD(session); patientProfileCEN = new PatientProfileCEN(patientProfileRESTCAD); // Modify patientProfileCEN.Modify(idPatientProfile, dto.PreferredLanguage , dto.Region , dto.HazardAvoidance , dto.Name , dto.Description ); // Return modified object returnValue = PatientProfileAssembler.Convert(patientProfileRESTCAD.ReadOIDDefault(idPatientProfile), 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 New_([FromBody] PatientProfileDTO dto) { // CAD, CEN, returnValue, returnOID PatientProfileRESTCAD patientProfileRESTCAD = null; PatientProfileCEN patientProfileCEN = null; PatientProfileDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); patientProfileRESTCAD = new PatientProfileRESTCAD(session); patientProfileCEN = new PatientProfileCEN(patientProfileRESTCAD); // Create returnOID = patientProfileCEN.New_( dto.PreferredLanguage //Atributo Primitivo: p_preferredLanguage , dto.Region //Atributo Primitivo: p_region , dto.HazardAvoidance //Atributo Primitivo: p_hazardAvoidance , dto.Name //Atributo Primitivo: p_name , dto.Description //Atributo Primitivo: p_description ); SessionCommit(); // Convert return returnValue = PatientProfileAssembler.Convert(patientProfileRESTCAD.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("GetOIDPatientProfile", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }