public void Insert() { Book book = GetBook(); Book backBook = _bookRepository.Insert(book); Assert.Equal(book.Author, backBook.Author); }
public ResultDto Post([FromBody] CreateUpdatePoemDto createPoem) { LinPoem poem = _mapper.Map <LinPoem>(createPoem); _poemRepository.Insert(poem); return(ResultDto.Success("新建诗词成功")); }
public void Register(LinUser user) { bool isExistGroup = _groupRepository.Select.Any(r => r.Id == user.GroupId); if (!isExistGroup) { throw new LinCmsException("分组不存在", ErrorCode.NotFound); } if (!string.IsNullOrEmpty(user.Username)) { bool isRepeatName = _userRepository.Select.Any(r => r.Username == user.Username); if (isRepeatName) { throw new LinCmsException("用户名重复,请重新输入", ErrorCode.RepeatField); } } if (!string.IsNullOrEmpty(user.Email.Trim())) { var isRepeatEmail = _userRepository.Select.Any(r => r.Email == user.Email.Trim()); if (isRepeatEmail) { throw new LinCmsException("注册邮箱重复,请重新输入", ErrorCode.RepeatField); } } user.Active = 1; user.Admin = 1; user.Password = LinCmsUtils.Get32Md5(user.Password); _userRepository.Insert(user); }
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); }
public ResultDto Post([FromBody] CreateUpdateArticleDto createArticle) { bool exist = _articleRepository.Select.Any(r => r.Title == createArticle.Title && r.CreateUserId == _currentUser.Id); if (exist) { throw new LinCmsException("您有一个同样标题的随笔"); } Article article = _mapper.Map <Article>(createArticle); article.Archive = DateTime.Now.ToString("yyy年MM月"); article.Author = _currentUser.UserName; article.Tags = new List <Tag>(); foreach (var articleTagId in createArticle.TagIds) { article.Tags.Add(new Tag() { Id = articleTagId, }); } _articleRepository.Insert(article); return(ResultDto.Success("新建随笔成功")); }
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 Post([FromBody] CreateMessageBoardDto createMessageBoardDto) { MessageBoard messageBoard = _mapper.Map <MessageBoard>(createMessageBoardDto); messageBoard.Ip = this.GetIp(); messageBoard.Agent = Request.Headers["User-agent"].ToString(); messageBoard.UserHost = Dns.GetHostName(); messageBoard.System = LinCmsUtils.GetOsNameByUserAgent(messageBoard.Agent); if (messageBoard.Ip.IsNotNullOrEmpty()) { IpQueryResult ipQueryResult = LinCmsUtils.IpQueryCity(messageBoard.Ip); messageBoard.GeoPosition = ipQueryResult.errno == 0 ? ipQueryResult.data : ipQueryResult.errmsg; } LinUser linUser = _userService.GetCurrentUser(); if (linUser == null) { messageBoard.Avatar = "/assets/user/" + new Random().Next(1, 360) + ".png"; } else { messageBoard.Avatar = _currentUser.GetFileUrl(linUser.Avatar); } _messageBoardRepository.Insert(messageBoard); return(ResultDto.Success("留言成功")); }
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 void Post(CreateNotificationDto createNotificationDto) { Notification linNotification = _mapper.Map <Notification>(createNotificationDto); _notificationRepository.Insert(linNotification); _notificationRepository.UnitOfWork.Commit(); }
public ResultDto Post([FromBody] CreateUpdateTagDto createTag) { bool exist = _tagRepository.Select.Any(r => r.TagName == createTag.TagName); if (exist) { throw new LinCmsException($"标签[{createTag.TagName}]已存在"); } Tag tag = _mapper.Map <Tag>(createTag); _tagRepository.Insert(tag); return(ResultDto.Success("新建标签成功")); }
public ResultDto 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(ResultDto.Success("新建分类专栏成功")); }
public ResultDto Post([FromBody] CreateUpdateBookDto createBook) { bool exist = _bookRepository.Select.Any(r => r.Title == createBook.Title); if (exist) { throw new LinCmsException("图书已存在"); } Book book = _mapper.Map <Book>(createBook); _bookRepository.Insert(book); return(ResultDto.Success("新建图书成功")); }
public UnifyResponseDto Post([FromBody] CreateUpdateBaseTypeDto createBaseType) { bool exist = _baseTypeRepository.Select.Any(r => r.TypeCode == createBaseType.TypeCode); if (exist) { throw new LinCmsException($"类别-编码[{createBaseType.TypeCode}]已存在"); } BaseType baseType = _mapper.Map <BaseType>(createBaseType); _baseTypeRepository.Insert(baseType); return(UnifyResponseDto.Success("新建类别成功")); }
public ResultDto Post([FromBody] CreateUpdateBaseItemDto createBaseItem) { bool exist = _baseItemRepository.Select.Any(r => r.BaseTypeId == createBaseItem.BaseTypeId && r.ItemCode == createBaseItem.ItemCode); if (exist) { throw new LinCmsException($"编码[{createBaseItem.ItemCode}]已存在"); } BaseItem baseItem = _mapper.Map <BaseItem>(createBaseItem); _baseItemRepository.Insert(baseItem); return(ResultDto.Success("新建字典成功")); }
public ResultDto Post([FromBody] CreateUpdateArticleDto createArticle) { bool exist = _articleRepository.Select.Any(r => r.Title == createArticle.Title && r.CreateUserId == _currentUser.Id); if (exist) { throw new LinCmsException("随笔标题不能重复"); } Article article = _mapper.Map <Article>(createArticle); article.Archive = DateTime.Now.ToString("yyy年MM月"); if (article.Author.IsNullOrEmpty()) { article.Author = _currentUser.UserName; } _articleRepository.Insert(article); return(ResultDto.Success("新建随笔成功")); }
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, }); }
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("点赞成功")); }
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 void CreateArticle(CreateUpdateArticleDto createArticle) { Article article = _mapper.Map <Article>(createArticle); article.Archive = DateTime.Now.ToString("yyy年MM月"); article.WordNumber = createArticle.Content.Length; article.ReadingTime = createArticle.Content.Length / 800; article.Tags = new List <Tag>(); foreach (var articleTagId in createArticle.TagIds) { article.Tags.Add(new Tag() { Id = articleTagId, }); tagService.UpdateArticleCount(articleTagId, 1); } _articleRepository.Insert(article); _classifyService.UpdateArticleCount(createArticle.ClassifyId, 1); }
public void Post([FromBody] CreateUpdateChannelDto createChannel) { bool exist = _channelRepository.Select.Any(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 }); }); _channelRepository.Insert(channel); }
public ResultDto Post([FromBody] CreateCommentDto createCommentDto) { Comment comment = _mapper.Map <Comment>(createCommentDto); _commentAuditBaseRepository.Insert(comment); if (createCommentDto.RootCommentId.HasValue) { _commentAuditBaseRepository.UpdateDiy.Set(r => r.ChildsCount + 1).Where(r => r.Id == createCommentDto.RootCommentId).ExecuteAffrows(); } switch (createCommentDto.SubjectType) { case 1: _articleRepository.UpdateDiy.Set(r => r.CommentQuantity + 1) .Where(r => r.Id == createCommentDto.SubjectId).ExecuteAffrows(); break; } return(ResultDto.Success("评论成功")); }
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("点赞成功")); }
public ResultDto Post([FromBody] CreateCommentDto createCommentDto) { Comment comment = _mapper.Map <Comment>(createCommentDto); _commentAuditBaseRepository.Insert(comment); if (createCommentDto.RootCommentId.HasValue) { _commentAuditBaseRepository.UpdateDiy.Set(r => r.ChildsCount + 1).Where(r => r.Id == createCommentDto.RootCommentId).ExecuteAffrows(); } switch (createCommentDto.SubjectType) { case 1: _articleRepository.UpdateDiy .Set(r => r.CommentQuantity + 1) .Where(r => r.Id == createCommentDto.SubjectId) .ExecuteAffrows(); 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(ResultDto.Success("评论成功")); }