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 async Task ChangeStatusAsync(long id, UserActive userActive)
        {
            LinUser user = await _userRepository.Select.Where(r => r.Id == id).ToOneAsync();

            if (user == null)
            {
                throw new LinCmsException("用户不存在", ErrorCode.NotFound);
            }

            if (user.IsActive() && userActive == UserActive.Active)
            {
                throw new LinCmsException("当前用户已处于禁止状态");
            }
            if (!user.IsActive() && userActive == UserActive.NotActive)
            {
                throw new LinCmsException("当前用户已处于激活状态");
            }

            await _userRepository.UpdateDiy.Where(r => r.Id == id)
            .Set(r => new { Active = userActive.GetHashCode() })
            .ExecuteUpdatedAsync();
        }
示例#3
0
        public void ChangeStatus(int id, UserActive userActive)
        {
            LinUser user = _userRepository.Select.Where(r => r.Id == id).ToOne();

            if (user == null)
            {
                throw new LinCmsException("用户不存在", ErrorCode.NotFound);
            }

            if (user.IsActive() && userActive == UserActive.Active)
            {
                throw new LinCmsException("当前用户已处于禁止状态");
            }
            if (!user.IsActive() && userActive == UserActive.NotActive)
            {
                throw new LinCmsException("当前用户已处于激活状态");
            }

            _freeSql.Update <LinUser>(id).Set(a => new LinUser()
            {
                Active = userActive.GetHashCode()
            }).ExecuteAffrows();
        }
示例#4
0
        public async Task 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("您已关注该用户");
            }

            using (IUnitOfWork unitOfWork = _unitOfWorkManager.Begin())
            {
                using ICapTransaction capTransaction = unitOfWork.BeginTransaction(_capBus, false);

                UserSubscribe userSubscribe = new UserSubscribe()
                {
                    SubscribeUserId = subscribeUserId
                };
                await _userSubscribeRepository.InsertAsync(userSubscribe);

                await _capBus.PublishAsync("NotificationController.Post", new CreateNotificationDto()
                {
                    NotificationType       = NotificationType.UserLikeUser,
                    NotificationRespUserId = subscribeUserId,
                    UserInfoId             = _currentUser.Id ?? 0,
                    CreateTime             = DateTime.Now,
                });

                await capTransaction.CommitAsync();
            }
        }
        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,
            });
        }