Example #1
0
        public ActionResult LoadUserInfo(long userId)
        {
            if (userId == 0)
            {
                return(View());
            }
            var user = UserService.GetUserById(userId);

            if (user == null)
            {
                return(View());
            }
            return(Json(new AjaxResult
            {
                Status = "OK",
                Data = new UserInfo
                {
                    Id = user.Id,
                    Biography = user.Biography,
                    FollowerCount = FollowService.GetFollowerCount(userId),
                    FollowingCount = FollowService.GetFollowingCount(userId),
                    FullName = user.FullName,
                    PostCount = PostService.GetPostCount(userId),
                    ProfilePic = user.ProfilePic,
                    UserName = user.UserName,
                    IsFollowing = FollowService.IsFollowing(Convert.ToInt64(Session["userId"]), userId)
                }
            }));
        }
        /// <summary>
        /// stop following the target
        /// </summary>
        /// <param name="targetUserId">target(followee) user id</param>
        /// <param name="followerUserId">the follower user id</param>
        public void UnFollow(Guid targetUserId, Guid followerUserId)
        {
            var targetPid   = MyUserManager.FindByIdAsync(targetUserId).Result.Profiles[OldHouseUserProfile.PROFILENBAME];
            var followerPid = MyUserManager.FindByIdAsync(followerUserId).Result.Profiles[OldHouseUserProfile.PROFILENBAME];

            FollowService.UnFollow(targetPid, followerPid);
        }
        /// <summary>
        /// Am i following this user
        /// </summary>
        /// <param name="targetUserId">the followee user id</param>
        /// <param name="followerUserId">the follower userid</param>
        /// <returns></returns>
        public bool AmIFollowing(Guid targetUserId, Guid followerUserId)
        {
            var targetPid   = MyUserManager.FindByIdAsync(targetUserId).Result.Profiles[OldHouseUserProfile.PROFILENBAME];
            var followerPid = MyUserManager.FindByIdAsync(followerUserId).Result.Profiles[OldHouseUserProfile.PROFILENBAME];

            return(FollowService.AmIFollowing(targetPid, followerPid));
        }
Example #4
0
        /// <summary>
        /// 检查用户是否接收动态
        /// </summary>
        /// <param name="activityService"></param>
        /// <param name="userId">UserId</param>
        /// <param name="activity">动态</param>
        /// <returns>接收动态返回true,否则返回false</returns>
        private bool IsReceiveActivity(ActivityService activityService, long userId, Activity activity)
        {
            //检查用户是否已在信息发布者的粉丝圈里面
            FollowService followService = new FollowService();

            if (followService.IsFollowed(userId, activity.UserId))
            {
                return(false);
            }
            //检查用户是否接收该动态项目
            Dictionary <string, bool> userSettings = activityService.GetActivityItemUserSettings(userId);

            if (userSettings.ContainsKey(activity.ActivityItemKey))
            {
                return(userSettings[activity.ActivityItemKey]);
            }
            else
            {
                //如果用户没有设置从默认设置获取
                ActivityItem activityItem = activityService.GetActivityItem(activity.ActivityItemKey);
                if (activityItem != null)
                {
                    return(activityItem.IsUserReceived);
                }
                else
                {
                    return(true);
                }
            }
        }
        /// <summary>
        /// 关注的用户菜单控件
        /// </summary>
        /// <returns></returns>
        public ActionResult _TopFollowedUsers(string spaceKey, int topNumber)
        {
            Dictionary <long, bool> isFollowesUser = new Dictionary <long, bool>();

            long userId        = UserIdToUserNameDictionary.GetUserId(spaceKey);
            long currentUserId = UserContext.CurrentUser.UserId;

            FollowService      followService = new FollowService();
            IEnumerable <long> ids           = followService.GetTopFollowedUserIds(userId, topNumber);

            foreach (var id in ids)
            {
                isFollowesUser[id] = followService.IsFollowed(currentUserId, id);
            }

            ViewData["isFollowesUser"] = isFollowesUser;

            if (currentUserId == userId)
            {
                ViewData["isSameUser"] = true;
            }

            ViewData["gender"] = (userService.GetUser(spaceKey) as User).Profile.Gender;
            IEnumerable <User> users = userService.GetFullUsers(ids);

            return(View(users));
        }
 /// <summary>
 /// 检查用户是否接收动态
 /// </summary>
 /// <param name="activityService"></param>
 /// <param name="isPublic">群组是否为公开群组</param>
 /// <param name="userId">UserId</param>
 /// <param name="activity">动态</param>
 /// <returns>接收动态返回true,否则返回false</returns>
 private bool IsReceiveActivity(ActivityService activityService, bool isPublic, long userId, Activity activity)
 {
     if (isPublic)
     {
         //检查用户是否已在信息发布者的粉丝圈里面
         FollowService followService = new FollowService();
         if (followService.IsFollowed(userId, activity.UserId))
             return false;
     }
     //检查用户是否已屏蔽群组
     if (new UserBlockService().IsBlockedGroup(userId, activity.OwnerId))
         return false;
     //检查用户是否接收该动态项目
     Dictionary<string, bool> userSettings = activityService.GetActivityItemUserSettings(userId);
     if (userSettings.ContainsKey(activity.ActivityItemKey))
         return userSettings[activity.ActivityItemKey];
     else
     {
         //如果用户没有设置从默认设置获取
         ActivityItem activityItem = activityService.GetActivityItem(activity.ActivityItemKey);
         if (activityItem != null)
             return activityItem.IsUserReceived;
         else
             return true;
     }
 }
        /// <summary>
        /// let the followerId follow the target id
        /// </summary>
        /// <param name="targetUserId">target(followee) user id</param>
        /// <param name="followerUserId">the follower user id</param>
        public void Follow(Guid targetUserId, Guid followerUserId)
        {
            //todo limit the following count here
            var targetPid   = MyUserManager.FindByIdAsync(targetUserId).Result.Profiles[OldHouseUserProfile.PROFILENBAME];
            var followerPid = MyUserManager.FindByIdAsync(followerUserId).Result.Profiles[OldHouseUserProfile.PROFILENBAME];

            FollowService.Follow(targetPid, followerPid);
        }
        /// <summary>
        /// 判断用户是否关注了某个用户
        /// </summary>
        /// <param name="user"><see cref="IUser"/></param>
        /// <param name="toUserId">待检测用户Id</param>
        /// <returns></returns>
        public static bool IsFollowed(this IUser user, long toUserId)
        {
            if (user == null)
                return false;

            FollowService followService = new FollowService();
            return followService.IsFollowed(user.UserId, toUserId);
        }
        public void TestAddFollows()
        {
            mockFollowRepository.Setup(x => x.Add(It.IsAny <Follow>())).Returns(follow);
            var    followService = new FollowService(mockFollowRepository.Object);
            Follow followReturn  = followService.AddFollows(follow);

            Assert.AreEqual(followReturn.Follower, follow.Follower);
        }
        public void TestUnfollow()
        {
            mockFollowRepository.Setup(x => x.Unfollow(It.IsAny <Follow>())).Returns(follow);
            var    followService = new FollowService(mockFollowRepository.Object);
            Follow followReturn  = followService.Unfollow(follow);

            Assert.AreEqual(followReturn, follow);
        }
        public void TestIsFollowed()
        {
            mockFollowRepository.Setup(x => x.IsFollowed(It.IsAny <string>(), It.IsAny <string>())).Returns(true);
            var  followService = new FollowService(mockFollowRepository.Object);
            bool checkFolled   = followService.IsFollowed("5d111299f3b75e0001f4ed78", "5d111299f3b75e0001f4ed78");

            Assert.IsTrue(checkFolled);
        }
        public WebimPlugin()
        {
            userService = DIContainer.Resolve<IUserService>();

            groupService = new GroupService();

            followService = new FollowService();
        }
 public StudentDashboard(StorageService storage, CookieService cookie, ProfileService profile, NotificationService notification, FollowService follow, ScheduleService schedule)
 {
     storageService      = storage;
     cookieService       = cookie;
     profileService      = profile;
     notificationService = notification;
     followService       = follow;
     scheduleService     = schedule;
 }
        public void TestGetAllFollowingId()
        {
            mockFollowRepository.Setup(x => x.GetAllFollowingId(It.IsAny <string>())).Returns(getAllFollowingId);
            var           followService           = new FollowService(mockFollowRepository.Object);
            List <string> getAllFollowingIds      = followService.GetAllFollowingId("5d111299f3b75e0001f4ed78");
            string        followeingIdFirstActual = getAllFollowingIds.FirstOrDefault();

            Assert.AreEqual(followeingIdFirstActual, "5d0a17701a0a4200017de6cv");
        }
Example #15
0
 public SignUpModel(StorageService storage, EncryptionService encryption, CookieService cookie, TopicService topics, EmailService email, FollowService follow)
 {
     storageService    = storage;
     encryptionService = encryption;
     cookieService     = cookie;
     topicService      = topics;
     emailService      = email;
     followService     = follow;
 }
 //done:zhengw,by mazq 缺少注释
 //zhengw回复:已修改
 /// <summary>
 /// 获取接收人UserId集合
 /// </summary>
 /// <param name="activityService">动态业务逻辑类</param>
 /// <param name="activity">动态</param>
 /// <returns></returns>
 IEnumerable<long> IActivityReceiverGetter.GetReceiverUserIds(ActivityService activityService, Activity activity)
 {
     //1、获取用户的所有粉丝,然后通过IsReceiveActivity()检查,是否给该粉丝推送动态;
     FollowService followService = new FollowService();
     IEnumerable<long> followerUserIds = followService.GetTopFollowerUserIds(activity.OwnerId, Follow_SortBy.DateCreated_Desc, ValueUtility.GetSqlMaxInt());
     if (followerUserIds == null)
         return new List<long>();
     return followerUserIds.Where(n => IsReceiveActivity(activityService, n, activity));
 }
Example #17
0
        /// <summary>
        /// 把用户加入黑名单
        /// </summary>
        /// <param name="stopedUser">黑名单</param>
        public bool CreateStopedUser(StopedUser stopedUser)
        {
            FollowService followService = new FollowService();
            followService.CancelFollow(stopedUser.UserId, stopedUser.ToUserId);
            followService.CancelFollow(stopedUser.ToUserId, stopedUser.UserId);

            bool isCreat = stopedUserRepository.CreateStopedUser(stopedUser);
            EventBus<StopedUser>.Instance().OnAfter(stopedUser, new CommonEventArgs(EventOperationType.Instance().Create()));
            return isCreat;
        }
Example #18
0
 public Tutor(StorageService storage, CookieService cookie, ProfileService profile, ScheduleService schedule, FollowService follow, NotificationService notification, EncryptionService encryption)
 {
     storageService      = storage;
     cookieService       = cookie;
     profileService      = profile;
     scheduleService     = schedule;
     followService       = follow;
     notificationService = notification;
     encryptionService   = encryption;
 }
 public TutorDashboard(StorageService storage, CookieService cookie, ProfileService profile, ScheduleService schedule, FollowService follow, SearchService search, NotificationService notification, ChatService chat)
 {
     storageService      = storage;
     cookieService       = cookie;
     profileService      = profile;
     scheduleService     = schedule;
     followService       = follow;
     searchService       = search;
     notificationService = notification;
     chatService         = chat;
 }
Example #20
0
 public QuotesController(QuotesService myService,
                         CategoryService categoryService,
                         UserService userService,
                         FollowService followService,
                         IEmailSender emailSender)
 {
     _myService       = myService;
     _categoryService = categoryService;
     _userService     = userService;
     _followService   = followService;
     _emailSender     = emailSender;
 }
Example #21
0
        static void Main(string[] args)
        {
            LikeService userService = new LikeService();

            userService.Like();

            FollowService followService = new FollowService();

            followService.Follow();

            Console.ReadKey();
        }
Example #22
0
        public FollowsServiceTests()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            var db = new ApplicationDbContext(options);

            this.repo = new EfRepository <UserFollow>(db);
            var userRepo = new EfRepository <ApplicationUser>(db);

            this.service = new FollowService(this.repo, userRepo);

            _ = new MapperInitializationProfile();
        }
 void SetStatusInvitationEventModule_After(Invitation sender, CommonEventArgs eventArgs)
 {
     if (eventArgs.EventOperationType == EventOperationType.Instance().Update())
     {
         InvitationService invitationService = DIContainer.Resolve<InvitationService>();
         Invitation invitation = invitationService.Get(sender.Id);
         if (invitation != null && invitation.InvitationTypeKey == InvitationTypeKeys.Instance().InviteFollow() && invitation.Status == InvitationStatus.Accept)
         {
             FollowService followService = new FollowService();
             followService.Follow(invitation.UserId, invitation.SenderUserId);
         }
     }
 }
 void SetStatusInvitationEventModule_After(Invitation sender, CommonEventArgs eventArgs)
 {
     if (eventArgs.EventOperationType == EventOperationType.Instance().Update())
     {
         InvitationService invitationService = DIContainer.Resolve <InvitationService>();
         Invitation        invitation        = invitationService.Get(sender.Id);
         if (invitation != null && invitation.InvitationTypeKey == InvitationTypeKeys.Instance().InviteFollow() && invitation.Status == InvitationStatus.Accept)
         {
             FollowService followService = new FollowService();
             followService.Follow(invitation.UserId, invitation.SenderUserId);
         }
     }
 }
        public void TestGetAllFollower()
        {
            IEnumerable <User> ienumableUsers = new List <User>()
            {
                user, userSecond
            };

            mockFollowRepository.Setup(x => x.GetAllFollower(It.IsAny <string>())).Returns(ienumableUsers);
            var followService = new FollowService(mockFollowRepository.Object);
            IEnumerable <User> ienumableReturn = followService.GetAllFollower("5d111299f3b75e0001f4ed78");
            User userActual = ienumableReturn.FirstOrDefault();

            Assert.AreEqual(userActual, user);
        }
        public ProfilesServiceTests()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            var db = new ApplicationDbContext(options);

            this.userRepo = new EfDeletableEntityRepository <ApplicationUser>(db);

            var userFollow = new EfRepository <UserFollow>(db);
            var followRepo = new FollowService(userFollow, this.userRepo);

            this.service = new ProfileService(this.userRepo, followRepo);

            var map = new MapperInitializationProfile();
        }
Example #27
0
 public HouseService(IRepository <House> repository, BlogPostService checkinService, EntityService <OldHouseUserProfile> profileSerice,
                     LikeRateFavService lrfService, UserManager <OldHouseUser> userManger, MessageService feedService) : base(repository)
 {
     CheckInService = checkinService;
     CheckInService.RegisterField <CheckIn>(new List <string>());
     ProfileService = profileSerice;
     //remember to register user private filds here
     MyUserManager = userManger;
     LrfService    = lrfService;
     //use the profile repository
     FollowService = new FollowService <OldHouseUserProfile>(ProfileService.EntityRepository);
     FeedService   = feedService;
     registerHouse();
     registerUserProfile();
     instence = this;
 }
        /// <summary>
        /// toggle the follow of a user
        /// </summary>
        /// <param name="targetUserId"></param>
        /// <param name="followerUserId"></param>
        /// <returns></returns>
        public bool ToggoleFollow(Guid targetUserId, Guid followerUserId)
        {
            var targetPid   = MyUserManager.FindByIdAsync(targetUserId).Result.Profiles[OldHouseUserProfile.PROFILENBAME];
            var user        = MyUserManager.FindByIdAsync(targetUserId).Result;
            var followerPid = MyUserManager.FindByIdAsync(followerUserId).Result.Profiles[OldHouseUserProfile.PROFILENBAME];

            if (FollowService.AmIFollowing(targetPid, followerPid))
            {
                FollowService.UnFollow(targetPid, followerPid);
                return(false);
            }
            else
            {
                FollowService.Follow(targetPid, followerPid);
                return(true);
            }
        }
        public void SetUp()
        {
            _followerId = "1";
            _followeeId = "2";

            _repository  = new Mock <IFollowRepository>();
            _userService = new Mock <IUserService>();

            _userService.Setup(us => us.GetCurrentUserIdAsync()).ReturnsAsync(_followerId);


            _followService = new FollowService(_repository.Object, _userService.Object);

            _follow = new Follow
            {
                FollowerId = _followerId,
                FolloweeId = _followeeId
            };

            /*List of people following the user*/
            _followee1 = new Follow
            {
                FollowerId = "3",
                FolloweeId = _followerId
            };

            _followee2 = new Follow
            {
                FollowerId = "4",
                FolloweeId = _followerId
            };

            /*List of people the user will follow*/
            _follower1 = new Follow
            {
                FollowerId = _followerId,
                FolloweeId = "3"
            };

            _follower2 = new Follow
            {
                FollowerId = _followerId,
                FolloweeId = "4"
            };
        }
Example #30
0
 public ActionResult Index(long?id)
 {
     //IUserService UserService1 = new Service.UserService();
     if (id == null)
     {
         return(View());
     }
     ViewBag.FollowerCount  = FollowService.GetFollowerCount(id.Value);
     ViewBag.FollowingCount = FollowService.GetFollowingCount(id.Value);
     if (Convert.ToInt64(Session["userId"]) != id.Value)
     {
         ViewBag.Following = FollowService.IsFollowing(Convert.ToInt64(Session["userId"]), id.Value);
     }
     ViewBag.PostCount = PostService.GetPostCount(id.Value);
     ViewBag.PostList  = PostService.GetPostPagerList(id.Value, PageSize, 1).Select(
         p => new PostInfo(p));
     return(View(UserService.GetUserById(id.Value)));
 }
Example #31
0
        /// <summary>
        /// 用户空间日志左侧控制面板
        /// </summary>
        /// <param name="menu">菜单项标识</param>
        public ActionResult _Panel(string spaceKey, string menu = null)
        {
            User user = userService.GetFullUser(spaceKey);
            ViewData["user"] = user;

            //用户日志数
            long threadCount = ownerDataService.GetLong(user.UserId, OwnerDataKeys.Instance().ThreadCount());
            ViewData["threadCount"] = threadCount;

            IUser currentUser = UserContext.CurrentUser;
            if (currentUser != null && currentUser.UserId != user.UserId)
            {
                bool followed = new FollowService().IsFollowed(currentUser.UserId, user.UserId);
                ViewData["followed"] = followed;
            }

            return View();
        }
Example #32
0
        /// <summary>
        /// 关注其他用户
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void FollowBtn_Click(object sender, EventArgs e)
        {
            if (!IsSignIn())
            {
                Response.Redirect("/layout/SignIn.aspx");
                return;
            }
            else
            {
                Button btn  = (Button)sender;
                User   user = (User)Session["User"];

                if (btn.Text.Trim() == "关注")
                {
                    string _followingId = btn.Attributes["data-user-id"].ToString();

                    Int64 followingId = !String.IsNullOrEmpty(_followingId) ? Int64.Parse(_followingId) : 0;

                    if (followingId == 0 || followingId == user.Id) // 不能关注自己
                    {
                        return;
                    }


                    Follow follower = new Follow()
                    {
                        UserId      = user.Id,
                        FollowingId = followingId
                    };

                    bool isOk = FollowService.Following(follower);

                    if (isOk)
                    {
                        btn.Text = "已关注";
                    }
                }
                else
                {
                    // TODO: 取消关注
                }
            }
        }
        protected override void DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling)
        {
            base.DidActivate(firstActivation, addedToHierarchy, screenSystemEnabling);

            if (firstActivation)
            {
                if (_followService == null)
                {
                    _followService = new FollowService();
                }

                if (_playlistService == null)
                {
                    _playlistService = new PlaylistService();
                }

                _followService.GetFollowing(SetFollowers);
            }
        }
Example #34
0
        public ActionResult LoadFollowing(long userId, int pageIndex = 1)
        {
            long            accountId     = Convert.ToInt64(Session["userId"]);
            List <UserInfo> userList      = new List <UserInfo>();
            var             followingList = FollowService.GetFollowingPagerList(userId, 12, pageIndex);

            foreach (var followingId in followingList)
            {
                var user = UserService.GetUserById(followingId);
                userList.Add(new UserInfo
                {
                    Id          = user.Id,
                    FullName    = user.FullName,
                    UserName    = user.UserName,
                    IsFollowing = FollowService.IsFollowing(accountId, followingId),
                    Biography   = user.Biography.Length > 50 ? user.Biography.Substring(0, 50) + "..." : user.Biography,
                    ProfilePic  = user.ProfilePic
                });
            }
            return(Json(new AjaxResult {
                Status = "OK", Data = userList
            }));
        }
Example #35
0
        public ActionResult Unfollow(long userId)
        {
            long accountId = 0;

            if (Session["userId"] == null || !long.TryParse(Session["userId"].ToString(), out accountId))
            {
                Session.Clear();
                return(Redirect("/User/Login"));
            }
            if (userId != accountId || userId == 0)
            {
                if (FollowService.Unfollow(accountId, userId))
                {
                    LogService.Add(accountId, 4, string.Format("{0}成功取消关注{1}", accountId, userId));
                    return(Json(new AjaxResult {
                        Status = "OK"
                    }));
                }
            }
            return(Json(new AjaxResult {
                Status = "Error", ErrorMsg = "Unfollow 失败"
            }));
        }
Example #36
0
        private void DeleteUserEventMoudle_After(IUser sender, DeleteUserEventArgs eventArgs)
        {
            IUserService userService = DIContainer.Resolve <IUserService>();

            IUser takeOverUser = userService.GetUser(eventArgs.TakeOverUserName);

            if (takeOverUser != null)
            {
                //将sender的内容转交给takeOverUser,同时还可根据eventArgs.TakeOverAll判断是否接管被删除用户的全部内容
            }



            #region 数据
            //清除应用数据
            ApplicationService applicationService = new ApplicationService();
            applicationService.DeleteUser(sender.UserId, eventArgs.TakeOverUserName, eventArgs.TakeOverAll);

            //删除用户信息
            new UserProfileService().Delete(sender.UserId);

            //清除用户内容计数数据
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
            ownerDataService.ClearOwnerData(sender.UserId);



            //清除用户关于分类的数据
            CategoryService categoryService = new CategoryService();
            categoryService.CleanByUser(sender.UserId);

            //清除用户动态
            ActivityService activityService = new ActivityService();
            activityService.CleanByUser(sender.UserId);

            //清除用户评论
            new CommentService().DeleteUserComments(sender.UserId, false);

            #endregion

            #region 消息


            //清除用户关于私信的数据
            MessageService messageService = new MessageService();
            messageService.ClearSessionsFromUser(sender.UserId);

            //清除请求的用户数据
            InvitationService invitationService = new InvitationService();
            invitationService.CleanByUser(sender.UserId);

            //清除通知的用户数据
            NoticeService noticeService = new NoticeService();
            noticeService.CleanByUser(sender.UserId);

            InviteFriendService inviteFriendService = new InviteFriendService();
            inviteFriendService.CleanByUser(sender.UserId);

            //清除站外提醒的用户数据
            ReminderService reminderService = new ReminderService();
            reminderService.CleanByUser(sender.UserId);

            #endregion

            #region 关注/访客


            //清除用户关于关注用户的数据
            FollowService followService = new FollowService();
            followService.CleanByUser(sender.UserId);


            //清除访客记录的用户数据
            VisitService visitService = new VisitService(string.Empty);
            visitService.CleanByUser(sender.UserId);

            #endregion

            #region 帐号

            //清除帐号绑定数据
            var accountBindingService = new AccountBindingService();
            var accountBindings       = new AccountBindingService().GetAccountBindings(sender.UserId);
            foreach (var accountBinding in accountBindings)
            {
                accountBindingService.DeleteAccountBinding(accountBinding.UserId, accountBinding.AccountTypeKey);
            }

            #endregion

            #region 装扮

            //调整皮肤文件使用次数
            var user = userService.GetFullUser(sender.UserId);
            if (user == null)
            {
                return;
            }
            var    presentArea            = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.UserSpace);
            string defaultThemeAppearance = string.Join(",", presentArea.DefaultThemeKey, presentArea.DefaultAppearanceKey);
            if (!user.IsUseCustomStyle)
            {
                new ThemeService().ChangeThemeAppearanceUserCount(PresentAreaKeysOfBuiltIn.UserSpace, null, !string.IsNullOrEmpty(user.ThemeAppearance) ? user.ThemeAppearance : defaultThemeAppearance);
            }

            #endregion
        }
Example #37
0
        /// <summary>
        /// 关注的用户菜单控件
        /// </summary>
        /// <returns></returns>
        public ActionResult _TopFollowedUsers(string spaceKey, int topNumber)
        {
            Dictionary<long, bool> isFollowesUser = new Dictionary<long, bool>();

            long userId = UserIdToUserNameDictionary.GetUserId(spaceKey);
            long currentUserId = UserContext.CurrentUser.UserId;

            FollowService followService = new FollowService();
            IEnumerable<long> ids = followService.GetTopFollowedUserIds(userId, topNumber);

            foreach (var id in ids)
            {
                isFollowesUser[id] = followService.IsFollowed(currentUserId, id);
            }

            ViewData["isFollowesUser"] = isFollowesUser;

            if (currentUserId == userId)
            {
                ViewData["isSameUser"] = true;
            }

            ViewData["gender"] = (userService.GetUser(spaceKey) as User).Profile.Gender;
            IEnumerable<User> users = userService.GetFullUsers(ids);

            return View(users);
        }
Example #38
0
        public JsonResult GetMyFollowedUsers(int? categoryId)
        {
            long userId = 0;
            if (UserContext.CurrentUser != null)
                userId = UserContext.CurrentUser.UserId;

            var followService = new FollowService();
            var followedUsers = followService.GetFollows(userId, categoryId, Follow_SortBy.FollowerCount_Desc);
            IUserService userService = DIContainer.Resolve<IUserService>();
            return Json(userService.GetFullUsers(followedUsers.Select(n => n.FollowedUserId))
                   .Select(n => new
                   {
                       userId = n.UserId,
                       displayName = GetDisplayName(n.DisplayName, GetNoteName(followedUsers, n.UserId)),
                       userName = n.UserName,
                       trueName = n.TrueName,
                       nickName = n.NickName,
                       noteName = GetNoteName(followedUsers, n.UserId),
                       userAvatarUrl = SiteUrls.Instance().UserAvatarUrl(n, AvatarSizeType.Small)
                   }), JsonRequestBehavior.AllowGet);
        }
Example #39
0
        public JsonResult SearchUsers(UserSelectorSearchScope searchScope)
        {
            string term = Request.QueryString.GetString("q", string.Empty);
            int topNumber = 8;
            if (string.IsNullOrEmpty(term))
                return Json(new { }, JsonRequestBehavior.AllowGet);
            term = WebUtility.UrlDecode(term);
            term = term.ToLower();
            long userId = 0;
            if (UserContext.CurrentUser != null)
                userId = UserContext.CurrentUser.UserId;
            IEnumerable<User> users = null;
            var followService = new FollowService();

            var followedUsers = followService.GetFollows(userId, null, Follow_SortBy.FollowerCount_Desc);
            if (searchScope == UserSelectorSearchScope.FollowedUser)
            {
                IUserService userService = DIContainer.Resolve<IUserService>();
                users = userService.GetFullUsers(followedUsers.Select(n => n.FollowedUserId))
                       .Where(n => n.TrueName.ToLower().Contains(term)
                                   || n.NickName.ToLower().Contains(term)
                                   || GetNoteName(followedUsers, n.UserId).ToLower().Contains(term)
                                   || n.UserName.ToLower().Contains(term))
                                   .Take(topNumber);
            }
            else
            {

                UserSearcher userSearcher = (UserSearcher)SearcherFactory.GetSearcher(UserSearcher.CODE);
                UserFullTextQuery query = new UserFullTextQuery();
                query.Keyword = term;
                query.PageIndex = 1;
                query.PageSize = topNumber;
                users = userSearcher.Search(query);
            }
            return Json(users
                   .Select(n => new
                   {
                       userId = n.UserId,
                       displayName = n.DisplayName,
                       userName = n.UserName,
                       trueName = n.TrueName,
                       nickName = n.NickName,
                       noteName = GetNoteName(followedUsers, n.UserId),
                       userAvatarUrl = SiteUrls.Instance().UserAvatarUrl(n, AvatarSizeType.Small)
                   }), JsonRequestBehavior.AllowGet);
        }
        private void DeleteUserEventMoudle_After(IUser sender, DeleteUserEventArgs eventArgs)
        {
            IUserService userService = DIContainer.Resolve<IUserService>();

            #region 数据
            //清除应用数据
            applicationService.DeleteUser(sender.UserId, eventArgs.TakeOverUserName, eventArgs.TakeOverAll);

            //删除用户信息
            new UserProfileService().Delete(sender.UserId);

            //清除用户内容计数数据
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
            ownerDataService.ClearOwnerData(sender.UserId);

            //清除用户关于分类的数据
            CategoryService categoryService = new CategoryService();
            categoryService.CleanByUser(sender.UserId);

            //清除用户动态
            ActivityService activityService = new ActivityService();
            activityService.CleanByUser(sender.UserId);

            //清除用户评论
            new CommentService().DeleteUserComments(sender.UserId, false);

            #endregion

            #region 消息

            //清除用户关于私信的数据
            MessageService messageService = new MessageService();
            messageService.ClearSessionsFromUser(sender.UserId);

            //清除请求的用户数据
            InvitationService invitationService = new InvitationService();
            invitationService.CleanByUser(sender.UserId);

            //清除通知的用户数据
            NoticeService noticeService = new NoticeService();
            noticeService.CleanByUser(sender.UserId);

            InviteFriendService inviteFriendService = new InviteFriendService();
            inviteFriendService.CleanByUser(sender.UserId);

            //清除站外提醒的用户数据
            ReminderService reminderService = new ReminderService();
            reminderService.CleanByUser(sender.UserId);

            #endregion

            #region 关注/访客

            //清除用户关于关注用户的数据
            FollowService followService = new FollowService();
            followService.CleanByUser(sender.UserId);

            //清除访客记录的用户数据
            VisitService visitService = new VisitService(string.Empty);
            visitService.CleanByUser(sender.UserId);

            #endregion

            #region 帐号

            //清除帐号绑定数据
            var accountBindingService = new AccountBindingService();
            var accountBindings = new AccountBindingService().GetAccountBindings(sender.UserId);
            foreach (var accountBinding in accountBindings)
            {
                accountBindingService.DeleteAccountBinding(accountBinding.UserId, accountBinding.AccountTypeKey);
            }

            #endregion

            #region 装扮

            //调整皮肤文件使用次数
            var user = userService.GetFullUser(sender.UserId);
            if (user == null)
                return;
            var presentArea = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.UserSpace);
            string defaultThemeAppearance = string.Join(",", presentArea.DefaultThemeKey, presentArea.DefaultAppearanceKey);
            if (!user.IsUseCustomStyle)
                new ThemeService().ChangeThemeAppearanceUserCount(PresentAreaKeysOfBuiltIn.UserSpace, null, !string.IsNullOrEmpty(user.ThemeAppearance) ? user.ThemeAppearance : defaultThemeAppearance);

            #endregion
        }
Example #41
0
        /// <summary>
        /// 用户空间文章左侧控制面板
        /// </summary>
        /// <param name="menu">菜单项标识</param>
        public ActionResult _Panel(string spaceKey, string menu = null)
        {
            User user = userService.GetFullUser(spaceKey);
            ViewData["user"] = user;

            //用户文章数
            long threadCount = ownerDataService.GetLong(user.UserId, OwnerDataKeys.Instance().ThreadCount());
            ViewData["threadCount"] = threadCount;

            IUser currentUser = UserContext.CurrentUser;
            if (currentUser != null && currentUser.UserId != user.UserId)
            {
                bool followed = new FollowService().IsFollowed(currentUser.UserId, user.UserId);
                ViewData["followed"] = followed;
            }

            return View();
        }
Example #42
0
        ///<overloads>隐私验证</overloads>
        /// <summary>
        /// 隐私验证
        /// </summary>        
        /// <param name="userId">用户Id</param>
        /// <param name="toUserId">被验证用户Id</param>
        /// <param name="itemKey">隐私项目Key</param>
        /// <returns>true-验证通过,false-验证失败</returns>
        public bool Validate(long userId, long toUserId, string itemKey)
        {
            if (toUserId == userId)
                return true;

            //被验证用户为超级管理员
            IUserService userService = DIContainer.Resolve<IUserService>();
            IUser toUser = null;
            if (toUserId > 0)
                toUser = userService.GetUser(toUserId);
            if (toUser != null)
            {
                if (toUser.IsSuperAdministrator())
                    return true;

                //被验证用户为黑名单用户
                if (IsStopedUser(userId, toUserId))
                    return false;
            }
            Dictionary<string, PrivacyStatus> userUserPrivacySettings = GetUserPrivacySettings(userId);
            if (userUserPrivacySettings.ContainsKey(itemKey))
            {
                switch (userUserPrivacySettings[itemKey])
                {
                    case PrivacyStatus.Public:
                        return true;
                    case PrivacyStatus.Part:
                        return toUser != null && ValidateUserPrivacySpecifyObject(userId, toUserId, itemKey);
                    case PrivacyStatus.Private:
                        return false;
                    default:
                        return false;
                }
            }
            var privacyItem = GetPrivacyItem(itemKey);
            if (privacyItem != null)
            {
                switch (privacyItem.PrivacyStatus)
                {
                    case PrivacyStatus.Private:
                        return false;
                    case PrivacyStatus.Part:
                        FollowService followService = new FollowService();
                        return followService.IsFollowed(userId, toUserId);
                    case PrivacyStatus.Public:
                        return true;
                    default:
                        return true;
                }
            }
            return false;
        }