示例#1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            var currentUser = _authenticationService.GetAuthenticatedUser();
            var description = Server.HtmlEncode(txtDescription.Text);

            description = txtDescription.Text;
            var topic = new DiscussionForum.Domain.DomainModel.Topic(currentUser.Id, int.Parse(ddlCategories.SelectedItem.Value), txtTitle.Text, description);

            int topicId = _topicService.CreateTopic(topic);

            if (topicId == -1)
            {
                error.InnerText = "A topic with this title already exists, please check it out, and rename your topic if necessary.";
            }
            else
            {
                var topicFollower = new TopicFollower(topicId, currentUser.Id);
                _topicService.FollowTopic(topicFollower);

                var category = _categoryService.GetCategoryById(topic.CategoryID);

                string message = $@"<strong>{currentUser.FullName}</strong> created new topic <a href='/topic/{topic.ID}'>{topic.Title}</a> in category <a href='/category/'{category.ID}'>{category.Name}</a>.";

                var followers = _categoryService.GetFollowers(category.ID);

                foreach (var follower in followers)
                {
                    Notification notification = new Notification(follower.FollowerID, message, DateTime.Now);
                    _notificationService.CreateNotification(notification);
                }

                Response.RedirectToRoute("TopicRoute", new { id = topicId });
            }
        }
示例#2
0
        public void FollowTopic(TopicFollower topicFollower)
        {
            string query = @"INSERT INTO TopicFollowers (TopicID, FollowerID)
                             values(@TopicID, @FollowerID)";

            _connection.Execute(query, new { topicFollower.TopicID, topicFollower.FollowerID });
        }
示例#3
0
        public void UnfollowTopic(TopicFollower topicFollower)
        {
            string query = @"DELETE FROM TopicFollowers 
                             WHERE TopicID = @TopicID 
                             AND FollowerID = @FollowerID";

            _connection.Execute(query, new { topicFollower.TopicID, topicFollower.FollowerID });
        }
示例#4
0
        protected void btnUnfollow_Click(object sender, EventArgs e)
        {
            var currentUser = _authenticationService.GetAuthenticatedUser();
            int topicID     = Convert.ToInt32(Page.RouteData.Values["id"]);

            if (currentUser == null)
            {
                redirectToLogin(Request.RawUrl);
            }

            var topicFollower = new TopicFollower(topicID, currentUser.Id);

            _topicService.UnfollowTopic(topicFollower);

            btnUnfollow.Style.Add("display", "none");
            btnFollow.Style.Add("display", "inline-block");
            var num = int.Parse(Followers.InnerText);

            Followers.InnerText = (num - 1).ToString();
        }