public UserProfileEditModel(UserProfile userProfile, User user) { if (userProfile != null) { Birthday = userProfile.Birthday; BirthdayType = userProfile.BirthdayType; Email = !string.IsNullOrEmpty(userProfile.Email) ? userProfile.Email : user.AccountEmail; Gender = userProfile.Gender; HomeAreaCode = userProfile.HomeAreaCode; Introduction = userProfile.Introduction; Mobile = userProfile.Mobile; Msn = userProfile.Msn; NowAreaCode = userProfile.NowAreaCode; QQ = userProfile.QQ; UserId = userProfile.UserId; } if (user != null) { TrueName = user.TrueName; NickName = user.NickName; AccountEmail = user.AccountEmail; UserName = user.UserName; IsEmailVerified = user.IsEmailVerified; } }
void NoEmailNotice(User sender, CreateUserEventArgs eventArgs) { if (string.IsNullOrEmpty(sender.AccountEmail)) { NoticeService noticeService = new NoticeService(); Notice notice = Notice.New(); notice.TemplateName = "NoEmailNotice"; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActorUrl = SiteUrls.Instance().EditUserProfile(sender.UserName); notice.UserId = sender.UserId; notice.Status = NoticeStatus.Unhandled; noticeService.Create(notice); } }
/// <summary> /// 首次上传头像加分 /// </summary> /// <param name="sender">用户实体</param> /// <param name="eventArgs">事件参数</param> public void AutoNoModeratedUserNoticeEventModule_After(User sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().AutoNoModeratedUser()) { Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = 0; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.TemplateName = "AutoNoModeratedUser"; notice.RelativeObjectName = "我的权限"; notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().UserModerated(sender.UserName)); notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().ListNotices(sender.UserName, null, null)); noticeService.Create(notice); } }
/// <summary> /// 关注按钮 /// </summary> /// <param name="currentUser">当前用户</param> /// <param name="followedUser">要关注的用户</param> /// <returns></returns> public ActionResult _FollowedButton(User currentUser, User followedUser) { ViewData["currentUser"] = currentUser; ViewData["followedUser"] = followedUser; if (currentUser != null && currentUser.UserId != followedUser.UserId) { bool currentUserIsFollowedUser = false; ViewData["currentUserIsFollowedUser"] = currentUserIsFollowedUser; } bool isFollowed = currentUser.IsFollowed(followedUser.UserId); ViewData["isFollowed"] = isFollowed; return View(); }
/// <summary> /// 群组地区导航内容块 /// </summary> /// <returns></returns> public ActionResult _AreaGroups(int topNumber, string areaCode, long? categoryId, SortBy_Group sortBy = SortBy_Group.DateCreated_Desc) { IUser iUser = (User)UserContext.CurrentUser; User user = null; if (iUser == null) { user = new User(); } else { user = userService.GetFullUser(iUser.UserId); } if (string.IsNullOrEmpty(areaCode) && Request.Cookies["AreaGroupCookie" + user.UserId] != null && !string.IsNullOrEmpty(Request.Cookies["AreaGroupCookie" + user.UserId].Value)) areaCode = Request.Cookies["AreaGroupCookie" + user.UserId].Value; if (string.IsNullOrEmpty(areaCode)) { string ip = WebUtility.GetIP(); areaCode = IPSeeker.Instance().GetAreaCode(ip); if (string.IsNullOrEmpty(areaCode) && user.Profile != null) { areaCode = user.Profile.NowAreaCode; } } ViewData["areaCode"] = areaCode; if (!string.IsNullOrEmpty(areaCode)) { Area area = areaService.Get(areaCode); if (!string.IsNullOrEmpty(area.ParentCode)) { Area parentArea = areaService.Get(area.ParentCode); ViewData["parentCode"] = parentArea.AreaCode; } } IEnumerable<GroupEntity> groups = groupService.GetTops(topNumber, areaCode, categoryId, sortBy); HttpCookie cookie = new HttpCookie("AreaGroupCookie" + user.UserId, areaCode); Response.Cookies.Add(cookie); return PartialView(groups); }
/// <summary> /// 创建用户的时候修改积分 /// </summary> /// <param name="sender">创建用户角色</param> /// <param name="eventArgs">参数</param> void RegisterEventModule_After(User sender, CreateUserEventArgs eventArgs) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_Register"), sender.UserName); pointService.GenerateByRole(sender.UserId, PointItemKeys.Instance().Register(), description, true); }
/// <summary> /// 新建实体时使用 /// </summary> public static User New() { User user = new User(); user.UserName = string.Empty; user.Password = string.Empty; user.PasswordQuestion = string.Empty; user.PasswordAnswer = string.Empty; user.AccountEmail = string.Empty; user.AccountMobile = string.Empty; user.TrueName = string.Empty; user.NickName = string.Empty; user.DateCreated = DateTime.UtcNow; user.IpCreated = string.Empty; user.LastActivityTime = DateTime.UtcNow; user.LastAction = string.Empty; user.IpLastActivity = string.Empty; user.BanReason = string.Empty; user.BanDeadline = DateTime.UtcNow; user.ThemeAppearance = string.Empty; user.FollowedCount = 0; user.FollowerCount = 0; user.Avatar = "avatar_default"; user.Rank = 1; return user; }
/// <summary> /// 更新索引 /// </summary> /// <param name="user">待更新的用户</param> public void Update(User user) { Document doc = UserIndexDocument.Convert(user); searchEngine.Update(doc, user.UserId.ToString(), UserIndexDocument.UserId); }
/// <summary> /// 添加索引 /// </summary> /// <param name="user">待添加的用户</param> public void Insert(User user) { Insert(new User[] { user }); }
/// <summary> /// User转换成<see cref="Lucene.Net.Documents.Document"/> /// </summary> /// <param name="user">用户实体</param> /// <returns>Lucene.Net.Documents.Document</returns> public static Document Convert(User user) { Document doc = new Document(); if (user == null) return doc; //索引用户基本信息 doc.Add(new Field(UserIndexDocument.UserId, user.UserId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(UserIndexDocument.UserName, user.UserName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(UserIndexDocument.TrueName, user.TrueName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(UserIndexDocument.NickName, user.NickName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(UserIndexDocument.DateCreated, DateTools.DateToString(user.DateCreated, DateTools.Resolution.DAY), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(UserIndexDocument.LastActivityTime, DateTools.DateToString(user.LastActivityTime, DateTools.Resolution.MINUTE), Field.Store.YES, Field.Index.NOT_ANALYZED)); //索引用户名称的拼音信息方便支持拼音搜索 doc.Add(new Field(UserIndexDocument.PinyinName, Pinyin.GetPinyin(user.UserName.ToLower()), Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(UserIndexDocument.PinyinName, Pinyin.GetPinyin(user.UserName.ToLower()).Replace(" ", ""), Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(UserIndexDocument.ShortPinyinName, Pinyin.GetInitials(user.UserName.ToLower()), Field.Store.YES, Field.Index.ANALYZED)); if (!string.IsNullOrEmpty(user.NickName)) { doc.Add(new Field(UserIndexDocument.PinyinName, Pinyin.GetPinyin(user.NickName.ToLower()), Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(UserIndexDocument.PinyinName, Pinyin.GetPinyin(user.NickName.ToLower()).Replace(" ", ""), Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(UserIndexDocument.ShortPinyinName, Pinyin.GetInitials(user.NickName.ToLower()), Field.Store.YES, Field.Index.ANALYZED)); } if (!string.IsNullOrEmpty(user.TrueName)) { doc.Add(new Field(UserIndexDocument.PinyinName, Pinyin.GetPinyin(user.TrueName.ToLower()), Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(UserIndexDocument.PinyinName, Pinyin.GetPinyin(user.TrueName.ToLower()).Replace(" ", ""), Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(UserIndexDocument.ShortPinyinName, Pinyin.GetInitials(user.TrueName.ToLower()), Field.Store.YES, Field.Index.ANALYZED)); } //索引用户资料 if (user.Profile != null) { doc.Add(new Field(UserIndexDocument.Gender, ((int)user.Profile.Gender).ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); if (user.Profile.Birthday != null) { doc.Add(new Field(UserIndexDocument.Birthday, DateTools.DateToString(user.Profile.Birthday, DateTools.Resolution.DAY), Field.Store.YES, Field.Index.NOT_ANALYZED)); //注意此处不能用NumericField,因为Lucene有NumericField不能序列化的bug,会导致采用WCF分布式部署时调用失败,所以只能以字符串的方式索引 string birthdayYear = user.Profile.Birthday.Year.ToString().PadLeft(3, '0'); doc.Add(new Field(UserIndexDocument.BirthdayYear, birthdayYear, Field.Store.YES, Field.Index.NOT_ANALYZED)); } if (user.Profile.NowAreaCode != null) { doc.Add(new Field(UserIndexDocument.NowAreaCode, user.Profile.NowAreaCode, Field.Store.YES, Field.Index.NOT_ANALYZED)); } if (user.Profile.HomeAreaCode != null) { doc.Add(new Field(UserIndexDocument.HomeAreaCode, user.Profile.HomeAreaCode, Field.Store.YES, Field.Index.NOT_ANALYZED)); } int hasAvatarImage = 0; if (user.HasAvatar) { hasAvatarImage = 1; } doc.Add(new Field(UserIndexDocument.HasAvatarImage, hasAvatarImage.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); if (user.Profile.Introduction != null) { doc.Add(new Field(UserIndexDocument.Introduction, user.Profile.Introduction.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); } foreach (EducationExperience educationExperience in user.Profile.EducationExperience) { doc.Add(new Field(UserIndexDocument.School, educationExperience.School.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); } foreach (WorkExperience workExperience in user.Profile.WorkExperience) { doc.Add(new Field(UserIndexDocument.CompanyName, workExperience.CompanyName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); } } //索引tag TagService tagService = new TagService(TenantTypeIds.Instance().User()); //fixed by jiangshl,已按要求修改 IEnumerable<ItemInTag> itemInTags = tagService.GetItemInTagsOfItem(user.UserId); foreach (ItemInTag itemInTag in itemInTags) { doc.Add(new Field(UserIndexDocument.TagName, itemInTag.TagName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); } return doc; }
/// <summary> /// 首次上传头像加分 /// </summary> /// <param name="sender">用户实体</param> /// <param name="eventArgs">事件参数</param> public void UserPointEventModule_After(User sender, CropAvatarEventArgs eventArgs) { string pointItemKey = string.Empty; string eventOperationType = string.Empty; if (eventArgs.IsFirst) { PointService pointService = new PointService(); pointItemKey = PointItemKeys.Instance().FirstUploadAvatar(); string description = ResourceAccessor.GetString("PointRecord_Pattern_FirstUploadAvatar"); pointService.GenerateByRole(sender.UserId, pointItemKey, description, true); } }
/// <summary> /// 初始化用户的应用 /// </summary> /// <param name="sender">用户实体</param> /// <param name="eventArgs">事件参数</param> private void InitAppForUserEventMoudle_After(User sender, CreateUserEventArgs eventArgs) { if (sender == null) return; applicationService.InstallApplicationsOfPresentAreaOwner(PresentAreaKeysOfBuiltIn.UserSpace, sender.UserId); var presentArea = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.UserSpace); new ThemeService().ChangeThemeAppearanceUserCount(PresentAreaKeysOfBuiltIn.UserSpace, null, presentArea.DefaultThemeKey + "," + presentArea.DefaultAppearanceKey); }
/// <summary> /// 用户解除管制后增加邀请人积分 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> void FreeModeratedUser_After(User sender, CommonEventArgs eventArgs) { if (sender == null || string.IsNullOrEmpty(eventArgs.EventOperationType)) return; if (eventArgs.EventOperationType == EventOperationType.Instance().CancelModerateUser() || eventArgs.EventOperationType == EventOperationType.Instance().AutoNoModeratedUser()) { PointService pointService = new PointService(); string pointItemKey = string.Empty; pointItemKey = PointItemKeys.Instance().FreeModeratedUser(); if (sender != null) { InviteFriendRecord invitingUser = inviteFriendService.GetInvitingUserId(sender.UserId); if (invitingUser != null) { if (!invitingUser.InvitingUserHasBeingRewarded) { string userName = UserIdToUserNameDictionary.GetUserName(invitingUser.UserId); string invitedName = UserIdToUserNameDictionary.GetUserName(sender.UserId); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_FreeModeratedUser"), userName, invitedName); pointService.GenerateByRole(invitingUser.UserId, pointItemKey, description); inviteFriendService.RewardingUser(invitingUser.UserId); } } } } }
/// <summary> /// 批量设置请求状态的方法 /// </summary> /// <param name="spaceKey">用户名</param> /// <param name="invitationIds">被设置的Id集合</param> /// <param name="invitationStatus">要设置成的状态</param> private void BatchSetStatus(IEnumerable<long> invitationIds, User user, InvitationStatus status) { foreach (int item in invitationIds) SetStatus(item, user.UserId, status); }