public async Task <UnifyResponseDto> CreateOrCancelAsync([FromBody] CreateUpdateUserLikeDto createUpdateUserLike) { string message = await _userLikeService.CreateOrCancelAsync(createUpdateUserLike); await this.PublishUserLikeNotification(createUpdateUserLike); return(UnifyResponseDto.Success(message)); }
public void Create() { CreateUpdateUserLikeDto createUpdateUserLike = new CreateUpdateUserLikeDto() { SubjectId = new Guid("5e63dcd7-6e39-36e0-0001-059272461091"), SubjectType = UserLikeSubjectType.UserLikeComment }; }
public async Task <UnifyResponseDto> CreateOrCancelAsync([FromBody] CreateUpdateUserLikeDto createUpdateUserLike) { using IUnitOfWork unitOfWork = _unitOfWorkManager.Begin(); using ICapTransaction trans = unitOfWork.BeginTransaction(_capBus, false); bool isCancel = await _userLikeService.CreateOrCancelAsync(createUpdateUserLike); await PublishUserLikeNotification(createUpdateUserLike, isCancel); trans.Commit(); return(UnifyResponseDto.Success(isCancel == false? "点赞成功": "已取消点赞")); }
public async Task <string> CreateOrCancelAsync(CreateUpdateUserLikeDto createUpdateUserLike) { Expression <Func <UserLike, bool> > predicate = r => r.SubjectId == createUpdateUserLike.SubjectId && r.CreateUserId == _currentUser.Id; bool exist = await _userLikeRepository.Select.AnyAsync(predicate); int increaseLikeQuantity = 1; if (exist) { increaseLikeQuantity = -1; await _userLikeRepository.DeleteAsync(predicate); } switch (createUpdateUserLike.SubjectType) { case UserLikeSubjectType.UserLikeArticle: await _articleService.UpdateLikeQuantity(createUpdateUserLike.SubjectId, increaseLikeQuantity); break; case UserLikeSubjectType.UserLikeComment: await _commentService.UpdateLikeQuantity(createUpdateUserLike.SubjectId, increaseLikeQuantity); break; } if (exist) { return("取消点赞成功"); } UserLike userLike = _mapper.Map <UserLike>(createUpdateUserLike); _userLikeRepository.Insert(userLike); return("点赞成功"); }
public ResultDto Post([FromBody] CreateUpdateUserLikeDto createUpdateUserLike) { Expression <Func <UserLike, bool> > predicate = r => r.SubjectId == createUpdateUserLike.SubjectId && r.CreateUserId == _currentUser.Id; bool exist = _userLikeRepository.Select.Any(predicate); if (exist) { _userLikeRepository.Delete(predicate); switch (createUpdateUserLike.SubjectType) { case 1: this.UpdateArticleLike(createUpdateUserLike.SubjectId, -1); break; case 2: this.UpdateCommentLike(createUpdateUserLike.SubjectId, -1); break; } return(ResultDto.Success("取消点赞成功")); } UserLike userLike = _mapper.Map <UserLike>(createUpdateUserLike); _userLikeRepository.Insert(userLike); switch (createUpdateUserLike.SubjectType) { case 1: this.UpdateArticleLike(createUpdateUserLike.SubjectId, 1); break; case 2: this.UpdateCommentLike(createUpdateUserLike.SubjectId, 1); break; } return(ResultDto.Success("点赞成功")); }
public ResultDto Post([FromBody] CreateUpdateUserLikeDto createUpdateUserLike) { Expression <Func <UserLike, bool> > predicate = r => r.SubjectId == createUpdateUserLike.SubjectId && r.CreateUserId == _currentUser.Id; bool exist = _userLikeRepository.Select.Any(predicate); if (exist) { _userLikeRepository.Delete(predicate); switch (createUpdateUserLike.SubjectType) { case 1: _articleAuditBaseRepository.UpdateDiy.Set(r => r.LikesQuantity - 1).Where(r => r.Id == createUpdateUserLike.SubjectId).ExecuteAffrows(); break; case 2: _commentRepository.UpdateDiy.Set(r => r.LikesQuantity - 1).Where(r => r.Id == createUpdateUserLike.SubjectId).ExecuteAffrows(); break; } return(ResultDto.Success("取消点赞成功")); } UserLike userLike = _mapper.Map <UserLike>(createUpdateUserLike); _userLikeRepository.Insert(userLike); switch (createUpdateUserLike.SubjectType) { case 1: _articleAuditBaseRepository.UpdateDiy.Set(r => r.LikesQuantity + 1).Where(r => r.Id == createUpdateUserLike.SubjectId).ExecuteAffrows(); break; case 2: _commentRepository.UpdateDiy.Set(r => r.LikesQuantity + 1).Where(r => r.Id == createUpdateUserLike.SubjectId).ExecuteAffrows(); break; } return(ResultDto.Success("点赞成功")); }
private void PublishUserLikeNotification(CreateUpdateUserLikeDto createUpdateUserLike) { //根据用户点赞类型:文章、评论,得到消息的NotificationRespUserId的值 var createNotificationDto = new CreateNotificationDto() { UserInfoId = _currentUser.Id ?? 0, CreateTime = DateTime.Now, }; switch (createUpdateUserLike.SubjectType) { case UserLikeSubjectType.UserLikeArticle: Article subjectArticle = _articleAuditBaseRepository.Where(r => r.Id == createUpdateUserLike.SubjectId).ToOne(); createNotificationDto.NotificationRespUserId = subjectArticle.CreateUserId; createNotificationDto.NotificationType = NotificationType.UserLikeArticle; createNotificationDto.ArticleId = createUpdateUserLike.SubjectId; break; case UserLikeSubjectType.UserLikeComment: Comment subjectComment = _commentRepository.Where(r => r.Id == createUpdateUserLike.SubjectId).ToOne(); createNotificationDto.NotificationRespUserId = subjectComment.CreateUserId; createNotificationDto.NotificationType = NotificationType.UserLikeArticleComment; createNotificationDto.ArticleId = subjectComment.SubjectId; createNotificationDto.CommentId = createUpdateUserLike.SubjectId; break; } if (createNotificationDto.NotificationRespUserId != 0 && _currentUser.Id != createNotificationDto.NotificationRespUserId) { using ICapTransaction trans = UnitOfWork.BeginTransaction(_capBus, false); _capBus.Publish("NotificationController.Post", createNotificationDto); trans.Commit(); } }
/// <summary> /// 根据用户点赞类型:文章、评论,得到消息的NotificationRespUserId的值 /// </summary> /// <param name="createUpdateUserLike"></param> /// <returns></returns> private async Task PublishUserLikeNotification(CreateUpdateUserLikeDto createUpdateUserLike) { var createNotificationDto = new CreateNotificationDto() { UserInfoId = _currentUser.Id ?? 0, CreateTime = DateTime.Now, }; switch (createUpdateUserLike.SubjectType) { case UserLikeSubjectType.UserLikeArticle: Article subjectArticle = await _articleRepository.Where(r => r.Id == createUpdateUserLike.SubjectId).ToOneAsync(); createNotificationDto.NotificationRespUserId = subjectArticle.CreateUserId; createNotificationDto.NotificationType = NotificationType.UserLikeArticle; createNotificationDto.ArticleId = createUpdateUserLike.SubjectId; break; case UserLikeSubjectType.UserLikeComment: Comment subjectComment = await _commentRepository.Where(r => r.Id == createUpdateUserLike.SubjectId).ToOneAsync(); createNotificationDto.NotificationRespUserId = subjectComment.CreateUserId; createNotificationDto.NotificationType = NotificationType.UserLikeArticleComment; createNotificationDto.ArticleId = subjectComment.SubjectId; createNotificationDto.CommentId = createUpdateUserLike.SubjectId; break; } // if (createNotificationDto.NotificationRespUserId != 0 && _currentUser.Id != createNotificationDto.NotificationRespUserId) // { // using ICapTransaction trans = _unitOfWorkManager.Current.BeginTransaction(_capBus, false); // // _capBus.Publish("NotificationController.Post", createNotificationDto); // // trans.Commit(); // } }
public UnifyResponseDto Create([FromBody] CreateUpdateUserLikeDto createUpdateUserLike) { Expression <Func <UserLike, bool> > predicate = r => r.SubjectId == createUpdateUserLike.SubjectId && r.CreateUserId == _currentUser.Id; bool exist = _userLikeRepository.Select.Any(predicate); int increaseLikeQuantity = 1; if (exist) { increaseLikeQuantity = -1; _userLikeRepository.Delete(predicate); } switch (createUpdateUserLike.SubjectType) { case UserLikeSubjectType.UserLikeArticle: this.UpdateArticleLike(createUpdateUserLike.SubjectId, increaseLikeQuantity); break; case UserLikeSubjectType.UserLikeComment: this.UpdateCommentLike(createUpdateUserLike.SubjectId, increaseLikeQuantity); break; } if (exist) { return(UnifyResponseDto.Success("取消点赞成功")); } UserLike userLike = _mapper.Map <UserLike>(createUpdateUserLike); _userLikeRepository.Insert(userLike); this.PublishUserLikeNotification(createUpdateUserLike); return(UnifyResponseDto.Success("点赞成功")); }
/// <summary> /// 根据用户点赞类型:文章、评论,得到消息的NotificationRespUserId的值 /// </summary> /// <param name="createUpdateUserLike"></param> /// <returns></returns> private async Task PublishUserLikeNotification(CreateUpdateUserLikeDto createUpdateUserLike, bool isCancel) { var createNotificationDto = new CreateNotificationDto() { UserInfoId = _currentUser.Id ?? 0, CreateTime = DateTime.Now, IsCancel = isCancel }; switch (createUpdateUserLike.SubjectType) { case UserLikeSubjectType.UserLikeArticle: Article subjectArticle = await _articleRepository.Where(r => r.Id == createUpdateUserLike.SubjectId).ToOneAsync(); createNotificationDto.NotificationRespUserId = subjectArticle.CreateUserId; createNotificationDto.NotificationType = NotificationType.UserLikeArticle; createNotificationDto.ArticleId = createUpdateUserLike.SubjectId; break; case UserLikeSubjectType.UserLikeComment: Comment subjectComment = await _commentRepository.Where(r => r.Id == createUpdateUserLike.SubjectId).ToOneAsync(); createNotificationDto.NotificationRespUserId = subjectComment.CreateUserId; createNotificationDto.NotificationType = NotificationType.UserLikeArticleComment; createNotificationDto.ArticleId = subjectComment.SubjectId; createNotificationDto.CommentId = createUpdateUserLike.SubjectId; break; } if (createNotificationDto.NotificationRespUserId != 0 && _currentUser.Id != createNotificationDto.NotificationRespUserId) { await _capBus.PublishAsync("NotificationController.Post", createNotificationDto); } }