public HttpResponseMessage New_([FromBody] IMPropertyDTO dto) { // CAD, CEN, returnValue, returnOID IMPropertyRESTCAD iMPropertyRESTCAD = null; IMPropertyCEN iMPropertyCEN = null; IMPropertyDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); iMPropertyRESTCAD = new IMPropertyRESTCAD(session); iMPropertyCEN = new IMPropertyCEN(iMPropertyRESTCAD); // Create returnOID = iMPropertyCEN.New_( dto.Name //Atributo Primitivo: p_name , dto.Type //Atributo Primitivo: p_type , dto.IsOID //Atributo Primitivo: p_isOID , dto.IsWritable //Atributo Primitivo: p_isWritable , dto.Description //Atributo Primitivo: p_description , //Atributo OID: p_entity // attr.estaRelacionado: true dto.Entity_oid // association role , dto.Value //Atributo Primitivo: p_value , //Atributo OID: p_property // attr.estaRelacionado: true dto.Property_oid // association role ); SessionCommit(); // Convert return returnValue = IMPropertyAssembler.Convert(iMPropertyRESTCAD.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("GetOIDIMProperty", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage Modify(int idIMProperty, [FromBody] IMPropertyDTO dto) { // CAD, CEN, returnValue IMPropertyRESTCAD iMPropertyRESTCAD = null; IMPropertyCEN iMPropertyCEN = null; IMPropertyDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); iMPropertyRESTCAD = new IMPropertyRESTCAD(session); iMPropertyCEN = new IMPropertyCEN(iMPropertyRESTCAD); // Modify iMPropertyCEN.Modify(idIMProperty, dto.Name , dto.Type , dto.IsOID , dto.IsWritable , dto.Description , dto.Value ); // Return modified object returnValue = IMPropertyAssembler.Convert(iMPropertyRESTCAD.ReadOIDDefault(idIMProperty), 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 IMPropertyEN Convert(IMPropertyDTO dto) { IMPropertyEN newinstance = null; try { if (dto != null) { newinstance = new IMPropertyEN(); if (dto.Property_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IPropertyCAD propertyCAD = new MoSIoTGenNHibernate.CAD.MosIoT.PropertyCAD(); newinstance.Property = propertyCAD.ReadOIDDefault(dto.Property_oid); } newinstance.Id = dto.Id; newinstance.Name = dto.Name; newinstance.Type = dto.Type; newinstance.IsOID = dto.IsOID; if (dto.TargetAssociation_oid != null) { MoSIoTGenNHibernate.CAD.MosIoT.IAssociationCAD associationCAD = new MoSIoTGenNHibernate.CAD.MosIoT.AssociationCAD(); newinstance.TargetAssociation = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.AssociationEN>(); foreach (int entry in dto.TargetAssociation_oid) { newinstance.TargetAssociation.Add(associationCAD.ReadOIDDefault(entry)); } } if (dto.OriginAsociation_oid != null) { MoSIoTGenNHibernate.CAD.MosIoT.IAssociationCAD associationCAD = new MoSIoTGenNHibernate.CAD.MosIoT.AssociationCAD(); newinstance.OriginAsociation = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.AssociationEN>(); foreach (int entry in dto.OriginAsociation_oid) { newinstance.OriginAsociation.Add(associationCAD.ReadOIDDefault(entry)); } } newinstance.AssociationType = dto.AssociationType; newinstance.IsWritable = dto.IsWritable; newinstance.Description = dto.Description; if (dto.Entity_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IEntityCAD entityCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EntityCAD(); newinstance.Entity = entityCAD.ReadOIDDefault(dto.Entity_oid); } if (dto.Trigger_oid != null) { MoSIoTGenNHibernate.CAD.MosIoT.IRecipeTriggerCAD recipeTriggerCAD = new MoSIoTGenNHibernate.CAD.MosIoT.RecipeTriggerCAD(); newinstance.Trigger = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.RecipeTriggerEN>(); foreach (int entry in dto.Trigger_oid) { newinstance.Trigger.Add(recipeTriggerCAD.ReadOIDDefault(entry)); } } if (dto.Register_oid != null) { MoSIoTGenNHibernate.CAD.MosIoT.IRegisterCAD registerCAD = new MoSIoTGenNHibernate.CAD.MosIoT.RegisterCAD(); newinstance.Register = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.RegisterEN>(); foreach (int entry in dto.Register_oid) { newinstance.Register.Add(registerCAD.ReadOIDDefault(entry)); } } newinstance.Value = dto.Value; } } catch (Exception ex) { throw ex; } return(newinstance); }