public static RangeStateTelemetryEN Convert(RangeStateTelemetryDTO dto) { RangeStateTelemetryEN newinstance = null; try { if (dto != null) { newinstance = new RangeStateTelemetryEN(); if (dto.StateTelemetry_oid != null) { MoSIoTGenNHibernate.CAD.MosIoT.IStateTelemetryCAD stateTelemetryCAD = new MoSIoTGenNHibernate.CAD.MosIoT.StateTelemetryCAD(); newinstance.StateTelemetry = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.StateTelemetryEN>(); foreach (int entry in dto.StateTelemetry_oid) { newinstance.StateTelemetry.Add(stateTelemetryCAD.ReadOIDDefault(entry)); } } newinstance.Id = dto.Id; newinstance.Name = dto.Name; newinstance.Value = dto.Value; } } catch (Exception ex) { throw ex; } return(newinstance); }
public HttpResponseMessage Modify(int idRangeStateTelemetry, [FromBody] RangeStateTelemetryDTO dto) { // CAD, CEN, returnValue RangeStateTelemetryRESTCAD rangeStateTelemetryRESTCAD = null; RangeStateTelemetryCEN rangeStateTelemetryCEN = null; RangeStateTelemetryDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); rangeStateTelemetryRESTCAD = new RangeStateTelemetryRESTCAD(session); rangeStateTelemetryCEN = new RangeStateTelemetryCEN(rangeStateTelemetryRESTCAD); // Modify rangeStateTelemetryCEN.Modify(idRangeStateTelemetry, dto.Name , dto.Value ); // Return modified object returnValue = RangeStateTelemetryAssembler.Convert(rangeStateTelemetryRESTCAD.ReadOIDDefault(idRangeStateTelemetry), 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] RangeStateTelemetryDTO dto) { // CAD, CEN, returnValue, returnOID RangeStateTelemetryRESTCAD rangeStateTelemetryRESTCAD = null; RangeStateTelemetryCEN rangeStateTelemetryCEN = null; RangeStateTelemetryDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); rangeStateTelemetryRESTCAD = new RangeStateTelemetryRESTCAD(session); rangeStateTelemetryCEN = new RangeStateTelemetryCEN(rangeStateTelemetryRESTCAD); // Create returnOID = rangeStateTelemetryCEN.New_( //Atributo Primitivo: p_name dto.Name, //Atributo Primitivo: p_value dto.Value); SessionCommit(); // Convert return returnValue = RangeStateTelemetryAssembler.Convert(rangeStateTelemetryRESTCAD.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("GetOIDRangeStateTelemetry", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }