public HttpResponseMessage New_([FromBody] AccessModeDTO dto) { // CAD, CEN, returnValue, returnOID AccessModeRESTCAD accessModeRESTCAD = null; AccessModeCEN accessModeCEN = null; AccessModeDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); accessModeRESTCAD = new AccessModeRESTCAD(session); accessModeCEN = new AccessModeCEN(accessModeRESTCAD); // Create returnOID = accessModeCEN.New_( //Atributo OID: p_patient // attr.estaRelacionado: true dto.Patient_oid // association role , dto.TypeAccessMode //Atributo Primitivo: p_typeAccessMode , dto.Description //Atributo Primitivo: p_description , //Atributo OID: p_disability // attr.estaRelacionado: true dto.Disability_oid // association role , dto.Name //Atributo Primitivo: p_name ); SessionCommit(); // Convert return returnValue = AccessModeAssembler.Convert(accessModeRESTCAD.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("GetOIDAccessMode", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage Modify(int idAccessMode, [FromBody] AccessModeDTO dto) { // CAD, CEN, returnValue AccessModeRESTCAD accessModeRESTCAD = null; AccessModeCEN accessModeCEN = null; AccessModeDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); accessModeRESTCAD = new AccessModeRESTCAD(session); accessModeCEN = new AccessModeCEN(accessModeRESTCAD); // Modify accessModeCEN.Modify(idAccessMode, dto.TypeAccessMode , dto.Description , dto.Name ); // Return modified object returnValue = AccessModeAssembler.Convert(accessModeRESTCAD.ReadOIDDefault(idAccessMode), 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 DevTemplatesAccessMode(int idAccessMode) { // CAD, EN AccessModeRESTCAD accessModeRESTCAD = null; AccessModeEN accessModeEN = null; // returnValue List <DeviceTemplateEN> en = null; List <DeviceTemplateDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); accessModeRESTCAD = new AccessModeRESTCAD(session); // Exists AccessMode accessModeEN = accessModeRESTCAD.ReadOIDDefault(idAccessMode); if (accessModeEN == null) { throw new HttpResponseException(this.Request.CreateResponse(HttpStatusCode.NotFound, "AccessMode#" + idAccessMode + " not found")); } // Rol // TODO: paginación en = accessModeRESTCAD.DevTemplatesAccessMode(idAccessMode).ToList(); // Convert return if (en != null) { returnValue = new List <DeviceTemplateDTOA>(); foreach (DeviceTemplateEN entry in en) { returnValue.Add(DeviceTemplateAssembler.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)); } }