コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void DeleteSynonym(object sender, DeleteSuggestedSynonymEventArgs <ImageButton> e)
        {
            var relatedTermId = Convert.ToInt32(e.ImageButton.CommandArgument);

            if (relatedTermId > 0)
            {
                var scoringCollection = Controller.GetUserScoreLogByKey(relatedTermId, ModuleContext.PortalId);

                if (scoringCollection.Count > 0)
                {
                    // Need to remove all logged items associated w/ this term synonym, also reset the user's score
                    foreach (var objScoreLog in scoringCollection)
                    {
                        Controller.DeleteUserScoreLog(objScoreLog.UserId, ModuleContext.PortalId, objScoreLog.UserScoringActionId, objScoreLog.Score, relatedTermId);
                    }
                }

                Controller.DeleteTermSynonym(View.Model.SelectedTerm.TermId, relatedTermId, ModuleContext.PortalId);

                var portalSynonyms = Controller.GetTermSynonyms(ModuleContext.PortalId);
                var objTermApprove =
                    ThresholdCollection.Single(s => s.Key == Constants.OpThresholds.TermSynonymApproveCount.ToString());
                var objTermReject = ThresholdCollection.Single(s => s.Key == Constants.OpThresholds.TermSynonymRejectCount.ToString());

                View.Model.SuggestedTermSynonyms =
                    (from t in portalSynonyms
                     where ((t.MasterTermId == View.Model.SelectedTerm.TermId) && ((t.Score < objTermApprove.Value) && (t.Score > -objTermReject.Value)))
                     select t).ToList();

                View.ShowAddSynonym(true);
                View.ShowSuggestedSynonyms(true);
                //View.ShowActiveSynonyms(View.Model.ActiveTermSynonyms.Count > 0);
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AddSynonym(object sender, AddTermSynonymEventArgs <string> e)
        {
            var objTerm        = Terms.CreateAndReturnTerm(e.TermName, VocabularyId);
            var portalSynonyms = Controller.GetTermSynonyms(ModuleContext.PortalId);
            var colMaster      = (from t in portalSynonyms where t.MasterTermId == objTerm.TermId select t).ToList();
            var colRelated     = (from t in portalSynonyms where t.RelatedTermId == objTerm.TermId select t).ToList();

            View.Model.ErrorMessage = "";

            if (colMaster.Count > 0)
            {
                View.Model.ErrorMessage = "AlreadyMaster";
                return;
            }
            if (colRelated.Count > 0)
            {
                var colSameTerm =
                    (from t in portalSynonyms
                     where ((t.MasterTermId == View.Model.SelectedTerm.TermId) && (t.RelatedTermId == objTerm.TermId))
                     select t).ToList();

                View.Model.ErrorMessage = colSameTerm.Count > 0 ? "SameRelationSuggested" : "AlreadyRelated";
                return;
            }

            var objSynonym = new TermSynonymInfo
            {
                MasterTermId    = View.Model.SelectedTerm.TermId,
                RelatedTermId   = objTerm.TermId,
                PortalId        = ModuleContext.PortalId,
                CreatedByUserId = ModuleContext.PortalSettings.UserId,
                CreatedOnDate   = DateTime.Now
            };

            Controller.AddTermSynonym(objSynonym);

            var updatedPortalSynonyms = Controller.GetTermSynonyms(ModuleContext.PortalId);
            var objTermApprove        =
                ThresholdCollection.Single(s => s.Key == Constants.OpThresholds.TermSynonymApproveCount.ToString());
            var objTermReject = ThresholdCollection.Single(s => s.Key == Constants.OpThresholds.TermSynonymRejectCount.ToString());

            View.Model.SuggestedTermSynonyms =
                (from t in updatedPortalSynonyms
                 where ((t.MasterTermId == View.Model.SelectedTerm.TermId) && ((t.Score < objTermApprove.Value) && (t.Score > -objTermReject.Value)))
                 select t).ToList();

            View.ShowSuggestedSynonyms(true);
            View.ShowActiveSynonyms(View.Model.ActiveTermSynonyms.Count > 0);
            View.ShowAddSynonym(true);
        }
コード例 #3
0
        /// <summary>
        /// This will check if the flagged vote put us over the threshold to complete the flagging process (soft delete on the post, assign reputation points, clearing cache, etc.)
        /// </summary>
        /// <param name="currentPostId"></param>
        /// <param name="questionId"></param>
        /// <param name="contentItemId"></param>
        /// <remarks>Always delete the post last, in case we move to hard deletes. We need to know the deleted post info to log scoring actions.</remarks>
        private void FlagThresholdCheck(int currentPostId, int questionId, int contentItemId)
        {
            var votes = (from t in Controller.GetPostVotes(currentPostId) where (t.VoteTypeId == (int)Constants.VoteType.FlagPost) select t).ToList();
            var objFlagCompleteThreshold = ThresholdCollection.Single(s => s.Key == Constants.OpThresholds.PostFlagCompleteCount.ToString());

            if ((votes.Count) >= objFlagCompleteThreshold.Value)
            {
                var objPost = Controller.GetPost(currentPostId, ModuleContext.PortalId);

                if (currentPostId != questionId)
                {
                    var objScoreLogApprove = new UserScoreLogInfo
                    {
                        UserId              = objPost.CreatedUserId,
                        PortalId            = ModuleContext.PortalId,
                        UserScoringActionId = (int)Constants.UserScoringActions.ProvidedFlaggedAnswer,
                        Score =
                            UserScoringCollection.Single(
                                s => s.Key == Constants.UserScoringActions.ProvidedFlaggedAnswer.ToString()).Value,
                        KeyId         = currentPostId,
                        CreatedOnDate = DateTime.Now
                    };

                    Controller.AddScoringLog(objScoreLogApprove, PrivilegeCollection);
                    Controller.DeletePost(currentPostId, questionId, ModuleContext.PortalId, contentItemId, true, ModuleContext.ModuleId);
                }
                else
                {
                    var objScoreLogApprove = new UserScoreLogInfo
                    {
                        UserId              = objPost.CreatedUserId,
                        PortalId            = ModuleContext.PortalId,
                        UserScoringActionId = (int)Constants.UserScoringActions.AskedFlaggedQuestion,
                        Score =
                            UserScoringCollection.Single(
                                s => s.Key == Constants.UserScoringActions.AskedFlaggedQuestion.ToString()).Value,
                        KeyId         = questionId,
                        CreatedOnDate = DateTime.Now
                    };

                    Controller.AddScoringLog(objScoreLogApprove, PrivilegeCollection);
                    Controller.DeletePost(currentPostId, 0, ModuleContext.PortalId, contentItemId, true, ModuleContext.ModuleId);
                }
            }
        }
コード例 #4
0
ファイル: HomePresenter.cs プロジェクト: wbonekamp/DNNQA
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        protected void ViewLoad(object sender, EventArgs eventArgs)
        {
            try
            {
                var objFlagHomeRemovalThreshold = ThresholdCollection.Single(s => s.Key == Constants.OpThresholds.PostFlagCompleteCount.ToString());
                var objMinHomeScore             = ThresholdCollection.Single(s => s.Key == Constants.OpThresholds.QuestionHomeMinScore.ToString());

                var colModuleTags = Controller.GetTermsByContentType(ModuleContext.PortalId, ModuleContext.ModuleId, VocabularyId);

                IEnumerable <TermInfo> colTags;
                switch (TagTimeFrame)
                {
                case Constants.TagMode.ShowDailyUsage:
                    colTags = (from t in colModuleTags where t.DayTermUsage > 0 select t);
                    break;

                case Constants.TagMode.ShowWeeklyUsage:
                    colTags = (from t in colModuleTags where t.WeekTermUsage > 0 select t);
                    break;

                case Constants.TagMode.ShowMonthlyUsage:
                    colTags = (from t in colModuleTags where t.MonthTermUsage > 0 select t);
                    break;

                default:
                    colTags = (from t in colModuleTags where t.TotalTermUsage > 0 select t);
                    break;
                }

                View.Model.LatestQuestions = Controller.GetHomeQuestions(ModuleContext.ModuleId, QuestionPageSize, objFlagHomeRemovalThreshold.Value, objMinHomeScore.Value);
                View.Model.LatestTerms     = Sorting.GetHomeTermCollection(TagPageSize, TagTimeFrame, colTags).ToList();
                View.ItemDataBound        += ItemDataBound;
                View.TagItemDataBound     += TagItemDataBound;
                View.DashboardDataBound   += DashboardDataBound;

                View.Refresh();
            }
            catch (Exception exc)
            {
                ProcessModuleLoadException(exc);
            }
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks>There is a potential problem here. If a user attempts to view a term that is not used in the module (need to investigate).</remarks>
        protected void ViewLoad(object sender, EventArgs eventArgs)
        {
            try
            {
                var objTermApprove =
                    ThresholdCollection.Single(s => s.Key == Constants.OpThresholds.TermSynonymApproveCount.ToString());
                var objTermReject = ThresholdCollection.Single(s => s.Key == Constants.OpThresholds.TermSynonymRejectCount.ToString());
                var objMaxSynonym = ThresholdCollection.Single(s => s.Key == Constants.OpThresholds.TermSynonymMaxCount.ToString());
                var synonymCount  = 0;

                var urlTerm =
                    (from t in Controller.GetTermsByContentType(ModuleContext.PortalId, ModuleContext.ModuleId, VocabularyId)
                     where t.Name.ToLower() == Tag.ToLower()
                     select t).SingleOrDefault();

                if (urlTerm != null)
                {
                    var portalSynonyms = Controller.GetTermSynonyms(ModuleContext.PortalId);
                    var activeSynonyms =
                        (from t in portalSynonyms
                         where t.MasterTermId == urlTerm.TermId && t.Score >= objTermApprove.Value
                         select t)
                        .ToList();
                    View.Model.SuggestedTermSynonyms =
                        (from t in portalSynonyms
                         where ((t.MasterTermId == urlTerm.TermId) && ((t.Score < objTermApprove.Value) && (t.Score > -objTermReject.Value))) select t).ToList();
                    View.Model.SelectedTerm = urlTerm;
                    var colTerms = new List <TermInfo>();

                    foreach (var objSynonym in activeSynonyms)
                    {
                        var synonym = objSynonym;

                        var termTerm = (from t in Controller.GetTermsByContentType(ModuleContext.PortalId, ModuleContext.ModuleId, VocabularyId)
                                        where t.TermId == synonym.RelatedTermId
                                        select t).SingleOrDefault();

                        if (termTerm == null)
                        {
                            // the term is not currently used within this module, go to core taxonomy store
                            var objTerm = (from t in Util.GetTermController().GetTermsByVocabulary(1)
                                           where t.TermId == synonym.RelatedTermId
                                           select t).SingleOrDefault();

                            var objTermInfo = new TermInfo
                            {
                                DayTermUsage   = 0,
                                TotalTermUsage = 0,
                                MonthTermUsage = 0,
                                WeekTermUsage  = 0,
                                TermId         = objTerm.TermId,
                                Name           = objTerm.Name,
                                Description    = objTerm.Description
                            };

                            colTerms.Add(objTermInfo);
                        }
                        else
                        {
                            // in taxonomy
                            colTerms.Add(termTerm);
                        }
                    }

                    View.Model.ActiveTermSynonyms = colTerms;
                    // we need to make sure we don't go above the max synonym count;
                    synonymCount = View.Model.ActiveTermSynonyms.Count + View.Model.SuggestedTermSynonyms.Count;
                }
                else
                {
                    // check to make sure this is a term in taxonomy (maybe it just wasn't associated with the content type)
                    var objTerm = (from t in Util.GetTermController().GetTermsByVocabulary(1)
                                   where t.Name.ToLower() == Tag.ToLower()
                                   select t).SingleOrDefault();
                    if (objTerm != null)
                    {
                        var objTermInfo = new TermInfo();

                        View.Model.ActiveTermSynonyms    = new List <TermInfo>();
                        View.Model.SuggestedTermSynonyms = new List <TermSynonymInfo>();
                        objTermInfo.DayTermUsage         = 0;
                        objTermInfo.TotalTermUsage       = 0;
                        objTermInfo.MonthTermUsage       = 0;
                        objTermInfo.WeekTermUsage        = 0;
                        objTermInfo.TermId      = objTerm.TermId;
                        objTermInfo.Name        = objTerm.Name;
                        objTermInfo.Description = objTerm.Description;
                        View.Model.SelectedTerm = objTermInfo;
                    }
                    else
                    {
                        Response.Redirect(Globals.AccessDeniedURL("AccessDenied"), false);
                    }
                }

                View.Model.SelectedView = ControlView;
                View.ItemDataBound     += ItemDataBound;
                View.AddSynonym        += AddSynonym;
                View.DeleteSynonym     += DeleteSynonym;

                View.ShowActiveSynonyms(View.Model.ActiveTermSynonyms.Count > 0);

                if (synonymCount < objMaxSynonym.Value)
                {
                    // check priv.
                    var objSuggestPriv = PrivilegeCollection.Single(s => s.Key == Constants.Privileges.CreateTagSynonym.ToString());

                    if (objSuggestPriv != null)
                    {
                        //        var objMinSynonymCreateAnswer =
                        //colOpThresholds.Single(s => s.Key == Constants.OpThresholds.UserTermSynonymCreateMinAnswerCount.ToString());

                        if ((UserScore.Score >= objSuggestPriv.Value || ModuleContext.IsEditable))
                        {
                            View.ShowAddSynonym(true);
                            View.ShowSuggestedSynonyms(true);
                        }
                        else
                        {
                            View.ShowAddSynonym(false);
                            View.ShowSuggestedSynonyms(View.Model.SuggestedTermSynonyms.Count > 0);
                        }
                    }
                }
                else
                {
                    View.ShowAddSynonym(false);
                    View.ShowSuggestedSynonyms(View.Model.SuggestedTermSynonyms.Count > 0);
                }

                switch (View.Model.SelectedView.ToLower())
                {
                case "termsynonyms":
                    View.Model.PageTitle       = Localization.GetString("SynonymMetaTitle", LocalResourceFile).Replace("[0]", View.Model.SelectedTerm.Name);
                    View.Model.PageDescription = Localization.GetString("SynonymMetaDescription", LocalResourceFile).Replace("[0]", View.Model.SelectedTerm.Name);
                    break;

                default:
                    View.Model.PageTitle       = Localization.GetString("DetailMetaTitle", LocalResourceFile).Replace("[0]", View.Model.SelectedTerm.Name);;
                    View.Model.PageDescription = View.Model.SelectedTerm.Description;
                    break;
                }

                // this should only factor in privileges/moderation + any op thresholds

                View.Refresh();
            }
            catch (Exception exc)
            {
                ProcessModuleLoadException(exc);
            }
        }
コード例 #6
0
ファイル: Voting.cs プロジェクト: wbonekamp/DNNQA
        /// <summary>
        ///
        /// </summary>
        /// <param name="threshold"></param>
        /// <param name="voteType"></param>
        private void VotingThresholdCheck(Constants.OpThresholds threshold, Constants.VoteType voteType)
        {
            var objThreshold = ThresholdCollection.Single(s => s.Key == threshold.ToString());
            var votes        = new List <VoteInfo>();

            switch (voteType)
            {
            case Constants.VoteType.VoteDownPost:
                votes = (from t in Controller.GetPostVotes(CurrentPostID) where (t.VoteTypeId == (int)Constants.VoteType.VoteDownPost) select t).ToList();
                break;

            case Constants.VoteType.VoteUpPost:
                votes = (from t in Controller.GetPostVotes(CurrentPostID) where (t.VoteTypeId == (int)Constants.VoteType.VoteUpPost) select t).ToList();
                break;

            case Constants.VoteType.VoteSynonymUp:
                votes = (from t in Controller.GetTermSynonymVotes(RelatedTermId, ModContext.PortalId) where (t.VoteTypeId == (int)Constants.VoteType.VoteSynonymUp) select t).ToList();
                break;

            case Constants.VoteType.VoteSynonymDown:
                votes = (from t in Controller.GetTermSynonymVotes(RelatedTermId, ModContext.PortalId) where (t.VoteTypeId == (int)Constants.VoteType.VoteSynonymDown) select t).ToList();
                break;
                // term cases possible in future
            }

            if ((votes.Count + 1) >= objThreshold.Value)
            {
                // we broke the threshold, log it
                switch (threshold)
                {
                case Constants.OpThresholds.TermSynonymApproveCount:
                    // give the author any credit due for suggesting a sysnonym that was approved
                    // we need to get the userId to given them some rep
                    var colPortalSynonyms = Controller.GetTermSynonyms(ModContext.PortalId);
                    var objSynonym        = (from t in colPortalSynonyms where ((t.RelatedTermId == RelatedTermId) && (t.PortalId == ModContext.PortalId) && (t.MasterTermId == TermId)) select t).SingleOrDefault();

                    var objScoreLogApprove = new UserScoreLogInfo
                    {
                        UserId              = objSynonym.CreatedByUserId,
                        PortalId            = ModContext.PortalId,
                        UserScoringActionId = (int)Constants.UserScoringActions.CreatedTagSynonym,
                        Score =
                            UserScoringCollection.Single(
                                s => s.Key == Constants.UserScoringActions.CreatedTagSynonym.ToString()).Value,
                        KeyId         = RelatedTermId,
                        CreatedOnDate = DateTime.Now
                    };

                    Controller.AddScoringLog(objScoreLogApprove, PrivilegeCollection);

                    // TODO: handle remapping of tags (keep count)? (or do we only update the new posts added)

                    break;

                case Constants.OpThresholds.TermSynonymRejectCount:
                    // TODO: handle closing off term synonym (so it cannot be suggested again, any scoring actions)

                    break;

                case Constants.OpThresholds.UserUpVoteQuestionCount:
                    // a question can be voted up infinite times, take no action
                    break;

                case Constants.OpThresholds.UserUpVoteAnswerCount:
                    // an answer can be voted up infinite times, take no action
                    break;
                    //case Constants.OpThresholds.UserDownVoteQuestionCount :

                    //    break;
                    //case Constants.OpThresholds.UserDownVoteAnswerCount :

                    //    break;
                }
            }
        }