diff --git a/NotificationsWeb/Api/NotificationsController.cs b/NotificationsWeb/Api/NotificationsController.cs new file mode 100644 index 00000000..5142ee37 --- /dev/null +++ b/NotificationsWeb/Api/NotificationsController.cs @@ -0,0 +1,65 @@ +using System.Linq; +using System.Web.Http; +using Umbraco.Web.WebApi; + +namespace NotificationsWeb.Api +{ + public class NotificationsController:UmbracoApiController + { + [HttpGet] + public string SubscribeToForumTopic(int topicId) + { + var currentMemberId = Members.GetCurrentMember().Id; + if (currentMemberId > 0) + { + BusinessLogic.ForumTopic.Subscribe(topicId, currentMemberId); + + return "true"; + } + + return "false"; + } + + [HttpGet] + public string UnSubscribeFromForumTopic(int topicId) + { + var currentMemberId = Members.GetCurrentMember().Id; + if (currentMemberId > 0) + { + BusinessLogic.ForumTopic.UnSubscribe(topicId, currentMemberId); + + return "true"; + } + + return "false"; + } + + [HttpGet] + public string SubscribeToForum(int forumId) + { + var currentMemberId = Members.GetCurrentMember().Id; + if (currentMemberId > 0) + { + BusinessLogic.Forum.Subscribe(forumId, currentMemberId); + + return "true"; + } + + return "false"; + } + + [HttpGet] + public string UnSubscribeFromForum(int forumId) + { + var currentMemberId = Members.GetCurrentMember().Id; + if (currentMemberId > 0) + { + BusinessLogic.Forum.UnSubscribe(forumId, currentMemberId); + + return "true"; + } + + return "false"; + } + } +} diff --git a/NotificationsWeb/Library/Rest.cs b/NotificationsWeb/Library/Rest.cs deleted file mode 100644 index 6a262f4d..00000000 --- a/NotificationsWeb/Library/Rest.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Security; - -namespace NotificationsWeb.Library -{ - public class Rest - { - public static string SubscribeToForumTopic(int topicId) - { - int _currentMember = HttpContext.Current.User.Identity.IsAuthenticated ? (int)Membership.GetUser().ProviderUserKey : 0; - - if (_currentMember > 0) - { - BusinessLogic.ForumTopic.Subscribe(topicId, _currentMember); - - return "true"; - } - - return "false"; - } - - - public static string UnSubscribeFromForumTopic(int topicId) - { - int _currentMember = HttpContext.Current.User.Identity.IsAuthenticated ? (int)Membership.GetUser().ProviderUserKey : 0; - - if (_currentMember > 0) - { - BusinessLogic.ForumTopic.UnSubscribe(topicId, _currentMember); - - return "true"; - } - - return "false"; - } - - public static string SubscribeToForum(int forumId) - { - int _currentMember = HttpContext.Current.User.Identity.IsAuthenticated ? (int)Membership.GetUser().ProviderUserKey : 0; - - if (_currentMember > 0) - { - BusinessLogic.Forum.Subscribe(forumId, _currentMember); - - return "true"; - } - - return "false"; - } - - - public static string UnSubscribeFromForum(int forumId) - { - int _currentMember = HttpContext.Current.User.Identity.IsAuthenticated ? (int)Membership.GetUser().ProviderUserKey : 0; - - if (_currentMember > 0) - { - BusinessLogic.Forum.UnSubscribe(forumId, _currentMember); - - return "true"; - } - - return "false"; - } - } -} diff --git a/NotificationsWeb/NotificationsWeb.csproj b/NotificationsWeb/NotificationsWeb.csproj index 03c49889..ba446da5 100644 --- a/NotificationsWeb/NotificationsWeb.csproj +++ b/NotificationsWeb/NotificationsWeb.csproj @@ -225,12 +225,12 @@ + - SheduledTaskTrigger.aspx diff --git a/OurUmbraco.Site/scripts/notifications/notifications.js b/OurUmbraco.Site/scripts/notifications/notifications.js index 4c942679..e86dbdd8 100644 --- a/OurUmbraco.Site/scripts/notifications/notifications.js +++ b/OurUmbraco.Site/scripts/notifications/notifications.js @@ -1,12 +1,12 @@ function SubscribeToForum(forumId){ - $.get("/base/Notifications/SubscribeToForum/" + forumId + ".aspx"); + $.get("/umbraco/api/Notifications/SubscribeToForum/?forumId=" + forumId); jQuery(".SubscribeForum").hide("slow"); jQuery(".UnSubscribeForum").show("slow"); } function UnSubscribeFromForum(forumId){ - $.get("/base/Notifications/UnSubscribeFromForum/" + forumId + ".aspx"); + $.get("/umbraco/api/Notifications/UnSubscribeFromForum/?forumId=" + forumId); jQuery(".UnSubscribeForum").hide("slow"); jQuery(".SubscribeForum").show("slow"); @@ -14,14 +14,14 @@ function UnSubscribeFromForum(forumId){ function SubscribeToForumTopic(topicId){ - $.get("/base/Notifications/SubscribeToForumTopic/" + topicId + ".aspx"); + $.get("/umbraco/api/Notifications/SubscribeToForumTopic/?topicId=" + topicId); jQuery(".SubscribeTopic").hide("slow"); jQuery(".UnSubscribeTopic").show("slow"); } function UnSubscribeFromForumTopic(topicId){ - $.get("/base/Notifications/UnSubscribeFromForumTopic/" + topicId + ".aspx"); + $.get("/umbraco/api/Notifications/UnSubscribeFromForumTopic/?topicId=" + topicId); jQuery(".UnSubscribeTopic").hide("slow"); jQuery(".SubscribeTopic").show("slow"); @@ -30,13 +30,13 @@ function UnSubscribeFromForumTopic(topicId){ function NotificationTopicUnsubscribe(obj, topicId) { - $.get("/base/Notifications/UnSubscribeFromForumTopic/" + topicId + ".aspx"); + $.get("/umbraco/api/Notifications/UnSubscribeFromForumTopic/?topicId=" + topicId); obj.parent().hide("slow"); } function NotificationForumUnsubscribe(obj, forumId) { - $.get("/base/Notifications/UnSubscribeFromForum/" + forumId + ".aspx"); + $.get("/umbraco/api/Notifications/UnSubscribeFromForum/?forumId=" + forumId); obj.parent().hide("slow"); } diff --git a/uForum/Api/ForumController.cs b/uForum/Api/ForumController.cs index 912d6d36..30bf1e73 100644 --- a/uForum/Api/ForumController.cs +++ b/uForum/Api/ForumController.cs @@ -25,13 +25,14 @@ namespace uForum.Api { var node = new Node(forumId); - if (Members.GetCurrentMember().Id > 0 && Access.HasAccces(node.Id, Members.GetCurrentMember().Id)) + var currentMemberId = Members.GetCurrentMember().Id; + if (currentMemberId > 0 && Access.HasAccces(node.Id, currentMemberId)) { var title = HttpContext.Current.Request["title"]; var body = HttpContext.Current.Request["body"]; var tags = HttpContext.Current.Request["tags"]; - var topic = Businesslogic.Topic.Create(forumId, title, body, Members.GetCurrentMember().Id); + var topic = Businesslogic.Topic.Create(forumId, title, body, currentMemberId); return Xslt.NiceTopicUrl(topic.Id); } @@ -61,10 +62,11 @@ namespace uForum.Api [HttpPost] public string NewComment(int topicId, int itemsPerPage) { - if (Members.GetCurrentMember().Id > 0 && topicId > 0) + var currentMemberId = Members.GetCurrentMember().Id; + if (currentMemberId > 0 && topicId > 0) { var body = HttpContext.Current.Request["body"]; - var comment = Businesslogic.Comment.Create(topicId, body, Members.GetCurrentMember().Id); + var comment = Businesslogic.Comment.Create(topicId, body, currentMemberId); return Xslt.NiceCommentUrl(comment.TopicId, comment.Id, itemsPerPage); } diff --git a/uPowers/Api/PowersController.cs b/uPowers/Api/PowersController.cs index 9132522f..3fc9ee5a 100644 --- a/uPowers/Api/PowersController.cs +++ b/uPowers/Api/PowersController.cs @@ -12,10 +12,11 @@ namespace uPowers.Api { var comment = HttpContext.Current.Request["comment"] + ""; - if (Members.GetCurrentMember().Id > 0) + var currentMemberId = Members.GetCurrentMember().Id; + if (currentMemberId > 0) { var action = new BusinessLogic.Action(alias); - return action.Perform(Members.GetCurrentMember().Id, pageId, comment).ToString(); + return action.Perform(currentMemberId, pageId, comment).ToString(); } return "notLoggedIn";