public static TargetDTOA Convert(TargetEN en, NHibernate.ISession session = null) { TargetDTOA dto = null; TargetRESTCAD targetRESTCAD = null; TargetCEN targetCEN = null; TargetCP targetCP = null; if (en != null) { dto = new TargetDTOA(); targetRESTCAD = new TargetRESTCAD(session); targetCEN = new TargetCEN(targetRESTCAD); targetCP = new TargetCP(session); // // Attributes dto.Id = en.Id; dto.DesiredValue = en.DesiredValue; dto.Description = en.Description; dto.DueDate = en.DueDate; // // TravesalLink /* Rol: Target o--> Measure */ dto.Measure = MeasureAssembler.Convert((MeasureEN)en.Measure, session); // // Service } return(dto); }
public HttpResponseMessage Modify(int idTarget, [FromBody] TargetDTO dto) { // CAD, CEN, returnValue TargetRESTCAD targetRESTCAD = null; TargetCEN targetCEN = null; TargetDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); targetRESTCAD = new TargetRESTCAD(session); targetCEN = new TargetCEN(targetRESTCAD); // Modify targetCEN.Modify(idTarget, dto.DesiredValue , dto.Description , dto.DueDate ); // Return modified object returnValue = TargetAssembler.Convert(targetRESTCAD.ReadOIDDefault(idTarget), 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] TargetDTO dto) { // CAD, CEN, returnValue, returnOID TargetRESTCAD targetRESTCAD = null; TargetCEN targetCEN = null; TargetDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); targetRESTCAD = new TargetRESTCAD(session); targetCEN = new TargetCEN(targetRESTCAD); // Create returnOID = targetCEN.New_( //Atributo OID: p_goal // attr.estaRelacionado: true dto.Goal_oid // association role , dto.DesiredValue //Atributo Primitivo: p_desiredValue , dto.Description //Atributo Primitivo: p_description , dto.DueDate //Atributo Primitivo: p_dueDate ); SessionCommit(); // Convert return returnValue = TargetAssembler.Convert(targetRESTCAD.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("GetOIDTarget", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage ReadOID(int idTarget) { // CAD, CEN, EN, returnValue TargetRESTCAD targetRESTCAD = null; TargetCEN targetCEN = null; TargetEN targetEN = null; TargetDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); targetRESTCAD = new TargetRESTCAD(session); targetCEN = new TargetCEN(targetRESTCAD); // Data targetEN = targetCEN.ReadOID(idTarget); // Convert return if (targetEN != null) { returnValue = TargetAssembler.Convert(targetEN, session); } } catch (Exception e) { 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 { return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue)); } }