コード例 #1
0
ファイル: Authorizer.cs プロジェクト: x1987624/SNS
        /// <summary>
        /// 创建回答
        /// </summary>
        /// <remarks>
        /// 1.登录用户可以回答问题
        /// 2.问题提问者不得回答自己的问题
        /// 3.每个回答者针对每个问题只能回答一次
        /// </remarks>
        public static bool Answer_Create(this Authorizer authorizer, AskQuestion question, out string errorMessage)
        {
            errorMessage = string.Empty;
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                errorMessage = "您需要先登录,才能回答";
                return(false);
            }
            if (question.UserId == currentUser.UserId)
            {
                errorMessage = "提问者不可以回答自己的问题";
                return(false);
            }
            if (question.Status != QuestionStatus.Unresolved)
            {
                errorMessage = "只有未解决状态的问题,才能回答";
                return(false);
            }
            AskAnswer answer = new AskService().GetUserAnswerByQuestionId(currentUser.UserId, question.QuestionId);

            if (answer != null)
            {
                errorMessage = "您已经回答过一次,不可重复回答";
                return(false);
            }
            bool result = authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Ask_CreateAnswer());

            if (!result && currentUser.IsModerated)
            {
                errorMessage = Resources.Resource.Description_ModeratedUser_CreateAnswerDenied;
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// 转换成AskAnswer类型
        /// </summary>
        /// <returns>回答实体</returns>
        public AskAnswer AsAskAnswer()
        {
            AskAnswer askAnswer = null;

            //发布回答
            if (this.AnswerId == 0)
            {
                askAnswer            = AskAnswer.New();
                askAnswer.UserId     = UserContext.CurrentUser.UserId;
                askAnswer.Author     = UserContext.CurrentUser.DisplayName;
                askAnswer.IsBest     = false;
                askAnswer.QuestionId = this.QuestionId;
            }
            //编辑回答
            else
            {
                AskService askService = new AskService();
                askAnswer = askService.GetAnswer(this.AnswerId);
                askAnswer.LastModified = DateTime.UtcNow;
            }

            askAnswer.Body = this.Body;

            return(askAnswer);
        }
コード例 #3
0
        public string GetCommentDetailUrl(long commentedObjectId, long id, long?userId = null)
        {
            AskAnswer answer = new AskService().GetAnswer(commentedObjectId);

            if (answer != null)
            {
                return(SiteUrls.Instance().AskQuestionDetail(answer.QuestionId));
            }
            return(null);
        }
コード例 #4
0
 /// <summary>
 /// 获取被评论对象名称
 /// </summary>
 /// <param name="commentedObjectId">被评论对象Id</param>
 /// <param name="tenantTypeId">租户类型Id</param>
 /// <returns></returns>
 public string GetCommentedObjectName(long commentedObjectId, string tenantTypeId)
 {
     if (tenantTypeId == TenantTypeIds.Instance().AskAnswer())
     {
         AskAnswer askAnswer = new AskService().GetAnswer(commentedObjectId);
         if (askAnswer != null)
         {
             return(askAnswer.Body);
         }
     }
     return(string.Empty);
 }
コード例 #5
0
ファイル: AskCommentUrlGetter.cs プロジェクト: x1987624/SNS
 /// <summary>
 /// 获取被评论对象名称
 /// </summary>
 /// <param name="commentedObjectId">被评论对象Id</param>
 /// <param name="tenantTypeId">租户类型Id</param>
 /// <returns></returns>
 public string GetCommentedObjectName(long commentedObjectId, string tenantTypeId)
 {
     if (tenantTypeId == TenantTypeIds.Instance().AskQuestion())
     {
         AskQuestion askQuestion = new AskService().GetQuestion(commentedObjectId);
         if (askQuestion != null)
         {
             return(askQuestion.Subject);
         }
     }
     return(string.Empty);
 }
コード例 #6
0
        /// <summary>
        /// 获取被评论对象(部分)
        /// </summary>
        /// <param name="commentedObjectId"></param>
        /// <returns></returns>
        public CommentedObject GetCommentedObject(long commentedObjectId)
        {
            AskAnswer answer = new AskService().GetAnswer(commentedObjectId);

            if (answer != null)
            {
                CommentedObject commentedObject = new CommentedObject();
                commentedObject.DetailUrl = SiteUrls.Instance().AskQuestionDetail(answer.QuestionId);
                commentedObject.Name      = answer.Body;
                commentedObject.Author    = answer.Author;
                commentedObject.UserId    = answer.UserId;
                return(commentedObject);
            }
            return(null);
        }
コード例 #7
0
ファイル: AskCommentUrlGetter.cs プロジェクト: x1987624/SNS
        /// <summary>
        /// 获取被评论对象(部分)
        /// </summary>
        /// <param name="commentedObjectId"></param>
        /// <returns></returns>
        public CommentedObject GetCommentedObject(long commentedObjectId)
        {
            AskQuestion question = new AskService().GetQuestion(commentedObjectId);

            if (question != null)
            {
                CommentedObject commentedObject = new CommentedObject();
                commentedObject.DetailUrl = SiteUrls.Instance().AskQuestionDetail(commentedObjectId);
                commentedObject.Name      = question.Subject;
                commentedObject.Author    = question.Author;
                commentedObject.UserId    = question.UserId;
                return(commentedObject);
            }
            return(null);
        }
コード例 #8
0
        /// <summary>
        /// 转换成AskQuestion类型
        /// </summary>
        /// <returns>问题实体</returns>
        public AskQuestion AsAskQuestion()
        {
            AskQuestion askQuestion = null;

            //发布问题
            if (this.QuestionId == 0)
            {
                askQuestion        = AskQuestion.New();
                askQuestion.UserId = UserContext.CurrentUser.UserId;
                askQuestion.Author = UserContext.CurrentUser.DisplayName;
                askQuestion.Status = QuestionStatus.Unresolved;

                if (this.AskUserId > 0)
                {
                    askQuestion.AskUserId = this.AskUserId;
                }
                if (this.OwnerId.HasValue)
                {
                    askQuestion.OwnerId      = this.OwnerId.Value;
                    askQuestion.TenantTypeId = TenantTypeIds.Instance().Group();
                }
                else
                {
                    askQuestion.OwnerId      = 0;
                    askQuestion.TenantTypeId = TenantTypeIds.Instance().User();
                }
            }
            //编辑问题
            else
            {
                AskService askService = new AskService();
                askQuestion = askService.GetQuestion(this.QuestionId);
                askQuestion.LastModified = DateTime.UtcNow;
            }

            askQuestion.Subject            = this.Subject;
            askQuestion.Body               = this.Body;
            askQuestion.LastModifiedUserId = UserContext.CurrentUser.UserId;
            askQuestion.LastModifier       = UserContext.CurrentUser.DisplayName;
            if (this.Reward > askQuestion.Reward && this.Reward <= askQuestion.User.TradePoints)
            {
                askQuestion.AddedReward = this.Reward - askQuestion.Reward;
                askQuestion.Reward      = this.Reward;
            }
            return(askQuestion);
        }
コード例 #9
0
ファイル: AskApplication.cs プロジェクト: x1987624/SNS
        /// <summary>
        /// 删除用户在应用中的数据
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="takeOverUserName">用于接管删除用户时不能删除的内容(例如:用户创建的群组)</param>
        /// <param name="isTakeOver">是否接管被删除用户可被接管的内容</param>
        protected override void DeleteUser(long userId, string takeOverUserName, bool isTakeOver)
        {
            AskService askService = DIContainer.Resolve <AskService>();

            askService.DeleteUser(userId, takeOverUserName, isTakeOver);
        }