Пример #1
0
        /// <summary>
        ///
        /// </summary>
        private void BuildQaPortalSettings()
        {
            var cntQa           = new DnnqaController();
            var colOpThresholds = QaSettings.GetOpThresholdCollection(cntQa.GetQaPortalSettings(ModuleContext.PortalId), ModuleContext.PortalId);

            dntbQCCVC.Text    = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.QuestionCloseCompleteVoteCount.ToString()).Value.ToString();
            dntbQCWD.Text     = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.QuestionCloseWindowDays.ToString()).Value.ToString();
            dntbQFHRC.Text    = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.QuestionFlagHomeRemoveCount.ToString()).Value.ToString();
            dntbPCVWM.Text    = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.PostChangeVoteWindowMinutes.ToString()).Value.ToString();
            dntbPFCC.Text     = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.PostFlagCompleteCount.ToString()).Value.ToString();
            dntbPFWH.Text     = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.PostFlagWindowHours.ToString()).Value.ToString();
            dntbTCWD.Text     = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.TagCloseWindowDays.ToString()).Value.ToString();
            dntbTFWH.Text     = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.TagFlagWindowHours.ToString()).Value.ToString();
            dntbTFCC.Text     = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.TagFlagCompleteCount.ToString()).Value.ToString();
            dntbTSAC.Text     = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.TermSynonymApproveCount.ToString()).Value.ToString();
            dntbTSRC.Text     = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.TermSynonymRejectCount.ToString()).Value.ToString();
            dntbTSMC.Text     = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.TermSynonymMaxCount.ToString()).Value.ToString();
            dntbUCVC.Text     = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.UserCloseVoteCount.ToString()).Value.ToString();
            dntbUFPMC.Text    = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.UserFlagPostModerateCount.ToString()).Value.ToString();
            dntbFPSC.Text     = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.UserFlagPostSpamCount.ToString()).Value.ToString();
            dntbUTSCMAC.Text  = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.UserTermSynonymCreateMinAnswerCount.ToString()).Value.ToString();
            dntbUTSVMASC.Text = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.UserTermSynonymVoteMinAnswerScoreCount.ToString()).Value.ToString();
            dntbUUVAC.Text    = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.UserUpVoteAnswerCount.ToString()).Value.ToString();
            dntbUUVQC.Text    = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.UserUpVoteQuestionCount.ToString()).Value.ToString();
            dntbQHMS.Text     = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.QuestionHomeMinScore.ToString()).Value.ToString();

            var colEmail     = QaSettings.GetEmailCollection(cntQa.GetQaPortalSettings(ModuleContext.PortalId), ModuleContext.PortalId);
            var currentEmail = colEmail.Single(s => s.Key == Constants.EmailSettings.FromAddress.ToString()).Value;

            txtbxFromEmail.Text = currentEmail != @"*****@*****.**" ? currentEmail : ModuleContext.PortalSettings.Email;

            var commentTemplate = colEmail.Single(s => s.Key == Constants.EmailSettings.CommentTemplate.ToString()).Value;

            txtbxCommentEmailTemplate.Text = commentTemplate;

            var singleQuestion = colEmail.Single(s => s.Key == Constants.EmailSettings.SingleQuestionTemplate.ToString()).Value;

            txtbxQuestionEmailTemplate.Text = singleQuestion;

            var answerTemplate = colEmail.Single(s => s.Key == Constants.EmailSettings.AnswerTemplate.ToString()).Value;

            txtAnswerEmailTemplate.Text = answerTemplate;

            var summaryTemplate = colEmail.Single(s => s.Key == Constants.EmailSettings.SummaryTemplate.ToString()).Value;

            txtbxSummaryEmailTemplate.Text = summaryTemplate;
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Save(object sender, AskQuestionEventArgs <PostInfo, bool, string> e)
        {
            try
            {
                var control = (System.Web.UI.UserControl)sender;

                if (e.Tags.Trim() == "")
                {
                    var minMsg = Localization.GetString("SelectMinTag", LocalResourceFile);
                    //var minCount = 1;
                    //minMsg = minMsg.Replace("{0}", minCount.ToString());

                    UI.Skins.Skin.AddModuleMessage(control, minMsg, ModuleMessage.ModuleMessageType.RedError);
                    return;
                }

                if (ModuleContext.Settings.ContainsKey(Constants.SettingMaxQuestionTags))
                {
                    var enteredTerms = e.Tags.Trim().Split(',').ToList();

                    if (enteredTerms.Count > Convert.ToInt32(ModuleContext.Settings[Constants.SettingMaxQuestionTags]))
                    {
                        var maxMsg = Localization.GetString("SelectMoreTags", LocalResourceFile);
                        maxMsg = maxMsg.Replace("{0}", (ModuleContext.Settings[Constants.SettingMaxQuestionTags]).ToString());

                        UI.Skins.Skin.AddModuleMessage(control, maxMsg, ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }
                }

                // TODO: validate selected tags are not in the disallow collection (module setting, loop through current collection and look for disallowed tags if found show message below)
                //UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("InvalidTag", SharedResourceFile), ModuleMessage.ModuleMessageType.RedError);

                if (ModuleContext.Settings.ContainsKey(Constants.SettingMinBodyChars))
                {
                    if (e.Post.Content.Length > Convert.ToInt32(ModuleContext.Settings[Constants.SettingMaxQuestionTags]))
                    {
                        UI.Skins.Skin.AddModuleMessage(control, Localization.GetString("InvalidBody", LocalResourceFile),
                                                       ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }
                }

                var userEnteredTerms = e.Tags.Split(',')
                                       .Where(s => s != string.Empty)
                                       .Select(p => p.Trim())
                                       .Distinct().ToList();

                foreach (var s in userEnteredTerms)
                {
                    if (!Utils.ContainsSpecialCharacter(s))
                    {
                        continue;
                    }
                    var msg = Localization.GetString("UnAllowedCharacters", LocalResourceFile);
                    msg = msg.Replace("{0}", Constants.DisallowedCharacters);
                    UI.Skins.Skin.AddModuleMessage(control, msg, ModuleMessage.ModuleMessageType.RedError);
                    return;
                }

                var terms = new List <Term>();
                userEnteredTerms.ForEach(t => terms.Add(Terms.CreateAndReturnTerm(t, VocabularyId)));

                var colOpThresholds = QaSettings.GetOpThresholdCollection(Controller.GetQaPortalSettings(ModuleContext.PortalId), ModuleContext.PortalId);
                var objTermApprove  = colOpThresholds.Single(s => s.Key == Constants.OpThresholds.TermSynonymApproveCount.ToString());
                var portalSynonyms  = Controller.GetTermSynonyms(ModuleContext.PortalId);
                var postTerms       = new List <Term>();

                foreach (var term in terms)
                {
                    var matchedSynonym = (from t in portalSynonyms where t.RelatedTermId == term.TermId && t.Score >= objTermApprove.Value select t).SingleOrDefault();
                    if (matchedSynonym != null)
                    {
                        var masterTerm = Terms.GetTermById(matchedSynonym.MasterTermId, VocabularyId);
                        // we have to make sure the masterTerm is not already in the list of terms
                        if (!terms.Contains(masterTerm))
                        {
                            postTerms.Add(masterTerm);
                            // update replaced count (for synonym)
                            Controller.TermSynonymReplaced(matchedSynonym.RelatedTermId, ModuleContext.PortalId);
                        }
                        //else
                        //{
                        //    // show it was removed?
                        //}
                    }
                    else
                    {
                        postTerms.Add(term);
                    }
                }

                e.Post.Terms.AddRange(postTerms);

                e.Post.PortalId = ModuleContext.PortalId;
                e.Post.ModuleID = ModuleContext.ModuleId;
                e.Post.Body     = Utils.ProcessSavePostBody(e.Post.Body);

                // remove line below if you want to enable post approval (changes in ascx too)
                e.Post.Approved = true;

                if (e.Post.Approved)
                {
                    e.Post.ApprovedDate = DateTime.Now;
                }

                e.Post.ParentId           = 0;
                e.Post.TabID              = ModuleContext.TabId;
                e.Post.CreatedUserId      = ModuleContext.PortalSettings.UserId;
                e.Post.CreatedDate        = DateTime.Now;
                e.Post.LastModifiedUserId = ModuleContext.PortalSettings.UserId;
                e.Post.LastModifiedDate   = DateTime.Now;

                // make sure title/body are passing through security filters
                var objSecurity = new PortalSecurity();
                e.Post.Title = objSecurity.InputFilter(e.Post.Title, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoAngleBrackets | PortalSecurity.FilterFlag.NoMarkup);
                e.Post.Body  = objSecurity.InputFilter(e.Post.Body, PortalSecurity.FilterFlag.NoScripting);

                var objPost = Controller.AddPost(e.Post, ModuleContext.TabId);
                Controller.UpdatePost(objPost, ModuleContext.TabId);

                // subscribe user
                if (e.Notify)
                {
                    var objSub = new SubscriptionInfo
                    {
                        CreatedOnDate    = DateTime.Now,
                        PortalId         = ModuleContext.PortalId,
                        PostId           = objPost.PostId,
                        SubscriptionType = (int)Constants.SubscriptionType.InstantPost,
                        UserId           = ModuleContext.PortalSettings.UserId
                    };

                    Controller.AddSubscription(objSub);
                }

                var colUserScoring = QaSettings.GetUserScoringCollection(Controller.GetQaPortalSettings(ModuleContext.PortalId), ModuleContext.PortalId);
                var objScoreLog    = new UserScoreLogInfo
                {
                    UserId              = ModuleContext.PortalSettings.UserId,
                    PortalId            = ModuleContext.PortalId,
                    UserScoringActionId = (int)Constants.UserScoringActions.AskedQuestion,
                    Score =
                        colUserScoring.Single(
                            s => s.Key == Constants.UserScoringActions.AskedQuestion.ToString()).Value,
                    CreatedOnDate = DateTime.Now
                };

                Controller.AddScoringLog(objScoreLog, PrivilegeCollection);

                // if we ever allow moderation/approval to be enabled, this needs to respect that.
                var cntJournal  = new Journal();
                var questionUrl = Links.ViewQuestion(objPost.PostId, objPost.Title, ModuleContext.PortalSettings.ActiveTab, ModuleContext.PortalSettings);

                cntJournal.AddQuestionToJournal(objPost, objPost.Title, ModuleContext.PortalId, ModuleContext.PortalSettings.UserId, questionUrl);
                Response.Redirect(questionUrl, false);
            }
            catch (Exception exception)
            {
                ProcessModuleLoadException(exception);
            }
        }