/***** * Method: GET * Action: coria applications * Rest Endpoints: *************** if id's are guids, * api.ashx/v2/coria.{ext} // coria applications * api.ashx/v2/coria/{containerId}.{ext} // container's application types * api.ashx/v2/coria/{containerId}/{applicationTypeId}.ext // applications * api.ashx/v2/coria/{containerId}/{applicationTypeId}/{applicationId}.ext // applicationId details * api.ashx/v2/coria/{containerId}/{applicationTypeId}/{applicationId}/{contentType}.ext // content types * api.ashx/v2/coria/{containerId}/{applicationTypeId}/{applicationId}/{contentType}/{contentId}.ext // contents ************ mapbooks for container * api.ashx/v2/coria/mapbooks.{ext} // mapbooks, site-wide * api.ashx/v2/coria/mapbooks/users/{userId}.{ext} // mapbooks, user's mapbooks * api.ashx/v2/coria/mapbooks/users/{userId}/{mapbookId}.{ext} // mapbook, user's mapbook * api.ashx/v2/coria/mapbooks/groups/{groupId}.{ext} // mapbooks, group's mapbooks * api.ashx/v2/coria/mapbooks/groups/{groupId}/{mapbookId}.{ext} // mapbook group's mapbook * ********** maps for mapbook * api.ashx/v2/coria/mapbooks/{mapbookId}.{ext} // mapbook * api.ashx/v2/coria/mapbooks/{mapbookId}/maps.{ext} // mapbook maps * api.ashx/v2/coria/mapbooks/{mapbookId}/{mapId}.{ext} // mapbook map * api.ashx/v2/coria/maps/{mapId}.{ext} // map * ************ layers for map * api.ashx/v2/coria/mapbooks/map/{mapId}.{ext} // mapbook * api.ashx/v2/coria/mapbooks/map/{mapId}/layers.{ext} // mapbook map layers * api.ashx/v2/coria/mapbooks/map/{mapId}/layer/{layerId}.{ext} // mapbook map layer *******/ public void Register(IRestEndpointController restRoutes) { object parameterList = new { resource = "CoriaMapBook", action = "List" }; object parameterCreate = new { resource = "CoriaMapBook", action = "Create" }; object parameterDelete = new { resource = "CoriaMapBookMaps", action = "Delete" }; object parameterConstraints = new { }; int version = 2; HttpMethod postMethod = HttpMethod.Post; HttpMethod getMethod = HttpMethod.Get; HttpMethod putMethod = HttpMethod.Put; HttpMethod deleteMethod = HttpMethod.Delete; #region coria/mapbooks/groups/{groupId} Func <IRestRequest, IRestResponse> ListGroupMapBooksResponse = (IRestRequest request) => ListGroupMapBooksRequestResponseFunc(request); Func <IRestRequest, IRestResponse> CreateGroupMapBookResponse = (IRestRequest request) => CreateGroupMapBookRequestResponseFunc(request); Func <IRestRequest, IRestResponse> DeleteMapResponse = (IRestRequest request) => DeleteMapRequestResponseFunc(request); /***** * Rest Endpoints: * api.ashx/v2/coria/mapbooks/groups/{groupId}.{ext} ********/ restRoutes.Add(version, "coria/mapbooks/groups/{groupId}", parameterList, parameterConstraints, getMethod, ListGroupMapBooksResponse); restRoutes.Add(version, "coria/mapbooks/groups/{groupId}", parameterCreate, parameterConstraints, postMethod, CreateGroupMapBookResponse); /************* * api.ashx/v2/coria/maps/{mapId}.{ext} */ restRoutes.Add(version, "coria/maps/{mapId}", parameterDelete, parameterConstraints, deleteMethod, DeleteMapResponse); #endregion #region /***** * Rest Endpoints: * api.ashx/v2/coria/mapbooks/users/{userId}.{ext} * Func<CoriaMapBook, MapBook> toMapBook = (CoriaMapBook fromCoriaMapBook) => ToMapBook(fromCoriaMapBook, new MapBook()); ********/ // restRoutes.Add(version, "coria/mapbooks/users/{userId}.{ext}", parameterList, parameterConstraints, getMethod, (IRestRequest request) => ListUserMapBooksRequestResponseFunc(request); // restRoutes.Add(version, "coria/mapbooks/users/{userId}.{ext}", parameterCreate, parameterConstraints, getMethod, (IRestRequest request) => ListUserMapBooksRequestResponseFunc(request); #endregion }
public void Register(IRestEndpointController controller) { controller.Add(2, "sharepoint/lists", new { }, new { }, HttpMethod.Get, request => RestApi.List.List(new SPListCollectionRequest(request))); controller.Add(2, "sharepoint/lists/{listId}", new { }, new { }, HttpMethod.Get, request => RestApi.List.Get(new SPListItemRequest(request))); controller.Add(2, "sharepoint/lists/{listId}/views", new { }, new { }, HttpMethod.Get, request => RestApi.View.List(new SPViewCollectionRequest(request))); controller.Add(2, "sharepoint/lists/{listId}/views/{viewId}", new { }, new { }, HttpMethod.Get, request => RestApi.View.Get(new SPViewItemRequest(request))); controller.Add(2, "sharepoint/users", new { }, new { }, HttpMethod.Get, request => RestApi.UserOrGroup.List(new SPUserOrGroupRequest(request), onlyGroups: false, onlyUsers: true)); controller.Add(2, "sharepoint/groups", new { }, new { }, HttpMethod.Get, request => RestApi.UserOrGroup.List(new SPUserOrGroupRequest(request), onlyGroups: true)); controller.Add(2, "sharepoint/usersandgroups", new { }, new { }, HttpMethod.Get, request => RestApi.UserOrGroup.List(new SPUserOrGroupRequest(request))); }
public void Register(IRestEndpointController restRoutes) { IThemeUtilities utilites = PluginManager.GetSingleton <IThemeUtilities>(); if (utilites == null || !utilites.EnableThemePageControls) { return; } restRoutes.Add(2, "themeutility/reset", HttpMethod.Post, request => { var response = new RestResponse(); try { string action = request.Request.QueryString["action"]; if (string.IsNullOrEmpty(action)) { throw new ArgumentException("Action parameter is required ('theme' or 'cache')."); } ThemeUtility themeUtility = PluginManager.GetSingleton <ThemeUtility>(); if (themeUtility != null) { if (action.Equals("theme", StringComparison.OrdinalIgnoreCase)) { themeUtility.RevertTheme(); } if (action.Equals("cache", StringComparison.OrdinalIgnoreCase)) { themeUtility.ResetCache(); } } } catch (Exception ex) { response.Errors = new [] { ex.Message }; } return(response); }); }
public void Register(IRestEndpointController restRoutes) { IThemeUtilities utilites = PluginManager.GetSingleton<IThemeUtilities>(); if (utilites == null || !utilites.EnableThemePageControls) return; restRoutes.Add(2, "themeutility/reset", HttpMethod.Post, request => { var response = new RestResponse(); try { string action = request.Request.QueryString["action"]; if (string.IsNullOrEmpty(action)) throw new ArgumentException("Action parameter is required ('theme' or 'cache')."); ThemeUtility themeUtility = PluginManager.GetSingleton<ThemeUtility>(); if (themeUtility != null) { if(action.Equals("theme", StringComparison.OrdinalIgnoreCase)) themeUtility.RevertTheme(); if (action.Equals("cache", StringComparison.OrdinalIgnoreCase)) themeUtility.ResetCache(); } } catch (Exception ex) { response.Errors = new [] { ex.Message }; } return response; }); }
public void Register(IRestEndpointController controller) { #region Poll Endpoints controller.Add(2, "groups/{groupid}/polls", null, new { groupid = @"\d+" }, HttpMethod.Get, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "Polls"; try { int pageSize; int pageIndex; string sortBy = "Date"; if (!int.TryParse(request.Request.QueryString["PageSize"], out pageSize)) { pageSize = 20; } if (!int.TryParse(request.Request.QueryString["PageIndex"], out pageIndex)) { pageIndex = 0; } if (request.Request.QueryString["SortBy"] != null) { sortBy = request.Request.QueryString["SortBy"]; } if (sortBy == "TopPollsScore") { var group = TEApi.Groups.Get(new GroupsGetOptions { Id = Convert.ToInt32(request.PathParameters["groupid"]) }); if (group == null || group.HasErrors()) { response.Data = new Telligent.Evolution.Extensibility.Rest.Entities.Version1.PagedList <RestApi.Poll>(); } else { var scores = TEApi.CalculatedScores.List(Plugins.TopPollsScore.ScoreId, new CalculatedScoreListOptions { ApplicationId = group.ApplicationId, ContentTypeId = PublicApi.Polls.ContentTypeId, PageIndex = pageIndex, PageSize = pageSize, SortOrder = "Descending" }); var polls = new List <RestApi.Poll>(); foreach (var score in scores) { if (score.Content != null) { var poll = InternalApi.PollingService.GetPoll(score.Content.ContentId); if (poll != null) { polls.Add(new RestApi.Poll(poll)); } } } response.Data = new Telligent.Evolution.Extensibility.Rest.Entities.Version1.PagedList <RestApi.Poll>(polls, scores.PageSize, scores.PageIndex, scores.TotalCount); } } else { var polls = InternalApi.PollingService.ListPolls(Convert.ToInt32(request.PathParameters["groupid"]), new PublicApi.PollsListOptions() { PageIndex = pageIndex, PageSize = pageSize, SortBy = sortBy }); response.Data = new Telligent.Evolution.Extensibility.Rest.Entities.Version1.PagedList <RestApi.Poll>(polls.Select(x => new RestApi.Poll(x)), polls.PageSize, polls.PageIndex, polls.TotalCount); } } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return(response); }); controller.Add(2, "polls/poll", HttpMethod.Get, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "Poll"; try { Guid pollId; if (!Guid.TryParse(request.Request.QueryString["Id"], out pollId)) { throw new ArgumentException("Id is required."); } var poll = InternalApi.PollingService.GetPoll(pollId); if (poll == null) { throw new Exception("The poll does not exist."); } response.Data = new RestApi.Poll(poll); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return(response); }); controller.Add(2, "polls/poll", HttpMethod.Delete, (IRestRequest request) => { var response = new RestApi.RestResponse(); try { Guid pollId; if (!Guid.TryParse(request.Request.QueryString["Id"], out pollId)) { throw new ArgumentException("Id is required."); } var poll = InternalApi.PollingService.GetPoll(pollId); if (poll != null) { InternalApi.PollingService.DeletePoll(poll); } } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return(response); }); controller.Add(2, "polls/poll", HttpMethod.Post, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "Poll"; try { // Create int groupId; if (!int.TryParse(request.Form["GroupId"], out groupId)) { throw new ArgumentException("GroupId is required."); } var group = TEApi.Groups.Get(new GroupsGetOptions() { Id = groupId }); if (group == null) { throw new ArgumentException("Group not found"); } string name = request.Form["Name"] ?? string.Empty; string description = request.Form["Description"]; bool hideResultsUntilVotingComplete = request.Form["HideResultsUntilVotingComplete"] == null ? false : Convert.ToBoolean(request.Form["HideResultsUntilVotingComplete"]); DateTime?votingEndDate = request.Form["VotingEndDate"] == null ? null : (DateTime?)InternalApi.Formatting.FromUserTimeToUtc(DateTime.Parse(request.Form["VotingEndDate"])); var poll = new InternalApi.Poll(); poll.ApplicationId = group.ApplicationId; poll.Name = name; poll.Description = description; poll.IsEnabled = true; poll.AuthorUserId = request.UserId; poll.HideResultsUntilVotingComplete = hideResultsUntilVotingComplete; poll.VotingEndDateUtc = votingEndDate; InternalApi.PollingService.AddUpdatePoll(poll); poll = InternalApi.PollingService.GetPoll(poll.Id); response.Data = new RestApi.Poll(poll); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return(response); }); controller.Add(2, "polls/poll", HttpMethod.Put, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "Poll"; try { // Update Guid pollId; if (!Guid.TryParse(request.Request.QueryString["Id"], out pollId)) { throw new ArgumentException("Id is required."); } string name = request.Form["Name"]; string description = request.Form["Description"]; var poll = InternalApi.PollingService.GetPoll(pollId); if (poll == null) { throw new Exception("The poll does not exist."); } if (request.Form["HideResultsUntilVotingComplete"] != null) { poll.HideResultsUntilVotingComplete = Convert.ToBoolean(request.Form["HideResultsUntilVotingComplete"]); } if (request.Form["VotingEndDate"] != null) { poll.VotingEndDateUtc = (DateTime?)InternalApi.Formatting.FromUserTimeToUtc(Convert.ToDateTime(request.Form["VotingEndDate"])); } else if (request.Form["ClearVotingEndDate"] != null && Convert.ToBoolean(request.Form["ClearVotingEndDate"])) { poll.VotingEndDateUtc = null; } if (name != null) { poll.Name = name; } if (description != null) { poll.Description = description; } InternalApi.PollingService.AddUpdatePoll(poll); poll = InternalApi.PollingService.GetPoll(poll.Id); response.Data = new RestApi.Poll(poll); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return(response); }); #endregion #region Poll Answer Endpoints controller.Add(2, "polls/answer", HttpMethod.Get, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "PollAnswer"; try { Guid pollAnswerId; if (!Guid.TryParse(request.Request.QueryString["Id"], out pollAnswerId)) { throw new ArgumentException("Id is required."); } var pollAnswer = InternalApi.PollingService.GetPollAnswer(pollAnswerId); if (pollAnswer == null) { throw new Exception("The poll answer does not exist."); } var poll = InternalApi.PollingService.GetPoll(pollAnswer.PollId); if (poll == null) { throw new Exception("The poll does not exist."); } response.Data = new RestApi.PollAnswer(pollAnswer, poll); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return(response); }); controller.Add(2, "polls/answer", HttpMethod.Delete, (IRestRequest request) => { var response = new RestApi.RestResponse(); try { Guid pollAnswerId; if (!Guid.TryParse(request.Request.QueryString["Id"], out pollAnswerId)) { throw new ArgumentException("Id is required."); } var pollAnswer = InternalApi.PollingService.GetPollAnswer(pollAnswerId); if (pollAnswer != null) { InternalApi.PollingService.DeletePollAnswer(pollAnswer); } } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return(response); }); controller.Add(2, "polls/answer", HttpMethod.Post, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "PollAnswer"; try { // Create Guid pollId; if (!Guid.TryParse(request.Form["PollId"], out pollId)) { throw new ArgumentException("PollId is required."); } string name = request.Form["Name"] ?? string.Empty; var pollAnswer = new InternalApi.PollAnswer(); pollAnswer.PollId = pollId; pollAnswer.Name = name; InternalApi.PollingService.AddUpdatePollAnswer(pollAnswer); pollAnswer = InternalApi.PollingService.GetPollAnswer(pollAnswer.Id); var poll = InternalApi.PollingService.GetPoll(pollAnswer.PollId); response.Data = new RestApi.PollAnswer(pollAnswer, poll); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return(response); }); controller.Add(2, "polls/answer", HttpMethod.Put, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "PollAnswer"; try { // Update Guid pollAnswerId; if (!Guid.TryParse(request.Request.QueryString["Id"], out pollAnswerId)) { throw new ArgumentException("Id is required."); } string name = request.Form["Name"]; var pollAnswer = InternalApi.PollingService.GetPollAnswer(pollAnswerId); if (pollAnswer == null) { throw new Exception("The poll answer does not exist."); } if (name != null) { pollAnswer.Name = name; } InternalApi.PollingService.AddUpdatePollAnswer(pollAnswer); pollAnswer = InternalApi.PollingService.GetPollAnswer(pollAnswer.Id); var poll = InternalApi.PollingService.GetPoll(pollAnswer.PollId); response.Data = new RestApi.PollAnswer(pollAnswer, poll); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return(response); }); #endregion #region Poll Voting Endpoints controller.Add(2, "polls/vote", HttpMethod.Get, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "PollVote"; try { Guid pollId; if (!Guid.TryParse(request.Request.QueryString["PollId"], out pollId)) { throw new ArgumentException("PollId is required."); } var poll = InternalApi.PollingService.GetPoll(pollId); if (poll == null) { throw new Exception("The poll does not exist."); } var vote = InternalApi.PollingService.GetPollVote(pollId, request.UserId); if (vote != null) { response.Data = new RestApi.PollVote(vote); } } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return(response); }); controller.Add(2, "polls/vote", HttpMethod.Delete, (IRestRequest request) => { var response = new RestApi.RestResponse(); try { Guid pollId; if (!Guid.TryParse(request.Form["PollId"], out pollId)) { throw new ArgumentException("PollId is required."); } var vote = InternalApi.PollingService.GetPollVote(pollId, request.UserId); if (vote != null) { InternalApi.PollingService.DeletePollVote(vote); } } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return(response); }); controller.Add(2, "polls/vote", HttpMethod.Post, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "PollVote"; try { // Create Guid pollId; if (!Guid.TryParse(request.Form["PollId"], out pollId)) { throw new ArgumentException("PollId is required."); } Guid pollAnswerId; if (!Guid.TryParse(request.Form["PollAnswerId"], out pollAnswerId)) { throw new ArgumentException("PollAnswerId is required."); } var pollVote = new InternalApi.PollVote(); pollVote.PollId = pollId; pollVote.PollAnswerId = pollAnswerId; pollVote.UserId = request.UserId; InternalApi.PollingService.AddUpdatePollVote(pollVote); pollVote = InternalApi.PollingService.GetPollVote(pollId, request.UserId); response.Data = new RestApi.PollVote(pollVote); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return(response); }); #endregion }
public void Register(IRestEndpointController restRoutes) { // Retrieving user status by userId restRoutes.Add(2, "lync/userstatus/{userId}", HttpMethod.Get, req => { var response = new DefaultRestResponse { Name = "UserStatus" }; try { int userId; if (!Int32.TryParse(req.PathParameters["userId"] as string, out userId)) { throw new ArgumentNullException("userId", "UserId is required"); } var user = PublicApi.Users.Get(new UsersGetOptions { Id = userId }); if (user == null) { throw new ArgumentNullException("user", "User not found"); } response.Data = new { status = _lyncCommunicationService.GetUserStatus(user).ToString(), userid = userId }; return(response); } catch (Exception ex) { response.Errors = new[] { ex.Message }; return(response); } }, new RestEndpointDocumentation { EndpointDocumentation = new RestEndpointDocumentationAttribute { Resource = "UserStatus", Action = "Get User Status" }, RequestDocumentation = new List <RestRequestDocumentationAttribute> { new RestRequestDocumentationAttribute { Name = "UserId", Type = typeof(int), Description = "Id of the user", Required = RestRequired.Required } }, ResponseDocumentation = new RestResponseDocumentationAttribute { Name = "UserStatus", Description = "User Status. Can be one of the list - 'Away', 'BeRightBack', 'Busy', 'DoNotDisturb', 'IdleBusy', 'IdleOnline', 'Offwork', 'Online' or 'Offline'", Type = typeof(UserStatus) } }); // Retrieving current user status restRoutes.Add(2, "lync/userstatus", HttpMethod.Get, req => { var response = new DefaultRestResponse { Name = "UserStatus" }; var user = PublicApi.Users.AccessingUser; try { response.Data = new { status = _lyncCommunicationService.GetCurrentUserStatus().ToString(), userid = user.Id.GetValueOrDefault() }; return(response); } catch (Exception ex) { response.Errors = new[] { ex.Message }; return(response); } }, new RestEndpointDocumentation { EndpointDocumentation = new RestEndpointDocumentationAttribute { Resource = "UserStatus", Action = "Get Current User Status" }, RequestDocumentation = new List <RestRequestDocumentationAttribute>(), ResponseDocumentation = new RestResponseDocumentationAttribute { Name = "UserStatus", Description = "User Status. Can be one of the list - 'Away', 'BeRightBack', 'Busy', 'DoNotDisturb', 'IdleBusy', 'IdleOnline', 'Offwork', 'Online' or 'Offline'", Type = typeof(UserStatus) } }); // Updating current user status restRoutes.Add(2, "lync/userstatus", HttpMethod.Post, req => { var response = new DefaultRestResponse { Name = "UserStatus" }; var user = PublicApi.Users.AccessingUser; try { PreferredUserStatus userStatus; if (!Enum.TryParse(req.Form["userStatus"], out userStatus)) { throw new ArgumentNullException("userStatus", "UserStatus not specified or has an invalid value. Allowed values - 'Away', 'BeRightBack', 'Busy', 'DoNotDisturb', 'Offwork', 'Online'"); } _lyncCommunicationService.SetCurrentUserStatus(userStatus); response.Data = new { status = _lyncCommunicationService.GetCurrentUserStatus().ToString(), userid = user.Id.GetValueOrDefault() }; return(response); } catch (Exception ex) { response.Errors = new[] { ex.Message }; return(response); } }, new RestEndpointDocumentation { EndpointDocumentation = new RestEndpointDocumentationAttribute { Resource = "UserStatus", Action = "Set Current User Status" }, RequestDocumentation = new List <RestRequestDocumentationAttribute> { new RestRequestDocumentationAttribute { Name = "UserStatus", Type = typeof(PreferredUserStatus), Description = "New status of the user. Allowed values - 'Away', 'BeRightBack', 'Busy', 'DoNotDisturb', 'Offwork', 'Online'", Required = RestRequired.Required } }, ResponseDocumentation = new RestResponseDocumentationAttribute { Name = "UserStatus", Description = "User Status. Can be one of the list - 'Away', 'BeRightBack', 'Busy', 'DoNotDisturb', 'IdleBusy', 'IdleOnline', 'Offwork', 'Online' or 'Offline'", Type = typeof(UserStatus) } }); }
public void Register(IRestEndpointController controller) { controller.Add(2, "sharepoint/integration/managers", new { }, new { }, HttpMethod.Get, request => IntegrationManagerControllerHelper.List(new IntegrationManagerListRequest(request))); controller.Add(2, "sharepoint/integration/managers/{managerId}", new { }, new { }, HttpMethod.Get, request => IntegrationManagerControllerHelper.Get(new IntegrationManagerRequest(request))); controller.Add(2, "sharepoint/integration/{groupId}/manager", new { }, new { groupid = @"\d+" }, HttpMethod.Get, request => IntegrationManagerControllerHelper.Get(new IntegrationManagerRequest(request))); }
public void Register(IRestEndpointController controller) { #region Poll Endpoints controller.Add(2, "groups/{groupid}/polls", null, new { groupid = @"\d+" }, HttpMethod.Get, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "Polls"; try { int pageSize; int pageIndex; string sortBy = "Date"; if (!int.TryParse(request.Request.QueryString["PageSize"], out pageSize)) pageSize = 20; if (!int.TryParse(request.Request.QueryString["PageIndex"], out pageIndex)) pageIndex = 0; if (request.Request.QueryString["SortBy"] != null) sortBy = request.Request.QueryString["SortBy"]; if (sortBy == "TopPollsScore") { var group = TEApi.Groups.Get(new GroupsGetOptions { Id = Convert.ToInt32(request.PathParameters["groupid"]) }); if (group == null || group.HasErrors()) response.Data = new Telligent.Evolution.Extensibility.Rest.Entities.Version1.PagedList<RestApi.Poll>(); else { var scores = TEApi.CalculatedScores.List(Plugins.TopPollsScore.ScoreId, new CalculatedScoreListOptions { ApplicationId = group.ApplicationId, ContentTypeId = PublicApi.Polls.ContentTypeId, PageIndex = pageIndex, PageSize = pageSize, SortOrder = "Descending" }); var polls = new List<RestApi.Poll>(); foreach (var score in scores) { if (score.Content != null) { var poll = InternalApi.PollingService.GetPoll(score.Content.ContentId); if (poll != null) polls.Add(new RestApi.Poll(poll)); } } response.Data = new Telligent.Evolution.Extensibility.Rest.Entities.Version1.PagedList<RestApi.Poll>(polls, scores.PageSize, scores.PageIndex, scores.TotalCount); } } else { var polls = InternalApi.PollingService.ListPolls(Convert.ToInt32(request.PathParameters["groupid"]), new PublicApi.PollsListOptions() { PageIndex = pageIndex, PageSize = pageSize, SortBy = sortBy }); response.Data = new Telligent.Evolution.Extensibility.Rest.Entities.Version1.PagedList<RestApi.Poll>(polls.Select(x => new RestApi.Poll(x)), polls.PageSize, polls.PageIndex, polls.TotalCount); } } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return response; }); controller.Add(2, "polls/poll", HttpMethod.Get, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "Poll"; try { Guid pollId; if (!Guid.TryParse(request.Request.QueryString["Id"], out pollId)) throw new ArgumentException("Id is required."); var poll = InternalApi.PollingService.GetPoll(pollId); if (poll == null) throw new Exception("The poll does not exist."); response.Data = new RestApi.Poll(poll); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return response; }); controller.Add(2, "polls/poll", HttpMethod.Delete, (IRestRequest request) => { var response = new RestApi.RestResponse(); try { Guid pollId; if (!Guid.TryParse(request.Request.QueryString["Id"], out pollId)) throw new ArgumentException("Id is required."); var poll = InternalApi.PollingService.GetPoll(pollId); if (poll != null) InternalApi.PollingService.DeletePoll(poll); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return response; }); controller.Add(2, "polls/poll", HttpMethod.Post, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "Poll"; try { // Create int groupId; if (!int.TryParse(request.Form["GroupId"], out groupId)) throw new ArgumentException("GroupId is required."); var group = TEApi.Groups.Get(new GroupsGetOptions() { Id = groupId }); if (group == null) throw new ArgumentException("Group not found"); string name = request.Form["Name"] ?? string.Empty; string description = request.Form["Description"]; bool hideResultsUntilVotingComplete = request.Form["HideResultsUntilVotingComplete"] == null ? false : Convert.ToBoolean(request.Form["HideResultsUntilVotingComplete"]); DateTime? votingEndDate = request.Form["VotingEndDate"] == null ? null : (DateTime?)InternalApi.Formatting.FromUserTimeToUtc(DateTime.Parse(request.Form["VotingEndDate"])); var poll = new InternalApi.Poll(); poll.ApplicationId = group.ApplicationId; poll.Name = name; poll.Description = description; poll.IsEnabled = true; poll.AuthorUserId = request.UserId; poll.HideResultsUntilVotingComplete = hideResultsUntilVotingComplete; poll.VotingEndDateUtc = votingEndDate; InternalApi.PollingService.AddUpdatePoll(poll); poll = InternalApi.PollingService.GetPoll(poll.Id); response.Data = new RestApi.Poll(poll); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return response; }); controller.Add(2, "polls/poll", HttpMethod.Put, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "Poll"; try { // Update Guid pollId; if (!Guid.TryParse(request.Request.QueryString["Id"], out pollId)) throw new ArgumentException("Id is required."); string name = request.Form["Name"]; string description = request.Form["Description"]; var poll = InternalApi.PollingService.GetPoll(pollId); if (poll == null) throw new Exception("The poll does not exist."); if (request.Form["HideResultsUntilVotingComplete"] != null) poll.HideResultsUntilVotingComplete = Convert.ToBoolean(request.Form["HideResultsUntilVotingComplete"]); if (request.Form["VotingEndDate"] != null) poll.VotingEndDateUtc = (DateTime?) InternalApi.Formatting.FromUserTimeToUtc(Convert.ToDateTime(request.Form["VotingEndDate"])); else if (request.Form["ClearVotingEndDate"] != null && Convert.ToBoolean(request.Form["ClearVotingEndDate"])) poll.VotingEndDateUtc = null; if (name != null) poll.Name = name; if (description != null) poll.Description = description; InternalApi.PollingService.AddUpdatePoll(poll); poll = InternalApi.PollingService.GetPoll(poll.Id); response.Data = new RestApi.Poll(poll); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return response; }); #endregion #region Poll Answer Endpoints controller.Add(2, "polls/answer", HttpMethod.Get, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "PollAnswer"; try { Guid pollAnswerId; if (!Guid.TryParse(request.Request.QueryString["Id"], out pollAnswerId)) throw new ArgumentException("Id is required."); var pollAnswer = InternalApi.PollingService.GetPollAnswer(pollAnswerId); if (pollAnswer == null) throw new Exception("The poll answer does not exist."); var poll = InternalApi.PollingService.GetPoll(pollAnswer.PollId); if (poll == null) throw new Exception("The poll does not exist."); response.Data = new RestApi.PollAnswer(pollAnswer, poll); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return response; }); controller.Add(2, "polls/answer", HttpMethod.Delete, (IRestRequest request) => { var response = new RestApi.RestResponse(); try { Guid pollAnswerId; if (!Guid.TryParse(request.Request.QueryString["Id"], out pollAnswerId)) throw new ArgumentException("Id is required."); var pollAnswer = InternalApi.PollingService.GetPollAnswer(pollAnswerId); if (pollAnswer != null) InternalApi.PollingService.DeletePollAnswer(pollAnswer); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return response; }); controller.Add(2, "polls/answer", HttpMethod.Post, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "PollAnswer"; try { // Create Guid pollId; if (!Guid.TryParse(request.Form["PollId"], out pollId)) throw new ArgumentException("PollId is required."); string name = request.Form["Name"] ?? string.Empty; var pollAnswer = new InternalApi.PollAnswer(); pollAnswer.PollId = pollId; pollAnswer.Name = name; InternalApi.PollingService.AddUpdatePollAnswer(pollAnswer); pollAnswer = InternalApi.PollingService.GetPollAnswer(pollAnswer.Id); var poll = InternalApi.PollingService.GetPoll(pollAnswer.PollId); response.Data = new RestApi.PollAnswer(pollAnswer, poll); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return response; }); controller.Add(2, "polls/answer", HttpMethod.Put, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "PollAnswer"; try { // Update Guid pollAnswerId; if (!Guid.TryParse(request.Request.QueryString["Id"], out pollAnswerId)) throw new ArgumentException("Id is required."); string name = request.Form["Name"]; var pollAnswer = InternalApi.PollingService.GetPollAnswer(pollAnswerId); if (pollAnswer == null) throw new Exception("The poll answer does not exist."); if (name != null) pollAnswer.Name = name; InternalApi.PollingService.AddUpdatePollAnswer(pollAnswer); pollAnswer = InternalApi.PollingService.GetPollAnswer(pollAnswer.Id); var poll = InternalApi.PollingService.GetPoll(pollAnswer.PollId); response.Data = new RestApi.PollAnswer(pollAnswer, poll); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return response; }); #endregion #region Poll Voting Endpoints controller.Add(2, "polls/vote", HttpMethod.Get, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "PollVote"; try { Guid pollId; if (!Guid.TryParse(request.Request.QueryString["PollId"], out pollId)) throw new ArgumentException("PollId is required."); var poll = InternalApi.PollingService.GetPoll(pollId); if (poll == null) throw new Exception("The poll does not exist."); var vote = InternalApi.PollingService.GetPollVote(pollId, request.UserId); if (vote != null) response.Data = new RestApi.PollVote(vote); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return response; }); controller.Add(2, "polls/vote", HttpMethod.Delete, (IRestRequest request) => { var response = new RestApi.RestResponse(); try { Guid pollId; if (!Guid.TryParse(request.Form["PollId"], out pollId)) throw new ArgumentException("PollId is required."); var vote = InternalApi.PollingService.GetPollVote(pollId, request.UserId); if (vote != null) InternalApi.PollingService.DeletePollVote(vote); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return response; }); controller.Add(2, "polls/vote", HttpMethod.Post, (IRestRequest request) => { var response = new RestApi.RestResponse(); response.Name = "PollVote"; try { // Create Guid pollId; if (!Guid.TryParse(request.Form["PollId"], out pollId)) throw new ArgumentException("PollId is required."); Guid pollAnswerId; if (!Guid.TryParse(request.Form["PollAnswerId"], out pollAnswerId)) throw new ArgumentException("PollAnswerId is required."); var pollVote = new InternalApi.PollVote(); pollVote.PollId = pollId; pollVote.PollAnswerId = pollAnswerId; pollVote.UserId = request.UserId; InternalApi.PollingService.AddUpdatePollVote(pollVote); pollVote = InternalApi.PollingService.GetPollVote(pollId, request.UserId); response.Data = new RestApi.PollVote(pollVote); } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } return response; }); #endregion }
public void Register(IRestEndpointController restRoutes) { restRoutes.Add(2, "mobile/pushnotifications/registration", HttpMethod.Put, request => GetRestResponse(request, true, (userId, token, device) => _deviceRegistrationService.RegisterDevice(userId.Value, token, device))); restRoutes.Add(2, "mobile/pushnotifications/registration", HttpMethod.Delete, request => GetRestResponse(request, false, (userId, token, device) => _deviceRegistrationService.UnregisterDevice(userId, token, device))); }