public HttpResponseMessage Modify(int idCareActivity, [FromBody] CareActivityDTO dto) { // CAD, CEN, returnValue CareActivityRESTCAD careActivityRESTCAD = null; CareActivityCEN careActivityCEN = null; CareActivityDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); careActivityRESTCAD = new CareActivityRESTCAD(session); careActivityCEN = new CareActivityCEN(careActivityRESTCAD); // Modify careActivityCEN.Modify(idCareActivity, dto.Periodicity , dto.Description , dto.Duration , dto.Location , dto.OutcomeCode , dto.TypeActivity , dto.ActivityCode , dto.Name ); // Return modified object returnValue = CareActivityAssembler.Convert(careActivityRESTCAD.ReadOIDDefault(idCareActivity), 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 CareActivityEN Convert(CareActivityDTO dto) { CareActivityEN newinstance = null; try { if (dto != null) { newinstance = new CareActivityEN(); if (dto.CarePlan_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.ICarePlanTemplateCAD carePlanTemplateCAD = new MoSIoTGenNHibernate.CAD.MosIoT.CarePlanTemplateCAD(); newinstance.CarePlan = carePlanTemplateCAD.ReadOIDDefault(dto.CarePlan_oid); } newinstance.Id = dto.Id; newinstance.Periodicity = dto.Periodicity; newinstance.Description = dto.Description; newinstance.Duration = dto.Duration; if (dto.Medication != null) { MoSIoTGenNHibernate.CAD.MosIoT.IMedicationCAD medicationCAD = new MoSIoTGenNHibernate.CAD.MosIoT.MedicationCAD(); newinstance.Medication = MedicationAssemblerDTO.Convert(dto.Medication); } newinstance.Location = dto.Location; newinstance.OutcomeCode = dto.OutcomeCode; if (dto.NutritionOrder != null) { MoSIoTGenNHibernate.CAD.MosIoT.INutritionOrderCAD nutritionOrderCAD = new MoSIoTGenNHibernate.CAD.MosIoT.NutritionOrderCAD(); newinstance.NutritionOrder = NutritionOrderAssemblerDTO.Convert(dto.NutritionOrder); } newinstance.TypeActivity = dto.TypeActivity; if (dto.Notification != null) { MoSIoTGenNHibernate.CAD.MosIoT.IComunicationCAD comunicationCAD = new MoSIoTGenNHibernate.CAD.MosIoT.ComunicationCAD(); newinstance.Notification = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.ComunicationEN>(); foreach (ComunicationDTO entry in dto.Notification) { newinstance.Notification.Add(ComunicationAssemblerDTO.Convert(entry)); } } newinstance.ActivityCode = dto.ActivityCode; newinstance.Name = dto.Name; if (dto.Appointment != null) { MoSIoTGenNHibernate.CAD.MosIoT.IAppointmentCAD appointmentCAD = new MoSIoTGenNHibernate.CAD.MosIoT.AppointmentCAD(); newinstance.Appointment = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.AppointmentEN>(); foreach (AppointmentDTO entry in dto.Appointment) { newinstance.Appointment.Add(AppointmentAssemblerDTO.Convert(entry)); } } } } catch (Exception ex) { throw ex; } return(newinstance); }
public HttpResponseMessage New_([FromBody] CareActivityDTO dto) { // CAD, CEN, returnValue, returnOID CareActivityRESTCAD careActivityRESTCAD = null; CareActivityCEN careActivityCEN = null; CareActivityDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); careActivityRESTCAD = new CareActivityRESTCAD(session); careActivityCEN = new CareActivityCEN(careActivityRESTCAD); // Create returnOID = careActivityCEN.New_( //Atributo OID: p_carePlanTemplate // attr.estaRelacionado: true dto.CarePlanTemplate_oid // association role , dto.Periodicity //Atributo Primitivo: p_periodicity , dto.Description //Atributo Primitivo: p_description , dto.Duration //Atributo Primitivo: p_duration , dto.Location //Atributo Primitivo: p_location , dto.OutcomeCode //Atributo Primitivo: p_outcomeCode , dto.TypeActivity //Atributo Primitivo: p_typeActivity , dto.ActivityCode //Atributo Primitivo: p_activityCode , dto.Name //Atributo Primitivo: p_name ); SessionCommit(); // Convert return returnValue = CareActivityAssembler.Convert(careActivityRESTCAD.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("GetOIDCareActivity", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }