コード例 #1
0
        /// <summary>
        /// 更改所有活动的状态
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        public void EditActivityStatus(object source, ElapsedEventArgs e)
        {
            var activityList = _activityTermExtension.GetAll().Where(x => (x.Status == ActivityStatus.未开始 || x.Status == ActivityStatus.进行中) && x.StartDataTime > DateTime.Now).ToList();

            foreach (var activity in activityList)
            {
                if (activity.StartDataTime > DateTime.Now && activity.EndDataTime > DateTime.Now)
                {
                    activity.Status = ActivityStatus.进行中;
                    _activityTermExtension.Edit(activity);
                }
                else if (activity.EndDataTime < DateTime.Now)
                {
                    activity.Status = ActivityStatus.已结束;
                    _activityTermExtension.Edit(activity);
                }
                _activityTermExtension.Save();
            }
        }