public HttpResponseMessage ReadAll() { // CAD, CEN, EN, returnValue IMCommandRESTCAD iMCommandRESTCAD = null; IMCommandCEN iMCommandCEN = null; List <IMCommandEN> iMCommandEN = null; List <IMCommandDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); iMCommandRESTCAD = new IMCommandRESTCAD(session); iMCommandCEN = new IMCommandCEN(iMCommandRESTCAD); // Data // TODO: paginaciĆ³n iMCommandEN = iMCommandCEN.ReadAll(0, -1).ToList(); // Convert return if (iMCommandEN != null) { returnValue = new List <IMCommandDTOA>(); foreach (IMCommandEN entry in iMCommandEN) { returnValue.Add(IMCommandAssembler.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 New_([FromBody] IMCommandDTO dto) { // CAD, CEN, returnValue, returnOID IMCommandRESTCAD iMCommandRESTCAD = null; IMCommandCEN iMCommandCEN = null; IMCommandDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); iMCommandRESTCAD = new IMCommandRESTCAD(session); iMCommandCEN = new IMCommandCEN(iMCommandRESTCAD); // Create returnOID = iMCommandCEN.New_( dto.Name //Atributo Primitivo: p_name , dto.Type //Atributo Primitivo: p_type , dto.ServiceType //Atributo Primitivo: p_serviceType , dto.Description //Atributo Primitivo: p_description , //Atributo OID: p_entity // attr.estaRelacionado: true dto.Entity_oid // association role , //Atributo OID: p_command // attr.estaRelacionado: true dto.Command_oid // association role ); SessionCommit(); // Convert return returnValue = IMCommandAssembler.Convert(iMCommandRESTCAD.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("GetOIDIMCommand", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage Modify(int idIMCommand, [FromBody] IMCommandDTO dto) { // CAD, CEN, returnValue IMCommandRESTCAD iMCommandRESTCAD = null; IMCommandCEN iMCommandCEN = null; IMCommandDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); iMCommandRESTCAD = new IMCommandRESTCAD(session); iMCommandCEN = new IMCommandCEN(iMCommandRESTCAD); // Modify iMCommandCEN.Modify(idIMCommand, dto.Name , dto.Type , dto.ServiceType , dto.Description ); // Return modified object returnValue = IMCommandAssembler.Convert(iMCommandRESTCAD.ReadOIDDefault(idIMCommand), 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 ReadOID(int idIMCommand) { // CAD, CEN, EN, returnValue IMCommandRESTCAD iMCommandRESTCAD = null; IMCommandCEN iMCommandCEN = null; IMCommandEN iMCommandEN = null; IMCommandDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); iMCommandRESTCAD = new IMCommandRESTCAD(session); iMCommandCEN = new IMCommandCEN(iMCommandRESTCAD); // Data iMCommandEN = iMCommandCEN.ReadOID(idIMCommand); // Convert return if (iMCommandEN != null) { returnValue = IMCommandAssembler.Convert(iMCommandEN, 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)); } }