public static IoTScenarioEN Convert(IoTScenarioDTO dto) { IoTScenarioEN newinstance = null; try { if (dto != null) { newinstance = new IoTScenarioEN(); newinstance.Id = dto.Id; newinstance.Name = dto.Name; if (dto.Entity != null) { MoSIoTGenNHibernate.CAD.MosIoT.IEntityCAD entityCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EntityCAD(); newinstance.Entity = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.EntityEN>(); foreach (EntityDTO entry in dto.Entity) { newinstance.Entity.Add(EntityAssemblerDTO.Convert(entry)); } } if (dto.Recipes != null) { MoSIoTGenNHibernate.CAD.MosIoT.IRecipeCAD recipeCAD = new MoSIoTGenNHibernate.CAD.MosIoT.RecipeCAD(); newinstance.Recipes = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.RecipeEN>(); foreach (RecipeDTO entry in dto.Recipes) { newinstance.Recipes.Add(RecipeAssemblerDTO.Convert(entry)); } } if (dto.Association != null) { MoSIoTGenNHibernate.CAD.MosIoT.IAssociationCAD associationCAD = new MoSIoTGenNHibernate.CAD.MosIoT.AssociationCAD(); newinstance.Association = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.AssociationEN>(); foreach (AssociationDTO entry in dto.Association) { newinstance.Association.Add(AssociationAssemblerDTO.Convert(entry)); } } newinstance.Description = dto.Description; } } catch (Exception ex) { throw ex; } return(newinstance); }
public HttpResponseMessage Modify(int idIoTScenario, [FromBody] IoTScenarioDTO dto) { // CAD, CEN, returnValue IoTScenarioRESTCAD ioTScenarioRESTCAD = null; IoTScenarioCEN ioTScenarioCEN = null; IoTScenarioDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); ioTScenarioRESTCAD = new IoTScenarioRESTCAD(session); ioTScenarioCEN = new IoTScenarioCEN(ioTScenarioRESTCAD); // Modify ioTScenarioCEN.Modify(idIoTScenario, dto.Name , dto.Description ); // Return modified object returnValue = IoTScenarioAssembler.Convert(ioTScenarioRESTCAD.ReadOIDDefault(idIoTScenario), 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] IoTScenarioDTO dto) { // CAD, CEN, returnValue, returnOID IoTScenarioRESTCAD ioTScenarioRESTCAD = null; IoTScenarioCEN ioTScenarioCEN = null; IoTScenarioDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); ioTScenarioRESTCAD = new IoTScenarioRESTCAD(session); ioTScenarioCEN = new IoTScenarioCEN(ioTScenarioRESTCAD); // Create returnOID = ioTScenarioCEN.New_( dto.Name //Atributo Primitivo: p_name , dto.Description //Atributo Primitivo: p_description ); SessionCommit(); // Convert return returnValue = IoTScenarioAssembler.Convert(ioTScenarioRESTCAD.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("GetOIDIoTScenario", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }