public static decimal AmountFromPoints(int proId, int points)
        {
            IPointOrderRuleRepository proRuleRepo = ServiceLocator.Current.Resolve <IPointOrderRuleRepository>();
            var     pro   = proRuleRepo.Get(r => r.StorePromotionId == proId && r.Status != (int)DataStatus.Deleted);
            decimal ratio = 0m;

            foreach (var rule in pro.ToList())
            {
                // hit rule be:
                // 1. rangfrom is null but rangto >points
                // 2. rangfrom is not null, and rangfrom <=points, and rangto is not null, rangto>points
                // 3. rangefrom is not null, and rangefrom <=points, and rangto is null
                if (!rule.RangeFrom.HasValue && rule.RangeTo.HasValue && rule.RangeTo > points)
                {
                    ratio = rule.Ratio.Value;
                    break;
                }
                if (rule.RangeFrom.HasValue && rule.RangeFrom <= points &&
                    (!rule.RangeTo.HasValue || (rule.RangeTo.HasValue && rule.RangeTo > points)))
                {
                    ratio = rule.Ratio.Value;
                    break;
                }
            }
            if (ratio <= 0)
            {
                throw new ApplicationException("规则设置有误!");
            }
            return(points / 100 * ratio);
        }
        public ActionResult Detail(int?id)
        {
            if (id == null)
            {
                ModelState.AddModelError("", "参数验证失败.");
                return(View());
            }
            var entity = _storepromotionRepo.Find(id.Value);
            var vo     = new StorePromotionViewModel().FromEntity <StorePromotionViewModel>(entity
                                                                                            , model => model.Rules = new StorePromotionRuleViewModel().FromEntities <StorePromotionRuleViewModel>(
                                                                                                _ruleRepo.Get(r => r.StorePromotionId == model.Id &&
                                                                                                              r.Status != (int)DataStatus.Deleted).ToList())
                                                                                            );

            return(View(vo));
        }