public HttpResponseMessage New_([FromBody] IMCommandDTO dto) { // CAD, CEN, returnValue, returnOID IMCommandRESTCAD iMCommandRESTCAD = null; IMCommandCEN iMCommandCEN = null; IMCommandDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); iMCommandRESTCAD = new IMCommandRESTCAD(session); iMCommandCEN = new IMCommandCEN(iMCommandRESTCAD); // Create returnOID = iMCommandCEN.New_( dto.Name //Atributo Primitivo: p_name , dto.Type //Atributo Primitivo: p_type , dto.ServiceType //Atributo Primitivo: p_serviceType , dto.Description //Atributo Primitivo: p_description , //Atributo OID: p_entity // attr.estaRelacionado: true dto.Entity_oid // association role , //Atributo OID: p_command // attr.estaRelacionado: true dto.Command_oid // association role ); SessionCommit(); // Convert return returnValue = IMCommandAssembler.Convert(iMCommandRESTCAD.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("GetOIDIMCommand", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage Modify(int idIMCommand, [FromBody] IMCommandDTO dto) { // CAD, CEN, returnValue IMCommandRESTCAD iMCommandRESTCAD = null; IMCommandCEN iMCommandCEN = null; IMCommandDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); iMCommandRESTCAD = new IMCommandRESTCAD(session); iMCommandCEN = new IMCommandCEN(iMCommandRESTCAD); // Modify iMCommandCEN.Modify(idIMCommand, dto.Name , dto.Type , dto.ServiceType , dto.Description ); // Return modified object returnValue = IMCommandAssembler.Convert(iMCommandRESTCAD.ReadOIDDefault(idIMCommand), 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 IMCommandEN Convert(IMCommandDTO dto) { IMCommandEN newinstance = null; try { if (dto != null) { newinstance = new IMCommandEN(); if (dto.Command_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.ICommandCAD commandCAD = new MoSIoTGenNHibernate.CAD.MosIoT.CommandCAD(); newinstance.Command = commandCAD.ReadOIDDefault(dto.Command_oid); } newinstance.Id = dto.Id; newinstance.Name = dto.Name; newinstance.Type = dto.Type; newinstance.ServiceType = dto.ServiceType; newinstance.Description = dto.Description; if (dto.EntityArgument != null) { MoSIoTGenNHibernate.CAD.MosIoT.IEntityArgumentCAD entityArgumentCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EntityArgumentCAD(); newinstance.EntityArgument = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.EntityArgumentEN>(); foreach (EntityArgumentDTO entry in dto.EntityArgument) { newinstance.EntityArgument.Add(EntityArgumentAssemblerDTO.Convert(entry)); } } if (dto.Entity_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IEntityCAD entityCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EntityCAD(); newinstance.Entity = entityCAD.ReadOIDDefault(dto.Entity_oid); } if (dto.RuleAction_oid != null) { MoSIoTGenNHibernate.CAD.MosIoT.IRecipeActionCAD recipeActionCAD = new MoSIoTGenNHibernate.CAD.MosIoT.RecipeActionCAD(); newinstance.RuleAction = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.RecipeActionEN>(); foreach (int entry in dto.RuleAction_oid) { newinstance.RuleAction.Add(recipeActionCAD.ReadOIDDefault(entry)); } } if (dto.OriginState_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IEntityStateCAD entityStateCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EntityStateCAD(); newinstance.OriginState = entityStateCAD.ReadOIDDefault(dto.OriginState_oid); } if (dto.TargetState_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IEntityStateCAD entityStateCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EntityStateCAD(); newinstance.TargetState = entityStateCAD.ReadOIDDefault(dto.TargetState_oid); } if (dto.Triggers_oid != null) { MoSIoTGenNHibernate.CAD.MosIoT.IRecipeTriggerCAD recipeTriggerCAD = new MoSIoTGenNHibernate.CAD.MosIoT.RecipeTriggerCAD(); newinstance.Triggers = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.RecipeTriggerEN>(); foreach (int entry in dto.Triggers_oid) { newinstance.Triggers.Add(recipeTriggerCAD.ReadOIDDefault(entry)); } } } } catch (Exception ex) { throw ex; } return(newinstance); }