public static DeviceTemplateEN Convert(DeviceTemplateDTO dto) { DeviceTemplateEN newinstance = null; try { if (dto != null) { newinstance = new DeviceTemplateEN(); newinstance.Id = dto.Id; newinstance.Name = dto.Name; if (dto.Property != null) { MoSIoTGenNHibernate.CAD.MosIoT.IPropertyCAD propertyCAD = new MoSIoTGenNHibernate.CAD.MosIoT.PropertyCAD(); newinstance.Property = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.PropertyEN>(); foreach (PropertyDTO entry in dto.Property) { newinstance.Property.Add(PropertyAssemblerDTO.Convert(entry)); } } if (dto.Command != null) { MoSIoTGenNHibernate.CAD.MosIoT.ICommandCAD commandCAD = new MoSIoTGenNHibernate.CAD.MosIoT.CommandCAD(); newinstance.Command = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.CommandEN>(); foreach (CommandDTO entry in dto.Command) { newinstance.Command.Add(CommandAssemblerDTO.Convert(entry)); } } if (dto.Telemetry != null) { MoSIoTGenNHibernate.CAD.MosIoT.ITelemetryCAD telemetryCAD = new MoSIoTGenNHibernate.CAD.MosIoT.TelemetryCAD(); newinstance.Telemetry = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.TelemetryEN>(); foreach (TelemetryDTO entry in dto.Telemetry) { newinstance.Telemetry.Add(TelemetryAssemblerDTO.Convert(entry)); } } newinstance.Type = dto.Type; newinstance.IsEdge = dto.IsEdge; } } catch (Exception ex) { throw ex; } return(newinstance); }
public HttpResponseMessage Modify(int idDeviceTemplate, [FromBody] DeviceTemplateDTO dto) { // CAD, CEN, returnValue DeviceTemplateRESTCAD deviceTemplateRESTCAD = null; DeviceTemplateCEN deviceTemplateCEN = null; DeviceTemplateDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); deviceTemplateRESTCAD = new DeviceTemplateRESTCAD(session); deviceTemplateCEN = new DeviceTemplateCEN(deviceTemplateRESTCAD); // Modify deviceTemplateCEN.Modify(idDeviceTemplate, dto.Name , dto.Type , dto.IsEdge ); // Return modified object returnValue = DeviceTemplateAssembler.Convert(deviceTemplateRESTCAD.ReadOIDDefault(idDeviceTemplate), 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] DeviceTemplateDTO dto) { // CAD, CEN, returnValue, returnOID DeviceTemplateRESTCAD deviceTemplateRESTCAD = null; DeviceTemplateCEN deviceTemplateCEN = null; DeviceTemplateDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); deviceTemplateRESTCAD = new DeviceTemplateRESTCAD(session); deviceTemplateCEN = new DeviceTemplateCEN(deviceTemplateRESTCAD); // Create returnOID = deviceTemplateCEN.New_( dto.Name //Atributo Primitivo: p_name , dto.Type //Atributo Primitivo: p_type , dto.IsEdge //Atributo Primitivo: p_isEdge ); SessionCommit(); // Convert return returnValue = DeviceTemplateAssembler.Convert(deviceTemplateRESTCAD.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("GetOIDDeviceTemplate", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }