/// <summary> /// 评论回答的动态 /// </summary> /// <param name="ActivityId"></param> public ActionResult _CommentAskAnswer(long ActivityId) { Activity activity = activityService.Get(ActivityId); if (activity == null) { return(Content(string.Empty)); } ViewData["Activity"] = activity; Comment comment = commentService.Get(activity.SourceId); if (comment == null) { return(Content(string.Empty)); } AskAnswer answer = askService.GetAnswer(comment.CommentedObjectId); if (answer == null) { return(Content(string.Empty)); } ViewData["answer"] = answer; IUser user = userService.GetUser(activity.UserId); ViewData["user"] = user; return(View(comment)); }
/// <summary> /// 回答问题的动态 /// </summary> /// <param name="ActivityId"></param> //[DonutOutputCache(CacheProfile = "Frequently")] public ActionResult _CreateAskAnswer(long ActivityId) { Activity activity = activityService.Get(ActivityId); if (activity == null) { return(Content(string.Empty)); } ViewData["Activity"] = activity; AskAnswer answer = askService.GetAnswer(activity.SourceId); if (answer == null) { return(Content(string.Empty)); } IEnumerable <Attachment> attachments = answerAttachementService.GetsByAssociateId(answer.AnswerId); if (attachments != null && attachments.Count() > 0) { IEnumerable <Attachment> attachmentImages = attachments.Where(n => n.MediaType == MediaType.Image); ViewData["attachments"] = attachmentImages; } return(View(answer)); }
public JsonResult _EditAnswer(AskAnswerEditModel model) { AskAnswer answer = model.AsAskAnswer(); askSevice.UpdateAnswer(answer); return(Json(new StatusMessageData(StatusMessageType.Success, "更新成功!"))); }
/// <summary> /// 回答增量索引 /// </summary> /// <param name="answer"></param> /// <param name="eventArgs"></param> private void AskAnswer_After(AskAnswer answer, CommonEventArgs eventArgs) { if (answer == null) { return; } if (askSearcher == null) { askSearcher = (AskSearcher)SearcherFactory.GetSearcher(AskSearcher.CODE); } //创建回答、更新回答、删除回答时更新问题索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Create() || eventArgs.EventOperationType == EventOperationType.Instance().Update() || eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { askSearcher.Update(answer.Question); } }
/// <summary> /// 回答操作日志事件处理 /// </summary> private void AskAnswerOperationLogEventModule_After(AskAnswer senders, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo); entry.ApplicationId = entry.ApplicationId; entry.Source = AskConfig.Instance().ApplicationName; entry.OperationType = eventArgs.EventOperationType; entry.OperationObjectName = StringUtility.Trim(senders.Body, 20); entry.OperationObjectId = senders.QuestionId; entry.Description = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType), "回答", entry.OperationObjectName); OperationLogService logService = Tunynet.DIContainer.Resolve <OperationLogService>(); logService.Create(entry); } }
/// <summary> /// 回答被赞同的相关事件处理 /// </summary> private void AskAnswerSupportEventModule_After(long objectId, SupportOpposeEventArgs eventArgs) { if (eventArgs.TenantTypeId == TenantTypeIds.Instance().AskAnswer()) { //如果不是第一次顶踩,则不处理 if (!eventArgs.FirstTime) { return; } if (eventArgs.EventOperationType == EventOperationType.Instance().Support()) { AskAnswer answer = askService.GetAnswer(objectId); AskQuestion question = answer.Question; //创建顶回答的动态[关注回答者的粉丝可以看到该顶信息] Activity activityOfFollower = Activity.New(); activityOfFollower.ActivityItemKey = ActivityItemKeys.Instance().SupportAskAnswer(); activityOfFollower.ApplicationId = AskConfig.Instance().ApplicationId; activityOfFollower.IsOriginalThread = true; activityOfFollower.IsPrivate = false; activityOfFollower.TenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfFollower.SourceId = answer.AnswerId; activityOfFollower.UserId = eventArgs.UserId; activityOfFollower.ReferenceId = answer.AnswerId; activityOfFollower.ReferenceTenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfFollower.OwnerId = eventArgs.UserId; activityOfFollower.OwnerName = userService.GetFullUser(eventArgs.UserId).DisplayName; activityOfFollower.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(activityOfFollower, true); //创建顶回答的动态[关注该问题的用户可以看到该顶信息] Activity activityOfQuestionSubscriber = Activity.New(); activityOfQuestionSubscriber.ActivityItemKey = ActivityItemKeys.Instance().SupportAskAnswer(); activityOfQuestionSubscriber.ApplicationId = AskConfig.Instance().ApplicationId; activityOfQuestionSubscriber.IsOriginalThread = true; activityOfQuestionSubscriber.IsPrivate = false; activityOfQuestionSubscriber.TenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfQuestionSubscriber.SourceId = answer.AnswerId; activityOfQuestionSubscriber.UserId = eventArgs.UserId; activityOfQuestionSubscriber.ReferenceId = answer.AnswerId; activityOfQuestionSubscriber.ReferenceTenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfQuestionSubscriber.OwnerId = question.QuestionId; activityOfQuestionSubscriber.OwnerName = question.Subject; activityOfQuestionSubscriber.OwnerType = ActivityOwnerTypes.Instance().AskQuestion(); activityService.Generate(activityOfQuestionSubscriber, false); //处理积分和威望 string pointItemKey = PointItemKeys.Instance().Ask_BeSupported(); //回答收到赞同时产生积分 string eventOperationType = EventOperationType.Instance().Support(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "回答", question.Subject); pointService.GenerateByRole(answer.UserId, pointItemKey, description); //记录用户的威望 PointItem pointItem = pointService.GetPointItem(pointItemKey); ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem.ReputationPoints); //赞同者自动关注问题 if (!subscribeService.IsSubscribed(question.QuestionId, eventArgs.UserId)) { subscribeService.Subscribe(question.QuestionId, eventArgs.UserId); //问题关注数计数,用于“可能感兴趣的问题”关联表查询 countService.ChangeCount(CountTypes.Instance().QuestionFollowerCount(), question.QuestionId, question.UserId, 1, false); } //增加赞同的用户计数 ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().AnswerSupportCount(), 1); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Oppose()) { AskAnswer answer = askService.GetAnswer(objectId); AskQuestion question = answer.Question; //处理积分和威望 string pointItemKey = PointItemKeys.Instance().Ask_BeOpposed(); //回答收到反对时产生积分 string eventOperationType = EventOperationType.Instance().Oppose(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "回答", question.Subject); pointService.GenerateByRole(answer.UserId, pointItemKey, description); //记录用户的威望 PointItem pointItem = pointService.GetPointItem(pointItemKey); ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem.ReputationPoints); //反对者自动关注问题 if (!subscribeService.IsSubscribed(question.QuestionId, eventArgs.UserId)) { subscribeService.Subscribe(answer.QuestionId, eventArgs.UserId); //问题关注数计数,用于“可能感兴趣的问题”关联表查询 countService.ChangeCount(CountTypes.Instance().QuestionFollowerCount(), question.QuestionId, question.UserId, 1, false); } //增加反对的用户计数 ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().AnswerOpposeCount(), 1); } } }
/// <summary> /// 回答增删改等触发的事件 /// </summary> private void AskAnswerEventModule_After(AskAnswer answer, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { //向关注该问题的用户发送通知 IEnumerable <long> userIds = subscribeService.GetUserIdsOfObject(answer.QuestionId); AskQuestion question = answer.Question; foreach (var userId in userIds) { //通知的对象排除掉自己 if (userId == answer.UserId) { continue; } Notice notice = Notice.New(); notice.UserId = userId; notice.ApplicationId = AskConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Reply(); notice.LeadingActor = answer.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().AskUser(UserIdToUserNameDictionary.GetUserName(answer.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(question.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().AskQuestionDetail(question.QuestionId)); notice.TemplateName = NoticeTemplateNames.Instance().NewAnswer(); noticeService.Create(notice); } //自动关注(回答者自动关注[订阅]该问题) if (!subscribeService.IsSubscribed(question.QuestionId, answer.UserId)) { subscribeService.Subscribe(question.QuestionId, answer.UserId); //问题关注数计数,用于“可能感兴趣的问题”关联表查询 countService.ChangeCount(CountTypes.Instance().QuestionFollowerCount(), question.QuestionId, question.UserId, 1, false); } } else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { //删除回答者对问题的关注 subscribeService.CancelSubscribe(answer.QuestionId, answer.UserId); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Update()) { AskQuestion question = new AskService().GetQuestion(answer.QuestionId); if (answer.IsBest && question.Status == QuestionStatus.Resolved && !question.IsTrated) { //如果问题有悬赏则悬赏分值转移到回答者的帐户(如有交易税,需要扣除) if (question.Reward > 0) { pointService.Trade(question.UserId, answer.UserId, question.Reward, string.Format(Resource.PointRecord_Pattern_QuestionReward, question.Subject), false); } askService.SetTradeStatus(question, true); //处理采纳回答相关的积分和威望 string pointItemKey_AcceptedAnswer = PointItemKeys.Instance().Ask_AcceptedAnswer(); //采纳回答时产生积分 string description_AcceptedAnswer = string.Format(Resource.PointRecord_Pattern_AcceptedAnswer, question.Subject); pointService.GenerateByRole(question.UserId, pointItemKey_AcceptedAnswer, description_AcceptedAnswer); //记录用户的威望 PointItem pointItem_AcceptedAnswer = pointService.GetPointItem(pointItemKey_AcceptedAnswer); ownerDataService.Change(question.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem_AcceptedAnswer.ReputationPoints); //处理回答被采纳相关的积分和威望 string pointItemKey_AnswerWereAccepted = PointItemKeys.Instance().Ask_AnswerWereAccepted(); //回答被采纳时产生积分 string description_AnswerWereAccepted = string.Format(Resource.PointRecord_Pattern_AnswerWereAccepted, question.Subject); pointService.GenerateByRole(answer.UserId, pointItemKey_AnswerWereAccepted, description_AnswerWereAccepted); //记录用户的威望 PointItem pointItem_AnswerWereAccepted = pointService.GetPointItem(pointItemKey_AnswerWereAccepted); ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem_AnswerWereAccepted.ReputationPoints); //向关注该问题的用户发送通知 IEnumerable <long> userIds = subscribeService.GetUserIdsOfObject(answer.QuestionId); foreach (var userId in userIds) { //通知的对象排除掉自己 if (userId == question.UserId) { continue; } Notice notice = Notice.New(); notice.UserId = userId; notice.ApplicationId = AskConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = question.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().AskUser(UserIdToUserNameDictionary.GetUserName(question.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(question.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().AskQuestionDetail(question.QuestionId)); notice.TemplateName = NoticeTemplateNames.Instance().SetBestAnswer(); noticeService.Create(notice); } } } }
/// <summary> /// 回答审核状态变更事件 /// </summary> private void AskAnswerAuditEventModule_After(AskAnswer answer, AuditEventArgs eventArgs) { bool?auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); //审核状态发生变化时处理积分 string pointItemKey = string.Empty; string eventOperationType = string.Empty; if (auditDirection == true) //加积分 { pointItemKey = PointItemKeys.Instance().Ask_CreateAnswer(); if (eventArgs.OldAuditStatus == null) { eventOperationType = EventOperationType.Instance().Create(); } else { eventOperationType = EventOperationType.Instance().Approved(); } } else if (auditDirection == false) //减积分 { pointItemKey = PointItemKeys.Instance().Ask_DeleteAnswer(); if (eventArgs.NewAuditStatus == null) { eventOperationType = EventOperationType.Instance().Delete(); } else { eventOperationType = EventOperationType.Instance().Disapproved(); } } if (!string.IsNullOrEmpty(pointItemKey)) { AskQuestion question = answer.Question; string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "回答", HtmlUtility.TrimHtml(answer.Body, 10)); pointService.GenerateByRole(answer.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete()); //记录用户的威望 PointItem pointItem = pointService.GetPointItem(pointItemKey); ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem.ReputationPoints); } //审核状态发生变化时生成动态 if (auditDirection == true) { AskQuestion question = answer.Question; //创建回答的动态[关注回答者的粉丝可以看到该回答] Activity activityOfFollower = Activity.New(); activityOfFollower.ActivityItemKey = ActivityItemKeys.Instance().CreateAskAnswer(); activityOfFollower.ApplicationId = AskConfig.Instance().ApplicationId; //判断是否有图片、音频、视频 AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().AskAnswer()); IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(answer.AnswerId); if (attachments != null && attachments.Any(n => n.MediaType == MediaType.Image)) { activityOfFollower.HasImage = true; } activityOfFollower.IsOriginalThread = true; activityOfFollower.IsPrivate = false; activityOfFollower.TenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfFollower.SourceId = answer.AnswerId; activityOfFollower.UserId = answer.UserId; activityOfFollower.ReferenceId = answer.QuestionId; activityOfFollower.ReferenceTenantTypeId = TenantTypeIds.Instance().AskQuestion(); activityOfFollower.OwnerId = answer.UserId; activityOfFollower.OwnerName = answer.Author; activityOfFollower.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(activityOfFollower, true); //创建回答的动态[关注该问题的用户可以看到该回答] Activity activityOfQuestionSubscriber = Activity.New(); activityOfQuestionSubscriber.ActivityItemKey = ActivityItemKeys.Instance().CreateAskAnswer(); activityOfQuestionSubscriber.ApplicationId = AskConfig.Instance().ApplicationId; activityOfQuestionSubscriber.HasImage = activityOfFollower.HasImage; activityOfQuestionSubscriber.IsOriginalThread = true; activityOfQuestionSubscriber.IsPrivate = false; activityOfQuestionSubscriber.TenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfQuestionSubscriber.SourceId = answer.AnswerId; activityOfQuestionSubscriber.UserId = answer.UserId; activityOfQuestionSubscriber.ReferenceId = answer.QuestionId; activityOfQuestionSubscriber.ReferenceTenantTypeId = TenantTypeIds.Instance().AskQuestion(); activityOfQuestionSubscriber.OwnerId = question.QuestionId; activityOfQuestionSubscriber.OwnerName = question.Subject; activityOfQuestionSubscriber.OwnerType = ActivityOwnerTypes.Instance().AskQuestion(); activityService.Generate(activityOfQuestionSubscriber, false); } else if (auditDirection == false) { activityService.DeleteSource(TenantTypeIds.Instance().AskAnswer(), answer.AnswerId); } }
/// <summary> /// 评论的相关事件处理 /// </summary> private void CommentEventModule_After(Comment comment, AuditEventArgs eventArgs) { if (comment.TenantTypeId != TenantTypeIds.Instance().AskQuestion() && comment.TenantTypeId != TenantTypeIds.Instance().AskAnswer()) { return; } bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); AskQuestion question = null; //评论问题 if (comment.TenantTypeId == TenantTypeIds.Instance().AskQuestion()) { //生成动态 if (auditDirection == true) { question = askService.GetQuestion(comment.CommentedObjectId); if (question.UserId != comment.UserId) { //创建评论的动态[关注评论者的粉丝可以看到该评论] Activity activityOfFollower = Activity.New(); activityOfFollower.ActivityItemKey = ActivityItemKeys.Instance().CommentAskQuestion(); activityOfFollower.ApplicationId = AskConfig.Instance().ApplicationId; activityOfFollower.IsOriginalThread = true; activityOfFollower.IsPrivate = false; activityOfFollower.TenantTypeId = TenantTypeIds.Instance().Comment(); activityOfFollower.SourceId = comment.Id; activityOfFollower.UserId = comment.UserId; activityOfFollower.ReferenceId = question.QuestionId; activityOfFollower.ReferenceTenantTypeId = TenantTypeIds.Instance().AskQuestion(); activityOfFollower.OwnerId = comment.UserId; activityOfFollower.OwnerName = comment.Author; activityOfFollower.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(activityOfFollower, true); //创建评论的动态[关注该问题的用户可以看到该评论] Activity activityOfQuestionSubscriber = Activity.New(); activityOfQuestionSubscriber.ActivityItemKey = ActivityItemKeys.Instance().CommentAskQuestion(); activityOfQuestionSubscriber.ApplicationId = AskConfig.Instance().ApplicationId; activityOfQuestionSubscriber.IsOriginalThread = true; activityOfQuestionSubscriber.IsPrivate = false; activityOfQuestionSubscriber.TenantTypeId = TenantTypeIds.Instance().Comment(); activityOfQuestionSubscriber.SourceId = comment.Id; activityOfQuestionSubscriber.UserId = comment.UserId; activityOfQuestionSubscriber.ReferenceId = question.QuestionId; activityOfQuestionSubscriber.ReferenceTenantTypeId = TenantTypeIds.Instance().AskQuestion(); activityOfQuestionSubscriber.OwnerId = question.QuestionId; activityOfQuestionSubscriber.OwnerName = question.Subject; activityOfQuestionSubscriber.OwnerType = ActivityOwnerTypes.Instance().AskQuestion(); activityService.Generate(activityOfQuestionSubscriber, false); } } else if (auditDirection == false) { activityService.DeleteSource(TenantTypeIds.Instance().Comment(), comment.Id); } } //评论回答 else if (comment.TenantTypeId == TenantTypeIds.Instance().AskAnswer()) { //生成动态 if (auditDirection == true) { AskAnswer answer = askService.GetAnswer(comment.CommentedObjectId); question = answer.Question; if (answer.UserId != comment.UserId) { //创建评论的动态[关注评论者的粉丝可以看到该评论] Activity activityOfFollower = Activity.New(); activityOfFollower.ActivityItemKey = ActivityItemKeys.Instance().CommentAskAnswer(); activityOfFollower.ApplicationId = AskConfig.Instance().ApplicationId; activityOfFollower.IsOriginalThread = true; activityOfFollower.IsPrivate = false; activityOfFollower.TenantTypeId = TenantTypeIds.Instance().Comment(); activityOfFollower.SourceId = comment.Id; activityOfFollower.UserId = comment.UserId; activityOfFollower.ReferenceId = answer.AnswerId; activityOfFollower.ReferenceTenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfFollower.OwnerId = comment.UserId; activityOfFollower.OwnerName = comment.Author; activityOfFollower.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(activityOfFollower, true); //创建评论的动态[关注该问题的用户可以看到该评论] Activity activityOfQuestionSubscriber = Activity.New(); activityOfQuestionSubscriber.ActivityItemKey = ActivityItemKeys.Instance().CommentAskAnswer(); activityOfQuestionSubscriber.ApplicationId = AskConfig.Instance().ApplicationId; activityOfQuestionSubscriber.IsOriginalThread = true; activityOfQuestionSubscriber.IsPrivate = false; activityOfQuestionSubscriber.TenantTypeId = TenantTypeIds.Instance().Comment(); activityOfQuestionSubscriber.SourceId = comment.Id; activityOfQuestionSubscriber.UserId = comment.UserId; activityOfQuestionSubscriber.ReferenceId = answer.AnswerId; activityOfQuestionSubscriber.ReferenceTenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfQuestionSubscriber.OwnerId = question.QuestionId; activityOfQuestionSubscriber.OwnerName = question.Subject; activityOfQuestionSubscriber.OwnerType = ActivityOwnerTypes.Instance().AskQuestion(); activityService.Generate(activityOfQuestionSubscriber, false); } } else if (auditDirection == false) { activityService.DeleteSource(TenantTypeIds.Instance().Comment(), comment.Id); } } ////关注的问题有新评论时,自动通知关注者 //IEnumerable<long> userIds = subscribeService.GetUserIdsOfObject(question.QuestionId); //foreach (var userId in userIds) //{ // //通知的对象排除掉自己 // if (userId == comment.UserId) // { // continue; // } // Notice notice = Notice.New(); // notice.UserId = userId; // notice.ApplicationId = AskConfig.Instance().ApplicationId; // notice.TypeId = NoticeTypeIds.Instance().Hint(); // notice.LeadingActor = comment.Author; // notice.LeadingActorUrl =SiteUrls.FullUrl(SiteUrls.Instance().AskUser(UserIdToUserNameDictionary.GetUserName(comment.UserId))); // notice.RelativeObjectName = HtmlUtility.TrimHtml(question.Subject, 64); // notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().AskQuestionDetail(question.QuestionId)); // notice.TemplateName = NoticeTemplateNames.Instance().NewAskComment(); // noticeService.Create(notice); //} //评论者自动关注该问题 if (!subscribeService.IsSubscribed(question.QuestionId, comment.UserId)) { subscribeService.Subscribe(question.QuestionId, comment.UserId); //问题关注数计数,用于“可能感兴趣的问题”关联表查询 countService.ChangeCount(CountTypes.Instance().QuestionFollowerCount(), question.QuestionId, question.UserId, 1, false); } }
public ActionResult _EditAnswer(long answerId) { AskAnswer askAnswer = askSevice.GetAnswer(answerId); return(View(askAnswer.AsEditModel())); }