public HttpResponseMessage Destroy(int p_property_oid) { // CAD, CEN PropertyRESTCAD propertyRESTCAD = null; PropertyCEN propertyCEN = null; try { SessionInitializeTransaction(); propertyRESTCAD = new PropertyRESTCAD(session); propertyCEN = new PropertyCEN(propertyRESTCAD); propertyCEN.Destroy(p_property_oid); 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 204 - No Content return(this.Request.CreateResponse(HttpStatusCode.NoContent)); }
public static PropertyDTOA Convert(PropertyEN en, NHibernate.ISession session = null) { PropertyDTOA dto = null; PropertyRESTCAD propertyRESTCAD = null; PropertyCEN propertyCEN = null; PropertyCP propertyCP = null; if (en != null) { dto = new PropertyDTOA(); propertyRESTCAD = new PropertyRESTCAD(session); propertyCEN = new PropertyCEN(propertyRESTCAD); propertyCP = new PropertyCP(session); // // Attributes dto.Id = en.Id; dto.Name = en.Name; dto.IsWritable = en.IsWritable; dto.IsCloudable = en.IsCloudable; // // TravesalLink // // Service } return(dto); }
public HttpResponseMessage ReadAll() { // CAD, CEN, EN, returnValue PropertyRESTCAD propertyRESTCAD = null; PropertyCEN propertyCEN = null; List <PropertyEN> propertyEN = null; List <PropertyDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); propertyRESTCAD = new PropertyRESTCAD(session); propertyCEN = new PropertyCEN(propertyRESTCAD); // Data // TODO: paginación propertyEN = propertyCEN.ReadAll(0, -1).ToList(); // Convert return if (propertyEN != null) { returnValue = new List <PropertyDTOA>(); foreach (PropertyEN entry in propertyEN) { returnValue.Add(PropertyAssembler.Convert(entry, session)); } } } catch (Exception e) { 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 204 - Empty if (returnValue == null || returnValue.Count == 0) { return(this.Request.CreateResponse(HttpStatusCode.NoContent)); } // Return 200 - OK else { return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue)); } }
public HttpResponseMessage Modify(int idProperty, [FromBody] PropertyDTO dto) { // CAD, CEN, returnValue PropertyRESTCAD propertyRESTCAD = null; PropertyCEN propertyCEN = null; PropertyDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); propertyRESTCAD = new PropertyRESTCAD(session); propertyCEN = new PropertyCEN(propertyRESTCAD); // Modify propertyCEN.Modify(idProperty, dto.Name , dto.IsWritable , dto.IsCloudable ); // Return modified object returnValue = PropertyAssembler.Convert(propertyRESTCAD.ReadOIDDefault(idProperty), 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] PropertyDTO dto) { // CAD, CEN, returnValue, returnOID PropertyRESTCAD propertyRESTCAD = null; PropertyCEN propertyCEN = null; PropertyDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); propertyRESTCAD = new PropertyRESTCAD(session); propertyCEN = new PropertyCEN(propertyRESTCAD); // Create returnOID = propertyCEN.New_( //Atributo OID: p_deviceTemplate // attr.estaRelacionado: true dto.DeviceTemplate_oid // association role , dto.Name //Atributo Primitivo: p_name , dto.IsWritable //Atributo Primitivo: p_isWritable , dto.IsCloudable //Atributo Primitivo: p_isCloudable ); SessionCommit(); // Convert return returnValue = PropertyAssembler.Convert(propertyRESTCAD.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("GetOIDProperty", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage ReadOID(int idProperty) { // CAD, CEN, EN, returnValue PropertyRESTCAD propertyRESTCAD = null; PropertyCEN propertyCEN = null; PropertyEN propertyEN = null; PropertyDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); propertyRESTCAD = new PropertyRESTCAD(session); propertyCEN = new PropertyCEN(propertyRESTCAD); // Data propertyEN = propertyCEN.ReadOID(idProperty); // Convert return if (propertyEN != null) { returnValue = PropertyAssembler.Convert(propertyEN, session); } } catch (Exception e) { 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 { return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue)); } }