public static AssociationEN Convert(AssociationDTO dto) { AssociationEN newinstance = null; try { if (dto != null) { newinstance = new AssociationEN(); newinstance.Id = dto.Id; newinstance.Name = dto.Name; if (dto.RolOrigin_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IEntityAttributesCAD entityAttributesCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EntityAttributesCAD(); newinstance.RolOrigin = entityAttributesCAD.ReadOIDDefault(dto.RolOrigin_oid); } if (dto.RolTarget_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IEntityAttributesCAD entityAttributesCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EntityAttributesCAD(); newinstance.RolTarget = entityAttributesCAD.ReadOIDDefault(dto.RolTarget_oid); } newinstance.Type = dto.Type; newinstance.CardinalityOrigin = dto.CardinalityOrigin; newinstance.CardinalityTarget = dto.CardinalityTarget; if (dto.EntityOrigin_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IEntityCAD entityCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EntityCAD(); newinstance.EntityOrigin = entityCAD.ReadOIDDefault(dto.EntityOrigin_oid); } if (dto.EntityTarget_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IEntityCAD entityCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EntityCAD(); newinstance.EntityTarget = entityCAD.ReadOIDDefault(dto.EntityTarget_oid); } if (dto.IoTScenario_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IIoTScenarioCAD ioTScenarioCAD = new MoSIoTGenNHibernate.CAD.MosIoT.IoTScenarioCAD(); newinstance.IoTScenario = ioTScenarioCAD.ReadOIDDefault(dto.IoTScenario_oid); } newinstance.Description = dto.Description; } } catch (Exception ex) { throw ex; } return(newinstance); }
public HttpResponseMessage Modify(int idAssociation, [FromBody] AssociationDTO dto) { // CAD, CEN, returnValue AssociationRESTCAD associationRESTCAD = null; AssociationCEN associationCEN = null; AssociationDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); associationRESTCAD = new AssociationRESTCAD(session); associationCEN = new AssociationCEN(associationRESTCAD); // Modify associationCEN.Modify(idAssociation, dto.Name , dto.Type , dto.CardinalityOrigin , dto.CardinalityTarget , dto.Description ); // Return modified object returnValue = AssociationAssembler.Convert(associationRESTCAD.ReadOIDDefault(idAssociation), 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] AssociationDTO dto) { // CAD, CEN, returnValue, returnOID AssociationRESTCAD associationRESTCAD = null; AssociationCEN associationCEN = null; AssociationDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); associationRESTCAD = new AssociationRESTCAD(session); associationCEN = new AssociationCEN(associationRESTCAD); // Create returnOID = associationCEN.New_( dto.Name //Atributo Primitivo: p_name , //Atributo OID: p_rolOrigin // attr.estaRelacionado: true dto.RolOrigin_oid // association role , //Atributo OID: p_rolTarget // attr.estaRelacionado: true dto.RolTarget_oid // association role , dto.Type //Atributo Primitivo: p_type , dto.CardinalityOrigin //Atributo Primitivo: p_cardinalityOrigin , dto.CardinalityTarget //Atributo Primitivo: p_cardinalityTarget , //Atributo OID: p_entityOrigin // attr.estaRelacionado: true dto.EntityOrigin_oid // association role , //Atributo OID: p_entityTarget // attr.estaRelacionado: true dto.EntityTarget_oid // association role , //Atributo OID: p_ioTScenario // attr.estaRelacionado: true dto.IoTScenario_oid // association role , dto.Description //Atributo Primitivo: p_description ); SessionCommit(); // Convert return returnValue = AssociationAssembler.Convert(associationRESTCAD.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("GetOIDAssociation", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }