public async Task SeedAsync()
        {
            List <PermissionDefinition> linCmsAttributes = ReflexHelper.GeAssemblyLinCmsAttributes();

            List <LinPermission> insertPermissions = new List <LinPermission>();
            List <LinPermission> allPermissions    = await _permissionRepository.Select.ToListAsync();

            linCmsAttributes.ForEach(r =>
            {
                bool exist = allPermissions.Any(u => u.Module == r.Module && u.Name == r.Permission);
                if (!exist)
                {
                    insertPermissions.Add(new LinPermission(r.Permission, r.Module));
                }
            });
            await _permissionRepository.InsertAsync(insertPermissions);

            _permissionRepository.UnitOfWork.Commit();
        }
Exemplo n.º 2
0
        public async Task CreateOrCancelAsync(CreateNotificationDto notificationDto)
        {
            if (notificationDto.IsCancel == false)
            {
                Notification linNotification = _mapper.Map <Notification>(notificationDto);
                await _notificationRepository.InsertAsync(linNotification);
            }
            else
            {
                Expression <Func <Notification, bool> > exprssion = r =>
                                                                    r.NotificationType == notificationDto.NotificationType &&
                                                                    r.UserInfoId == notificationDto.UserInfoId;
                switch (notificationDto.NotificationType)
                {
                case NotificationType.UserLikeArticle:    //点赞随笔
                    exprssion = exprssion.And(r => r.ArticleId == notificationDto.ArticleId);
                    break;

                case NotificationType.UserCommentOnArticle:     //评论随笔
                case NotificationType.UserLikeArticleComment:   //点赞随笔下的评论
                    exprssion = exprssion.And(r =>
                                              r.ArticleId == notificationDto.ArticleId && r.CommentId == notificationDto.CommentId);
                    break;

                case NotificationType.UserCommentOnComment:     //回复评论
                    exprssion = exprssion.And(r =>
                                              r.ArticleId == notificationDto.ArticleId && r.CommentId == notificationDto.CommentId &&
                                              r.NotificationRespUserId == notificationDto.NotificationRespUserId);
                    break;

                case NotificationType.UserLikeUser:     //关注用户
                    exprssion = exprssion.And(r =>
                                              r.NotificationRespUserId == notificationDto.NotificationRespUserId);
                    break;

                default:
                    exprssion = r => false;
                    break;
                }

                await _notificationRepository.DeleteAsync(exprssion);
            }
        }
        public Task SeedAsync()
        {
            List <PermissionDefinition> linCmsAttributes = ReflexHelper.GeAssemblyLinCmsAttributes();

            linCmsAttributes.ForEach(async r =>
            {
                bool exist = await _permissionRepository.Select
                             .Where(u => u.Module == r.Module && u.Name == r.Permission)
                             .AnyAsync();

                if (!exist)
                {
                    await _permissionRepository.InsertAsync(new LinPermission(r.Permission, r.Module));
                }
            });
            _permissionRepository.UnitOfWork.Commit();

            return(Task.CompletedTask);
        }
Exemplo n.º 4
0
        public async Task CreateAsync(CreateCommentDto createCommentDto)
        {
            using IUnitOfWork uow       = UnitOfWorkManager.Begin();
            using ICapTransaction trans = uow.BeginTransaction(_capBus, false);

            Comment comment = Mapper.Map <Comment>(createCommentDto);
            await _commentRepository.InsertAsync(comment);

            if (createCommentDto.RootCommentId.HasValue)
            {
                await _commentRepository.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)
            {
                await _capBus.PublishAsync(CreateNotificationDto.CreateOrCancelAsync, new CreateNotificationDto()
                {
                    NotificationType       = NotificationType.UserCommentOnArticle,
                    ArticleId              = createCommentDto.SubjectId,
                    NotificationRespUserId = createCommentDto.RespUserId,
                    UserInfoId             = CurrentUser.Id ?? 0,
                    CreateTime             = comment.CreateTime,
                    CommentId              = comment.Id
                });
            }

            await trans.CommitAsync();
        }
Exemplo n.º 5
0
        public async Task ChangePasswordAsync(LinUserIdentity linUserIdentity, string newpassword)
        {
            string encryptPassword = EncryptUtil.Encrypt(newpassword);

            if (linUserIdentity == null)
            {
                linUserIdentity = new LinUserIdentity()
                {
                    IdentityType = LinUserIdentity.Password,
                    Identifier   = "",
                    Credential   = encryptPassword
                };
                await _userIdentityRepository.InsertAsync(linUserIdentity);
            }
            else
            {
                linUserIdentity.Credential = encryptPassword;
                await _userIdentityRepository.UpdateAsync(linUserIdentity);
            }
        }
Exemplo n.º 6
0
        public async Task UpdateTagAsync(Guid id, CreateUpdateArticleDto updateArticleDto)
        {
            List <Guid> tagIds = await _tagArticleRepository.Select.Where(r => r.ArticleId == id).ToListAsync(r => r.TagId);

            tagIds.ForEach(async(tagId) => { await _tagService.UpdateArticleCountAsync(tagId, -1); });

            _tagArticleRepository.Delete(r => r.ArticleId == id);

            List <TagArticle> tagArticles = new List <TagArticle>();

            updateArticleDto.TagIds.ForEach(async(tagId) =>
            {
                tagArticles.Add(new TagArticle()
                {
                    ArticleId = id,
                    TagId     = tagId
                });
                await _tagService.UpdateArticleCountAsync(tagId, 1);
            });
            await _tagArticleRepository.InsertAsync(tagArticles);
        }
        public async Task <bool> 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.UpdateLikeQuantityAysnc(createUpdateUserLike.SubjectId, increaseLikeQuantity);

                break;

            case UserLikeSubjectType.UserLikeComment:
                await _commentService.UpdateLikeQuantityAysnc(createUpdateUserLike.SubjectId, increaseLikeQuantity);

                break;
            }

            if (exist)
            {
                return(true);
            }


            UserLike userLike = _mapper.Map <UserLike>(createUpdateUserLike);
            await _userLikeRepository.InsertAsync(userLike);

            return(false);
        }
Exemplo n.º 8
0
        public async Task CreateAsync([FromBody] CreateUpdateChannelDto createChannel)
        {
            bool exist = await _channelRepository.Select.AnyAsync(r => r.ChannelName == createChannel.ChannelName && r.ChannelCode == createChannel.ChannelCode);

            if (exist)
            {
                throw new LinCmsException($"技术频道[{createChannel.ChannelName}]已存在");
            }

            Channel channel = Mapper.Map <Channel>(createChannel);

            channel.Tags = new List <Tag>();
            createChannel.TagIds?.ForEach(r =>
            {
                channel.Tags.Add(new Tag()
                {
                    Id = r
                });
            });

            await _channelRepository.InsertAsync(channel);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 上传文件至七牛云,如果本地存在这条记录,直接返回文件的信息
        /// </summary>
        /// <param name="file">单个文件</param>
        /// <param name="key"></param>
        /// <returns></returns>
        public async Task <FileDto> UploadAsync(IFormFile file, int key = 0)
        {
            string md5 = LinCmsUtils.GetHash <MD5>(file.OpenReadStream());

            LinFile linFile = await _fileRepository.Where(r => r.Md5 == md5 && r.Type == 2).FirstAsync();

            if (linFile != null)
            {
                return(new FileDto
                {
                    Id = linFile.Id,
                    Key = "file_" + key,
                    Path = linFile.Path,
                    Url = _fileStorageOption.Qiniu.Host + linFile.Path
                });
            }

            string path = this.QiniuUpload(file);

            LinFile saveLinFile = new LinFile()
            {
                Extension = Path.GetExtension(file.FileName),
                Md5       = md5,
                Name      = file.FileName,
                Path      = path,
                Type      = 2,
                Size      = file.Length,
            };

            long id = (await _fileRepository.InsertAsync(saveLinFile)).Id;

            return(new FileDto
            {
                Id = id,
                Key = "file_" + key,
                Path = path,
                Url = _fileStorageOption.Qiniu.Host + path
            });
        }
Exemplo n.º 10
0
        public async Task <UnifyResponseDto> CreateAsync([FromBody] CreateCommentDto createCommentDto)
        {
            Comment comment = _mapper.Map <Comment>(createCommentDto);
            await _commentAuditBaseRepository.InsertAsync(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)
            {
                await _capBus.PublishAsync("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("评论成功"));
        }
        /// <summary>
        /// 权限标签上的Permission改变时,删除数据库中存在的无效权限,并生成新的权限。
        /// </summary>
        /// <returns></returns>
        public async Task SeedAsync()
        {
            List <PermissionDefinition> linCmsAttributes = ReflexHelper.GeAssemblyLinCmsAttributes();

            List <LinPermission> insertPermissions = new List <LinPermission>();
            List <LinPermission> allPermissions    = await _permissionRepository.Select.ToListAsync();

            Expression <Func <LinGroupPermission, bool> > expression           = u => false;
            Expression <Func <LinPermission, bool> >      permissionExpression = u => false;

            allPermissions.ForEach(permissioin =>
            {
                if (!linCmsAttributes.Any(r => r.Permission == permissioin.Name))
                {
                    expression           = expression.Or(r => r.PermissionId == permissioin.Id);
                    permissionExpression = permissionExpression.Or(r => r.Id == permissioin.Id);
                }
            });

            int effectRows = await _permissionRepository.DeleteAsync(permissionExpression);

            effectRows += await _groupPermissionRepository.DeleteAsync(expression);

            _logger.LogInformation($"删除了{effectRows}条数据");

            linCmsAttributes.ForEach(r =>
            {
                bool exist = allPermissions.Any(u => u.Module == r.Module && u.Name == r.Permission);
                if (!exist)
                {
                    insertPermissions.Add(new LinPermission(r.Permission, r.Module));
                }
            });
            await _permissionRepository.InsertAsync(insertPermissions);

            _logger.LogInformation($"新增了{insertPermissions.Count}条数据");
        }
Exemplo n.º 12
0
 public async Task CreateAsync(CreateUpdateDocDto createDoc)
 {
     Doc doc = _mapper.Map <Doc>(createDoc);
     await Repository.InsertAsync(doc);
 }