예제 #1
0
        public void Update()
        {
            Book book = GetBook();

            book.Id    = 5;
            book.Title = "112122123";
            int len = _bookRepository.Update(book);

            Assert.Equal(1, len);
        }
        public ResultDto Put(int id, [FromBody] CreateUpdateBaseItemDto updateBaseItem)
        {
            BaseItem baseItem = _baseItemRepository.Select.Where(r => r.Id == id).ToOne();

            if (baseItem == null)
            {
                throw new LinCmsException("该数据不存在");
            }

            bool typeExist = _baseTypeRepository.Select.Any(r => r.Id == updateBaseItem.BaseTypeId);

            if (!typeExist)
            {
                throw new LinCmsException("请选择正确的类别");
            }

            bool exist = _baseItemRepository.Select.Any(r => r.BaseTypeId == updateBaseItem.BaseTypeId && r.ItemCode == updateBaseItem.ItemCode && r.Id != id);

            if (exist)
            {
                throw new LinCmsException($"编码[{updateBaseItem.ItemCode}]已存在");
            }

            _mapper.Map(updateBaseItem, baseItem);

            _baseItemRepository.Update(baseItem);

            return(ResultDto.Success("更新字典成功"));
        }
예제 #3
0
        public ResultDto Put(int id, [FromBody] CreateUpdateBookDto updateBook)
        {
            Book book = _bookRepository.Select.Where(r => r.Id == id).ToOne();

            if (book == null)
            {
                throw new LinCmsException("没有找到相关书籍");
            }

            bool exist = _bookRepository.Select.Any(r => r.Title == updateBook.Title && r.Id != id);

            if (exist)
            {
                throw new LinCmsException("图书已存在");
            }

            //book.Image = updateBook.Image;
            //book.Title = updateBook.Title;
            //book.Author = updateBook.Author;
            //book.Summary = updateBook.Summary;
            //book.Summary = updateBook.Summary;

            //使用AutoMapper方法简化类与类之间的转换过程
            _mapper.Map(updateBook, book);

            _bookRepository.Update(book);

            return(ResultDto.Success("更新图书成功"));
        }
        public ResultDto Put(Guid id, [FromBody] CreateUpdateClassifyDto updateClassify)
        {
            Classify classify = _classifyRepository.Select.Where(r => r.Id == id).ToOne();

            if (classify == null)
            {
                throw new LinCmsException("该数据不存在");
            }

            if (classify.CreateUserId != _currentUser.Id)
            {
                throw new LinCmsException("您无权编辑他人的分类专栏");
            }

            bool exist = _classifyRepository.Select.Any(r => r.ClassifyName == updateClassify.ClassifyName && r.Id != id && r.CreateUserId == _currentUser.Id);

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

            _mapper.Map(updateClassify, classify);

            _classifyRepository.Update(classify);

            return(ResultDto.Success("更新分类专栏成功"));
        }
예제 #5
0
        /// <summary>
        /// 修改指定字段,邮件和组别
        /// </summary>
        /// <param name="id"></param>
        /// <param name="updateUserDto"></param>
        /// <returns></returns>
        public void UpdateUserInfo(int id, UpdateUserDto updateUserDto)
        {
            //此方法适用于更新字段少时
            //_freeSql.Update<LinUser>(id).Set(a => new LinUser()
            //{
            //    Email = updateUserDto.Email,
            //    GroupId = updateUserDto.GroupId
            //}).ExecuteAffrows();

            //需要多查一次
            LinUser linUser = _userRepository.Where(r => r.Id == id).ToOne();

            if (linUser == null)
            {
                throw new LinCmsException("用户不存在", ErrorCode.NotFound);
            }
            //赋值过程可使用AutoMapper简化
            //只更新 Email、GroupId
            // UPDATE `lin_user` SET `email` = ?p_0, `group_id` = ?p_1
            // WHERE(`id` = 1) AND(`is_deleted` = 0)
            //linUser.Email = updateUserDto.Email;
            //linUser.GroupId = updateUserDto.GroupId;

            _mapper.Map(updateUserDto, linUser);

            _userRepository.Update(linUser);
        }
예제 #6
0
        public void Put(Guid id, CreateUpdateChannelDto updateChannel)
        {
            Channel channel = _channelRepository.Select.Where(r => r.Id == id).ToOne();

            if (channel == null)
            {
                throw new LinCmsException("该数据不存在");
            }

            bool exist = _channelRepository.Select.Any(r => r.ChannelName == updateChannel.ChannelName && r.Id != id && r.ChannelCode == updateChannel.ChannelCode);

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

            _mapper.Map(updateChannel, channel);

            var channelTagLists = new List <ChannelTag>();

            updateChannel.TagIds?.ForEach(r => { channelTagLists.Add(new ChannelTag(id, r)); });

            _channelTagRepository.Delete(r => r.ChannelId == id);
            _channelRepository.Update(channel);
            _channelTagRepository.Insert(channelTagLists);
        }
        public ResultDto Put(Guid id, bool isAudit)
        {
            MessageBoard messageBoard = _messageBoardRepository.Select.Where(r => r.Id == id).ToOne();

            if (messageBoard == null)
            {
                throw new LinCmsException("没有找到相关留言");
            }

            messageBoard.IsAudit = isAudit;
            _messageBoardRepository.Update(messageBoard);
            return(ResultDto.Success());
        }
        public ResultDto Put(Guid id, bool isAudit)
        {
            Comment comment = _commentAuditBaseRepository.Select.Where(r => r.Id == id).ToOne();

            if (comment == null)
            {
                throw new LinCmsException("没有找到相关评论");
            }

            comment.IsAudit = isAudit;
            _commentAuditBaseRepository.Update(comment);
            return(ResultDto.Success());
        }
예제 #9
0
        public ResultDto Put(Guid id, bool isAudit)
        {
            Article article = _articleRepository.Select.Where(r => r.Id == id).ToOne();

            if (article == null)
            {
                throw new LinCmsException("没有找到相关随笔");
            }

            article.IsAudit = isAudit;
            _articleRepository.Update(article);
            return(ResultDto.Success());
        }
예제 #10
0
        public ResultDto Put(long id, [FromBody] CreateUpdatePoemDto updatePoem)
        {
            LinPoem poem = _poemRepository.Select.Where(r => r.Id == id).ToOne();

            if (poem == null)
            {
                throw new LinCmsException("没有找到诗词");
            }

            //使用AutoMapper方法简化类与类之间的转换过程
            _mapper.Map(updatePoem, poem);

            _poemRepository.Update(poem);

            return(ResultDto.Success("更新诗词成功"));
        }
        public ResultDto Put(Guid id, [FromBody] CreateUpdateArticleDto updateArticle)
        {
            Article article = _articleRepository.Select.Where(r => r.Id == id).ToOne();

            if (article.CreateUserId != _currentUser.Id)
            {
                throw new LinCmsException("您无权修改他人的随笔");
            }
            if (article == null)
            {
                throw new LinCmsException("没有找到相关随笔");
            }

            bool exist = _articleRepository.Select.Any(r => r.Title == updateArticle.Title && r.Id != id && r.CreateUserId == _currentUser.Id);

            if (exist)
            {
                throw new LinCmsException("您有一个同样标题的随笔");
            }

            //使用AutoMapper方法简化类与类之间的转换过程
            _mapper.Map(updateArticle, article);


            _articleRepository.Update(article);

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

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

            updateArticle.TagIds.ForEach(r => tagArticles.Add(new TagArticle()
            {
                ArticleId = id,
                TagId     = r
            }));

            _tagArticleRepository.Insert(tagArticles);

            return(ResultDto.Success("更新随笔成功"));
        }
        public UnifyResponseDto Put(int id, [FromBody] CreateUpdateBaseTypeDto updateBaseType)
        {
            BaseType baseType = _baseTypeRepository.Select.Where(r => r.Id == id).ToOne();

            if (baseType == null)
            {
                throw new LinCmsException("该数据不存在");
            }

            bool exist = _baseTypeRepository.Select.Any(r => r.TypeCode == updateBaseType.TypeCode && r.Id != id);

            if (exist)
            {
                throw new LinCmsException($"基础类别-编码[{updateBaseType.TypeCode}]已存在");
            }

            _mapper.Map(updateBaseType, baseType);

            _baseTypeRepository.Update(baseType);

            return(UnifyResponseDto.Success("更新类别成功"));
        }
예제 #13
0
        public ResultDto Put(Guid id, [FromBody] CreateUpdateTagDto updateTag)
        {
            Tag tag = _tagRepository.Select.Where(r => r.Id == id).ToOne();

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

            bool exist = _tagRepository.Select.Any(r => r.TagName == updateTag.TagName && r.Id != id);

            if (exist)
            {
                throw new LinCmsException($"标签[{updateTag.TagName}]已存在");
            }

            _mapper.Map(updateTag, tag);

            _tagRepository.Update(tag);

            return(ResultDto.Success("更新标签成功"));
        }
예제 #14
0
        public void UpdateArticle(CreateUpdateArticleDto updateArticleDto, Article article)
        {
            //使用AutoMapper方法简化类与类之间的转换过程
            article.WordNumber  = article.Content.Length;
            article.ReadingTime = article.Content.Length / 800;

            _articleRepository.Update(article);

            Article oldArticle = _articleRepository.Select.Where(r => r.Id == article.Id)
                                 .IncludeMany(r => r.Tags).ToOne();

            oldArticle.Tags.ToList()
            .ForEach(u =>
            {
                tagService.UpdateArticleCount(u.Id, -1);
            });

            _tagArticleRepository.Delete(r => r.ArticleId == article.Id);

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

            updateArticleDto.TagIds.ForEach(tagId =>
            {
                tagArticles.Add(new TagArticle()
                {
                    ArticleId = article.Id,
                    TagId     = tagId
                });
                tagService.UpdateArticleCount(tagId, 1);
            });

            _tagArticleRepository.Insert(tagArticles);
            if (article.ClassifyId != updateArticleDto.ClassifyId)
            {
                _classifyService.UpdateArticleCount(article.ClassifyId, -1);
                _classifyService.UpdateArticleCount(updateArticleDto.ClassifyId, 1);
            }
        }
예제 #15
0
        public ResultDto Put(int id, [FromBody] CreateUpdateArticleDto updateArticle)
        {
            Article article = _articleRepository.Select.Where(r => r.Id == id).ToOne();

            if (article == null)
            {
                throw new LinCmsException("没有找到相关随笔");
            }

            bool exist = _articleRepository.Select.Any(r => r.Title == updateArticle.Title && r.Id != id && r.CreateUserId == _currentUser.Id);

            if (exist)
            {
                throw new LinCmsException("随笔已存在");
            }

            //使用AutoMapper方法简化类与类之间的转换过程
            _mapper.Map(updateArticle, article);

            _articleRepository.Update(article);

            return(ResultDto.Success("更新随笔成功"));
        }