public HttpResponseMessage Destroy(int p_imcondition_oid) { // CAD, CEN IMConditionRESTCAD iMConditionRESTCAD = null; IMConditionCEN iMConditionCEN = null; try { SessionInitializeTransaction(); iMConditionRESTCAD = new IMConditionRESTCAD(session); iMConditionCEN = new IMConditionCEN(iMConditionRESTCAD); iMConditionCEN.Destroy(p_imcondition_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 IMConditionDTOA Convert(EntityAttributesEN en, NHibernate.ISession session = null) { IMConditionDTOA dto = null; IMConditionRESTCAD iMConditionRESTCAD = null; IMConditionCEN iMConditionCEN = null; IMConditionCP iMConditionCP = null; if (en != null) { dto = new IMConditionDTOA(); iMConditionRESTCAD = new IMConditionRESTCAD(session); iMConditionCEN = new IMConditionCEN(iMConditionRESTCAD); iMConditionCP = new IMConditionCP(session); IMConditionEN enHijo = iMConditionRESTCAD.ReadOIDDefault(en.Id); // // Attributes dto.Id = en.Id; dto.Name = en.Name; dto.Description = en.Description; // // TravesalLink /* Rol: IMCondition o--> Condition */ dto.ValueCondition = ConditionAssembler.Convert((ConditionEN)enHijo.Condition, session); // // Service } return(dto); }
public HttpResponseMessage ReadAll() { // CAD, CEN, EN, returnValue IMConditionRESTCAD iMConditionRESTCAD = null; IMConditionCEN iMConditionCEN = null; List <IMConditionEN> iMConditionEN = null; List <IMConditionDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); iMConditionRESTCAD = new IMConditionRESTCAD(session); iMConditionCEN = new IMConditionCEN(iMConditionRESTCAD); // Data // TODO: paginaciĆ³n iMConditionEN = iMConditionCEN.ReadAll(0, -1).ToList(); // Convert return if (iMConditionEN != null) { returnValue = new List <IMConditionDTOA>(); foreach (IMConditionEN entry in iMConditionEN) { returnValue.Add(IMConditionAssembler.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 idIMCondition, [FromBody] IMConditionDTO dto) { // CAD, CEN, returnValue IMConditionRESTCAD iMConditionRESTCAD = null; IMConditionCEN iMConditionCEN = null; IMConditionDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); iMConditionRESTCAD = new IMConditionRESTCAD(session); iMConditionCEN = new IMConditionCEN(iMConditionRESTCAD); // Modify iMConditionCEN.Modify(idIMCondition, dto.Name , dto.Type , dto.IsOID , dto.IsWritable , dto.Description , dto.Value ); // Return modified object returnValue = IMConditionAssembler.Convert(iMConditionRESTCAD.ReadOIDDefault(idIMCondition), 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] IMConditionDTO dto) { // CAD, CEN, returnValue, returnOID IMConditionRESTCAD iMConditionRESTCAD = null; IMConditionCEN iMConditionCEN = null; IMConditionDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); iMConditionRESTCAD = new IMConditionRESTCAD(session); iMConditionCEN = new IMConditionCEN(iMConditionRESTCAD); // Create returnOID = iMConditionCEN.New_( dto.Name //Atributo Primitivo: p_name , dto.Type //Atributo Primitivo: p_type , dto.IsOID //Atributo Primitivo: p_isOID , dto.IsWritable //Atributo Primitivo: p_isWritable , dto.Description //Atributo Primitivo: p_description , //Atributo OID: p_entity // attr.estaRelacionado: true dto.Entity_oid // association role , dto.Value //Atributo Primitivo: p_value , //Atributo OID: p_condition // attr.estaRelacionado: true dto.Condition_oid // association role ); SessionCommit(); // Convert return returnValue = IMConditionAssembler.Convert(iMConditionRESTCAD.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("GetOIDIMCondition", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage ReadOID(int idIMCondition) { // CAD, CEN, EN, returnValue IMConditionRESTCAD iMConditionRESTCAD = null; IMConditionCEN iMConditionCEN = null; IMConditionEN iMConditionEN = null; IMConditionDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); iMConditionRESTCAD = new IMConditionRESTCAD(session); iMConditionCEN = new IMConditionCEN(iMConditionRESTCAD); // Data iMConditionEN = iMConditionCEN.ReadOID(idIMCondition); // Convert return if (iMConditionEN != null) { returnValue = IMConditionAssembler.Convert(iMConditionEN, 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)); } }