public HttpResponseMessage Modify(int idGoal, [FromBody] GoalDTO dto) { // CAD, CEN, returnValue GoalRESTCAD goalRESTCAD = null; GoalCEN goalCEN = null; GoalDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); goalRESTCAD = new GoalRESTCAD(session); goalCEN = new GoalCEN(goalRESTCAD); // Modify goalCEN.Modify(idGoal, dto.Priority , dto.Status , dto.Description , dto.Category , dto.OutcomeCode , dto.Name ); // Return modified object returnValue = GoalAssembler.Convert(goalRESTCAD.ReadOIDDefault(idGoal), 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] GoalDTO dto) { // CAD, CEN, returnValue, returnOID GoalRESTCAD goalRESTCAD = null; GoalCEN goalCEN = null; GoalDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); goalRESTCAD = new GoalRESTCAD(session); goalCEN = new GoalCEN(goalRESTCAD); // Create returnOID = goalCEN.New_( //Atributo OID: p_carePlanTemplate // attr.estaRelacionado: true dto.CarePlanTemplate_oid // association role , dto.Priority //Atributo Primitivo: p_priority , dto.Status //Atributo Primitivo: p_status , //Atributo OID: p_condition // attr.estaRelacionado: true dto.Condition_oid // association role , dto.Description //Atributo Primitivo: p_description , dto.Category //Atributo Primitivo: p_category , dto.OutcomeCode //Atributo Primitivo: p_outcomeCode , dto.Name //Atributo Primitivo: p_name ); SessionCommit(); // Convert return returnValue = GoalAssembler.Convert(goalRESTCAD.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("GetOIDGoal", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }