Exemplo n.º 1
0
        public void UnlikeTopic(TopicLike topicLike)
        {
            string query = @"DELETE FROM TopicLikes 
                             WHERE TopicID = @TopicID 
                             AND UserID = @UserID";

            _connection.Execute(query, new { topicLike.TopicID, topicLike.UserID });
        }
Exemplo n.º 2
0
        public TopicDTO LikeTopic(TopicLike topicLike)
        {
            string query = @"INSERT INTO TopicLikes (TopicID, UserID)
                             values(@TopicID, @UserID)
                             SELECT * 
                             FROM Topics 
                             WHERE Topics.ID = @TopicID";
            var    topic = _connection.Query <TopicDTO>(query, new { topicLike.TopicID, topicLike.UserID }).FirstOrDefault();

            return(topic);
        }
Exemplo n.º 3
0
        protected void btnUnlike_Click(object sender, EventArgs e)
        {
            var currentUser = _authenticationService.GetAuthenticatedUser();
            int topicID     = Convert.ToInt32(Page.RouteData.Values["id"]);

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

            var topicLike = new TopicLike(topicID, currentUser.Id);

            _topicService.UnlikeTopic(topicLike);

            btnUnlike.Style.Add("display", "none");
            btnLike.Style.Add("display", "inline-block");
            var num = int.Parse(btnlikeNum.Text);

            btnlikeNum.Text = (num - 1).ToString();
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Post([FromBody] TopicLike model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!await MatchAppUserWithToken(model.SupportAppUserId))
            {
                return(Unauthorized());
            }

            if (!await _repo.AppUserExist(model.SupportAppUserId))
            {
                return(NotFound());
            }

            if (!await _repo.DailyTopicExists(model.DailyTopicId))
            {
                return(NotFound());
            }

            var topicLike = await this._repo.GetTopicLike(model.SupportAppUserId, model.DailyTopicId);

            if (topicLike != null)
            {
                return(BadRequest("既にリアクションされています"));
            }

            _repo.Add(model);
            if (await _repo.SaveAll() > 0)
            {
                return(CreatedAtRoute("GetTopicLike", new { userId = model.SupportAppUserId, recordId = model.DailyTopicId }, _mapper.Map <TopicLikeForReturnDto>(model)));
            }
            return(BadRequest("Failed to post topic like"));
        }
Exemplo n.º 5
0
        protected void btnLike_Click(object sender, EventArgs e)
        {
            var currentUser = _authenticationService.GetAuthenticatedUser();
            int topicID     = Convert.ToInt32(Page.RouteData.Values["id"]);

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

            var topicLike = new TopicLike(topicID, currentUser.Id);

            var          topic        = _topicService.LikeTopic(topicLike);
            string       message      = $@"<strong>{currentUser.FullName}<strong> liked your topic <a href='/topic/{topicID}'>{topic.Title}</a>.";
            Notification notification = new Notification(topic.CreatorID, message, DateTime.Now);

            _notificationService.CreateNotification(notification);

            btnLike.Style.Add("display", "none");
            btnUnlike.Style.Add("display", "inline-block");
            var num = int.Parse(btnlikeNum.Text);

            btnlikeNum.Text = (num + 1).ToString();
        }