Beispiel #1
0
        /// <summary>
        ///     Adds a new rule to the end of the list and selects it.
        /// </summary>
        private void AddRule()
        {
            UserScoreRule newRule = new UserScoreRule(GlobalStrings.AutoCatUserScore_NewRuleName, 0, 100, 0, 0);

            ruleList.Add(newRule);
            lstRules.SelectedIndex = lstRules.Items.Count - 1;
        }
Beispiel #2
0
        /// <summary>
        /// 添加积分规则
        /// </summary>
        /// <param name="name"></param>
        /// <param name="score"></param>
        /// <param name="limitScore"></param>
        /// <param name="createUserId"></param>
        /// <returns></returns>
        public bool CreateUserScoreRule(string name, int score, int limitScore, int createUserId)
        {
            AssertUtil.NotNullOrWhiteSpace(name, LanguageUtil.Translate("api_Repository_UserScoreRule_CreateUserScoreRule_name_NotNullOrWhiteSpace"));
            AssertUtil.AreBigger(score, 0, LanguageUtil.Translate("api_Repository_UserScoreRule_CreateUserScoreRule_score_AreBigger"));
            AssertUtil.AreBigger(limitScore, score, LanguageUtil.Translate("api_Repository_UserScoreRule_CreateUserScoreRule_limitScore_AreBigger"));
            AssertUtil.AreBigger(createUserId, 0, LanguageUtil.Translate("api_Repository_UserScoreRule_CreateUserScoreRule_createUserId_AreBiggere"));
            var success = Execute <bool>(db =>
            {
                var manage = db.Manage.FirstOrDefault(m => m.State == false && m.Id == createUserId);
                AssertUtil.IsNotNull(manage, LanguageUtil.Translate("api_Repository_UserScoreRule_CreateUserScoreRule_createUserId_IsNotNul"));
                var userScoreRule = new UserScoreRule()
                {
                    CreateTime   = DateTime.Now,
                    CreateUserId = manage.Id,
                    Name         = name,
                    Score        = score,
                    LimitScore   = limitScore
                };
                db.UserScoreRule.Add(userScoreRule);
                return(db.SaveChanges() > 0);
            });

            if (success)
            {
                CreateCache <UserScoreRule>();
            }
            return(success);
        }
Beispiel #3
0
 public UserScoreRule(UserScoreRule other)
 {
     Name       = other.Name;
     MinScore   = other.MinScore;
     MaxScore   = other.MaxScore;
     MinReviews = other.MinReviews;
     MaxReviews = other.MaxReviews;
 }
Beispiel #4
0
        /// <summary>
        /// 获取积分规则信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public UserScoreRule GetUserScoreRule(int id)
        {
            UserScoreRule userScoreRule = new UserScoreRule();

            if (id > 0)
            {
                userScoreRule = this._scoreRuleRepository.GetEntity(ConditionEqualId(id)) ?? new UserScoreRule();
            }
            return(userScoreRule);
        }
Beispiel #5
0
        /// <summary>
        ///     Moves the specified rule a certain number of spots up or down in the list. Does nothing if the spot would be off
        ///     the list.
        /// </summary>
        /// <param name="mainIndex">Index of the rule to move.</param>
        /// <param name="offset">Number of spots to move the rule. Negative moves up, positive moves down.</param>
        /// <param name="selectMoved">If true, select the moved element afterwards</param>
        private void MoveItem(int mainIndex, int offset, bool selectMoved)
        {
            int alterIndex = mainIndex + offset;

            if (mainIndex < 0 || mainIndex >= lstRules.Items.Count || alterIndex < 0 || alterIndex >= lstRules.Items.Count)
            {
                return;
            }

            UserScoreRule mainItem = ruleList[mainIndex];

            ruleList[mainIndex]  = ruleList[alterIndex];
            ruleList[alterIndex] = mainItem;
            if (selectMoved)
            {
                lstRules.SelectedIndex = alterIndex;
            }
        }
Beispiel #6
0
 private static bool CheckRule(UserScoreRule rule, int score, int reviews) => (score >= rule.MinScore) &&
 (score <= rule.MaxScore) &&
 (rule.MinReviews <= reviews) &&
 ((rule.MaxReviews == 0) ||
  (rule.MaxReviews >= reviews));
Beispiel #7
0
 public bool DeleteEntity(UserScoreRule entity)
 {
     return(base.DeleteEntity <UserScoreRule>(entity));
 }
Beispiel #8
0
 public bool UpdateEntity(UserScoreRule entity)
 {
     return(base.UpdateEntity(entity));
 }
Beispiel #9
0
 public bool CreateEntity(UserScoreRule entity)
 {
     return(base.CreateEntity <UserScoreRule>(entity));
 }
 private static bool CheckRule(UserScoreRule rule, int score, int reviews)
 {
     return(score >= rule.MinScore && score <= rule.MaxScore && rule.MinReviews <= reviews && (rule.MaxReviews == 0 || rule.MaxReviews >= reviews));
 }