public HttpResponseMessage Modify(int idCarePlanTemplate, [FromBody] CarePlanTemplateDTO dto) { // CAD, CEN, returnValue CarePlanTemplateRESTCAD carePlanTemplateRESTCAD = null; CarePlanTemplateCEN carePlanTemplateCEN = null; CarePlanTemplateDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); carePlanTemplateRESTCAD = new CarePlanTemplateRESTCAD(session); carePlanTemplateCEN = new CarePlanTemplateCEN(carePlanTemplateRESTCAD); // Modify carePlanTemplateCEN.Modify(idCarePlanTemplate, dto.Status , dto.Intent , dto.Title , dto.Modified , dto.DurationDays , dto.Name , dto.Description ); // Return modified object returnValue = CarePlanTemplateAssembler.Convert(carePlanTemplateRESTCAD.ReadOIDDefault(idCarePlanTemplate), 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 CarePlanTemplateEN Convert(CarePlanTemplateDTO dto) { CarePlanTemplateEN newinstance = null; try { if (dto != null) { newinstance = new CarePlanTemplateEN(); if (dto.CareActivity != null) { MoSIoTGenNHibernate.CAD.MosIoT.ICareActivityCAD careActivityCAD = new MoSIoTGenNHibernate.CAD.MosIoT.CareActivityCAD(); newinstance.CareActivity = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.CareActivityEN>(); foreach (CareActivityDTO entry in dto.CareActivity) { newinstance.CareActivity.Add(CareActivityAssemblerDTO.Convert(entry)); } } if (dto.PatientProfile_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IPatientProfileCAD patientProfileCAD = new MoSIoTGenNHibernate.CAD.MosIoT.PatientProfileCAD(); newinstance.PatientProfile = patientProfileCAD.ReadOIDDefault(dto.PatientProfile_oid); } newinstance.Status = dto.Status; newinstance.Intent = dto.Intent; newinstance.Title = dto.Title; newinstance.Modified = dto.Modified; if (dto.Goals != null) { MoSIoTGenNHibernate.CAD.MosIoT.IGoalCAD goalCAD = new MoSIoTGenNHibernate.CAD.MosIoT.GoalCAD(); newinstance.Goals = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.GoalEN>(); foreach (GoalDTO entry in dto.Goals) { newinstance.Goals.Add(GoalAssemblerDTO.Convert(entry)); } } if (dto.AddressConditions_oid != null) { MoSIoTGenNHibernate.CAD.MosIoT.IConditionCAD conditionCAD = new MoSIoTGenNHibernate.CAD.MosIoT.ConditionCAD(); newinstance.AddressConditions = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.ConditionEN>(); foreach (int entry in dto.AddressConditions_oid) { newinstance.AddressConditions.Add(conditionCAD.ReadOIDDefault(entry)); } } newinstance.Id = dto.Id; newinstance.DurationDays = dto.DurationDays; newinstance.Name = dto.Name; newinstance.Description = dto.Description; if (dto.Comunication != null) { MoSIoTGenNHibernate.CAD.MosIoT.IComunicationCAD comunicationCAD = new MoSIoTGenNHibernate.CAD.MosIoT.ComunicationCAD(); newinstance.Comunication = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.ComunicationEN>(); foreach (ComunicationDTO entry in dto.Comunication) { newinstance.Comunication.Add(ComunicationAssemblerDTO.Convert(entry)); } } } } catch (Exception ex) { throw ex; } return(newinstance); }
public HttpResponseMessage New_([FromBody] CarePlanTemplateDTO dto) { // CAD, CEN, returnValue, returnOID CarePlanTemplateRESTCAD carePlanTemplateRESTCAD = null; CarePlanTemplateCEN carePlanTemplateCEN = null; CarePlanTemplateDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); carePlanTemplateRESTCAD = new CarePlanTemplateRESTCAD(session); carePlanTemplateCEN = new CarePlanTemplateCEN(carePlanTemplateRESTCAD); // Create returnOID = carePlanTemplateCEN.New_( dto.Status //Atributo Primitivo: p_status , dto.Intent //Atributo Primitivo: p_intent , dto.Title //Atributo Primitivo: p_title , dto.Modified //Atributo Primitivo: p_modified , dto.DurationDays //Atributo Primitivo: p_durationDays , dto.Name //Atributo Primitivo: p_name , dto.Description //Atributo Primitivo: p_description ); SessionCommit(); // Convert return returnValue = CarePlanTemplateAssembler.Convert(carePlanTemplateRESTCAD.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("GetOIDCarePlanTemplate", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }