public IHttpActionResult CreateSubZone(string id, [FromBody] ZoneDTO zone) { HttpResponseMessage response = new HttpResponseMessage(); try { Guid token = this.GetToken(); Guid mainZoneId = Guid.Parse(id); UserDTO userLogged = this.userService.GetUserLoggedIn(token); PermissionHandler permissionHandler = new PermissionHandler(); if (permissionHandler.IsUserAllowedToCreateZones(userLogged.Role)) { this.zoneService.AddSubZone(mainZoneId, zone); response = this.Request.CreateResponse(HttpStatusCode.Created); } else { response = this.Request.CreateResponse(HttpStatusCode.Unauthorized, "El usuario no tiene permisos para ejecutar esta accion"); } } catch (ZoneNullAttributesException e) { response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message); } catch (UserNotExistException e) { response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message); } catch (ZoneOutOfCapacityException e) { response = this.Request.CreateResponse(HttpStatusCode.BadRequest, e.Message); } catch (InvalidOperationException) { string message = "No se ha enviado header de autenticación."; response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message); } catch (FormatException) { string message = "El token enviado no tiene un formato valido."; response = this.Request.CreateResponse(HttpStatusCode.BadRequest, message); } return(ResponseMessage(response)); }