public void UnlikeTopic(TopicLike topicLike) { string query = @"DELETE FROM TopicLikes WHERE TopicID = @TopicID AND UserID = @UserID"; _connection.Execute(query, new { topicLike.TopicID, topicLike.UserID }); }
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); }
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(); }
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")); }
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(); }