Ejemplo n.º 1
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);
        }