public void Post(Guid tagId)
        {
            Tag tag = _tagRepository.Select.Where(r => r.Id == tagId).ToOne();

            if (tag == null)
            {
                throw new LinCmsException("该标签不存在");
            }

            if (!tag.Status)
            {
                throw new LinCmsException("该标签已被拉黑");
            }

            bool any = _userTagRepository.Select.Any(r =>
                                                     r.CreateUserId == _currentUser.Id && r.TagId == tagId);

            if (any)
            {
                throw new LinCmsException("您已关注该标签");
            }

            UserTag userTag = new UserTag()
            {
                TagId = tagId
            };

            _userTagRepository.Insert(userTag);

            _tagService.UpdateSubscribersCount(tagId, 1);
        }
        public UnifyResponseDto Post([FromBody] CreateUpdatePoemDto createPoem)
        {
            LinPoem poem = _mapper.Map <LinPoem>(createPoem);

            _poemRepository.Insert(poem);
            return(UnifyResponseDto.Success("新建诗词成功"));
        }
        public void CreateLog(LinLog linlog)
        {
            linlog.Time     = DateTime.Now;
            linlog.UserName = _currentUser.UserName;
            linlog.UserId   = _currentUser.Id ?? 0;

            _linLogRepository.Insert(linlog);
        }
        public void Post()
        {
            Comment comment = new Comment()
            {
                Text = "😃😃😃😃"
            };

            _baseRepository.Insert(comment);
        }
Example #5
0
        public async Task <UnifyResponseDto> LogoutAsync()
        {
            var    username = User.FindUserName();
            string?Jti      = await HttpContext.GetTokenAsync("Bearer", "access_token");

            //string Jti = Request.Headers["Authorization"].ToString().Substring(JwtBearerDefaults.AuthenticationScheme.Length + 1).Trim();
            _blackRecordRepository.Insert(new BlackRecord {
                Jti = Jti, UserName = username
            });
            return(UnifyResponseDto.Success("退出登录"));
        }
Example #6
0
        public UnifyResponseDto Post([FromBody] CreateUpdateClassifyDto createClassify)
        {
            bool exist = _classifyRepository.Select.Any(r => r.ClassifyName == createClassify.ClassifyName && r.CreateUserId == _currentUser.Id);

            if (exist)
            {
                throw new LinCmsException($"分类专栏[{createClassify.ClassifyName}]已存在");
            }

            Classify classify = _mapper.Map <Classify>(createClassify);

            _classifyRepository.Insert(classify);
            return(UnifyResponseDto.Success("新建分类专栏成功"));
        }
        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 void Post(long subscribeUserId)
        {
            if (subscribeUserId == _currentUser.Id)
            {
                throw new LinCmsException("您无法关注自己");
            }
            LinUser linUser = _userRepository.Select.Where(r => r.Id == subscribeUserId).ToOne();

            if (linUser == null)
            {
                throw new LinCmsException("该用户不存在");
            }

            if (!linUser.IsActive())
            {
                throw new LinCmsException("该用户已被拉黑");
            }

            bool any = _userSubscribeRepository.Select.Any(r =>
                                                           r.CreateUserId == _currentUser.Id && r.SubscribeUserId == subscribeUserId);

            if (any)
            {
                throw new LinCmsException("您已关注该用户");
            }

            UserSubscribe userSubscribe = new UserSubscribe()
            {
                SubscribeUserId = subscribeUserId
            };

            _userSubscribeRepository.Insert(userSubscribe);

            _capBus.Publish("NotificationController.Post", new CreateNotificationDto()
            {
                NotificationType       = NotificationType.UserLikeUser,
                NotificationRespUserId = subscribeUserId,
                UserInfoId             = _currentUser.Id ?? 0,
                CreateTime             = DateTime.Now,
            });
        }
Example #9
0
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            //当方法或控制器上存在DisableAuditingAttribute特性标签时,不记录日志
            if (context.ActionDescriptor is ControllerActionDescriptor d && d.MethodInfo.IsDefined(typeof(DisableAuditingAttribute), true) ||
                context.Controller.GetType().IsDefined(typeof(DisableAuditingAttribute), true)
                )
            {
                base.OnActionExecuted(context);
                return;
            }
            LoggerAttribute loggerAttribute = context.ActionDescriptor.EndpointMetadata.OfType <LoggerAttribute>().FirstOrDefault();
            var             linLog          = new LinLog
            {
                Path       = context.HttpContext.Request.Path,
                Method     = context.HttpContext.Request.Method,
                StatusCode = context.HttpContext.Response.StatusCode,
                UserId     = _currentUser.Id ?? 0,
                Username   = _currentUser.UserName
            };

            if (loggerAttribute != null)
            {
                linLog.Message = this.parseTemplate(loggerAttribute.Template, _currentUser, context.HttpContext.Request, context.HttpContext.Response);
            }
            else
            {
                linLog.Message = $"访问{linLog.Path}";
            }

            LinCmsAuthorizeAttribute linCmsAttribute = context.ActionDescriptor.EndpointMetadata.OfType <LinCmsAuthorizeAttribute>().FirstOrDefault();

            if (linCmsAttribute != null)
            {
                linLog.Authority = $"{linCmsAttribute.Module}  {linCmsAttribute.Permission}";
            }

            _logRepository.Insert(linLog);
            base.OnActionExecuted(context);
        }
Example #10
0
        public async Task <UnifyResponseDto> CreateAsync([FromBody] CreateCommentDto createCommentDto)
        {
            Comment comment = _mapper.Map <Comment>(createCommentDto);

            _commentAuditBaseRepository.Insert(comment);

            if (createCommentDto.RootCommentId.HasValue)
            {
                await _commentAuditBaseRepository.UpdateDiy.Set(r => r.ChildsCount + 1).Where(r => r.Id == createCommentDto.RootCommentId).ExecuteAffrowsAsync();
            }

            switch (createCommentDto.SubjectType)
            {
            case 1:
                await _articleRepository.UpdateDiy
                .Set(r => r.CommentQuantity + 1)
                .Where(r => r.Id == createCommentDto.SubjectId)
                .ExecuteAffrowsAsync();

                break;
            }

            if (_currentUser.Id != createCommentDto.RespUserId)
            {
                _capBus.Publish("NotificationController.Post", new CreateNotificationDto()
                {
                    NotificationType       = NotificationType.UserCommentOnArticle,
                    ArticleId              = createCommentDto.SubjectId,
                    NotificationRespUserId = createCommentDto.RespUserId,
                    UserInfoId             = _currentUser.Id ?? 0,
                    CreateTime             = comment.CreateTime,
                    CommentId              = comment.Id
                });
            }

            return(UnifyResponseDto.Success("评论成功"));
        }