Exemple #1
0
        protected virtual void AfterSubmit()
        {
            var orderInfo = this.OrderInfo;

            orderInfo.EndTime = DateTime.Now;
            var user = dataAccess.Find <Account>(orderInfo.UserId);

            user.Amount += orderInfo.Money;
            dataAccess.Update(orderInfo);
            dataAccess.Update(user);
            dataAccess.SaveChanges();
            Common.RedisHelper redis = new Common.RedisHelper();
            redis.Remove(orderInfo.Id.ToString());
        }
 public override OrderInfo Get()
 {
     try
     {
         var orderInfo = base.Get();
         //设置失效时间
         Common.RedisHelper redis = new Common.RedisHelper();
         int failureTime          = Convert.ToInt32(TimeConfig.commentFailureTime);
         redis.SetString(orderInfo.Id.ToString(), "1", new TimeSpan(0, failureTime, 0));
         return(orderInfo);
     }
     catch (Exception ex)
     {
         Common.LogHelper.WriteLog(this.GetType(), ex);
         throw;
     }
 }
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            // if (string.IsNullOrEmpty(_key))
            int key = actionContext.Request.RequestUri.AbsoluteUri.GetHashCode();
            HttpResponseMessage rm = new HttpResponseMessage(System.Net.HttpStatusCode.OK);

            rm.Content = new StringContent("{\"status\": 1, \"message\":\"请求太频繁\"}", Encoding.UTF8, "appliction/json");

            Common.RedisHelper redis = new Common.RedisHelper(5);
            if (redis.IsKey(HttpContext.Current.Request.UserHostAddress + key))
            {
                actionContext.Response = rm;
            }
            else
            {
                redis.SetString(HttpContext.Current.Request.UserHostAddress + key, "", new TimeSpan(0, 0, 2));
            }
        }
        public override OrderInfo Get()
        {
            var orderInfo = base.Get();

            try
            {
                //设置失效时间
                Common.RedisHelper redis       = new Common.RedisHelper();
                string             failureTime = Convert.ToString(TimeConfig.retainedFailureTime);
                var now             = DateTime.Now;
                var failureDateTime = Convert.ToDateTime(now.AddDays(1).ToString("yyyy-MM-dd " + failureTime));
                redis.SetString(orderInfo.Id.ToString(), "1", failureDateTime - now);
                return(orderInfo);
            }
            catch (Exception ex)
            {
                Common.LogHelper.WriteLog(this.GetType(), ex);
                throw;
            }
        }