public IHttpActionResult GetAll() { HttpResponseMessage response = new HttpResponseMessage(); try { Guid token = this.GetToken(); UserDTO user = this.userService.GetUserLoggedIn(token); PermissionHandler permissionHandler = new PermissionHandler(); if (permissionHandler.IsUserAllowedToListTransports(user.Role)) { List <TransportDTO> transports = this.transportService.GetAllTransports(); response = this.Request.CreateResponse(HttpStatusCode.OK, transports); } else { response = this.Request.CreateResponse(HttpStatusCode.Unauthorized, "El usuario no tiene permisos para ejecutar esta accion"); } } catch (Exception e) { response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message); } return(ResponseMessage(response)); }
public IHttpActionResult GetById(Guid id) { HttpResponseMessage response = new HttpResponseMessage(); if (id != null) { try { Guid token = this.GetToken(); UserDTO user = this.userService.GetUserLoggedIn(token); PermissionHandler permissionHandler = new PermissionHandler(); if (permissionHandler.IsUserAllowedToListTransports(user.Role)) { TransportDTO transport = this.transportService.FindTransportById(id); response = this.Request.CreateResponse(HttpStatusCode.OK, transport); } else { response = this.Request.CreateResponse(HttpStatusCode.Unauthorized, "El usuario no tiene permisos para ejecutar esta accion"); } } catch (Exception e) { response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message); } } else { string message = "El formato del transporte es incorrecto"; response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message); } return(ResponseMessage(response)); }