示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>If we are changing the accepted answer, for now we are ok with multiple authors getting credit for an accepted answer BUT we only want to allow a single user to be rewarded 1x per answer. </remarks>
        protected void AcceptAnswer(object sender, AcceptAnswerEventArgs <int, int, int> e)
        {
            var objPost = Controller.GetPost(e.PostId, ModuleContext.PortalId);

            if (objPost != null)
            {
                Controller.AcceptAnswer(e.PostId, e.UserId, DateTime.Now, ModuleContext.ModuleId);

                var colUserScoring = QaSettings.GetUserScoringCollection(Controller.GetQaPortalSettings(ModuleContext.PortalId), ModuleContext.PortalId);
                if (View.Model.Question.AnswerId > 0)
                {
                    // these prevent anyone for getting points 2x for the same answer (although multiple answer authors could be credited over the liftime of a question since an accepted answer can change).
                    Controller.DeleteUserScoreLog(objPost.CreatedUserId, ModuleContext.PortalId,
                                                  (int)Constants.UserScoringActions.ProvidedAcceptedAnswer, UserScoringCollection.Single(s => s.Key == Constants.UserScoringActions.ProvidedAcceptedAnswer.ToString()).Value,
                                                  e.PostId);
                    Controller.DeleteUserScoreLog(ModuleContext.PortalSettings.UserId, ModuleContext.PortalId,
                                                  (int)Constants.UserScoringActions.AcceptedQuestionAnswer, UserScoringCollection.Single(s => s.Key == Constants.UserScoringActions.AcceptedQuestionAnswer.ToString()).Value,
                                                  e.PostId);
                }

                var objAScoreLog = new UserScoreLogInfo
                {
                    UserId              = objPost.CreatedUserId,
                    PortalId            = ModuleContext.PortalId,
                    UserScoringActionId = (int)Constants.UserScoringActions.ProvidedAcceptedAnswer,
                    KeyId = e.PostId,
                    Score =
                        colUserScoring.Single(
                            s => s.Key == Constants.UserScoringActions.ProvidedAcceptedAnswer.ToString()).Value,
                    CreatedOnDate = DateTime.Now
                };

                Controller.AddScoringLog(objAScoreLog, PrivilegeCollection);

                var objScoreLog = new UserScoreLogInfo
                {
                    UserId              = ModuleContext.PortalSettings.UserId,
                    PortalId            = ModuleContext.PortalId,
                    UserScoringActionId = (int)Constants.UserScoringActions.AcceptedQuestionAnswer,
                    KeyId = e.PostId,
                    Score =
                        colUserScoring.Single(
                            s => s.Key == Constants.UserScoringActions.AcceptedQuestionAnswer.ToString()).Value,
                    CreatedOnDate = DateTime.Now
                };

                Controller.AddScoringLog(objScoreLog, PrivilegeCollection);
            }

            //TODO: CP - Journal Integration once accepted answer is in build.'
            Response.Redirect(Links.ViewQuestion(QuestionID, View.Model.Question.Title, ModuleContext.PortalSettings.ActiveTab, ModuleContext.PortalSettings), true);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        protected void ViewLoad(object sender, EventArgs eventArgs)
        {
            try
            {
                View.Model.UserScoringActions = QaSettings.GetUserScoringCollection(Controller.GetQaPortalSettings(ModuleContext.PortalId), ModuleContext.PortalId).ToList();
                View.OnScoringSave           += OnScoringSave;

                View.Refresh();
            }
            catch (Exception exc)
            {
                ProcessModuleLoadException(exc);
            }
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Save(object sender, EditTermEventArgs <TermHistoryInfo> e)
        {
            try
            {
                var notes = e.TermHistory.Notes;

                //TODO: allow tag name editing
                // we have our UI values temporarily stored in variables above, we can update the history item (it needs to be added PRIOR to taxonomy term update done via core API)
                // TODO: Change auto approval to off
                Controller.AddTermHistory(ModuleContext.PortalId, View.Model.SelectedTerm.TermId, notes, true, ModuleContext.ModuleId);

                var cntTerm = new DotNetNuke.Entities.Content.Taxonomy.TermController();
                var objTerm = View.Model.SelectedTerm;

                // make sure title/body are passing through security filters
                var objSecurity = new PortalSecurity();
                var description = objSecurity.InputFilter(e.TermHistory.Description, PortalSecurity.FilterFlag.NoScripting);

                objTerm.Description = description;
                cntTerm.UpdateTerm(objTerm);

                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.EditedTag,
                    Score =
                        colUserScoring.Single(
                            s => s.Key == Constants.UserScoringActions.EditedTag.ToString()).Value,
                    CreatedOnDate = DateTime.Now
                };

                Controller.AddScoringLog(objScoreLog, PrivilegeCollection);

                Response.Redirect(Links.ViewTagDetail(ModuleContext, ModuleContext.TabId, View.Model.SelectedTerm.Name), false);
            }
            catch (Exception exception)
            {
                ProcessModuleLoadException(exception);
            }
        }
示例#4
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);
            }
        }