예제 #1
0
        /// <summary>
        /// Mark any tasks done that are low priority and were scheduled in the past; save changes
        /// </summary>
        internal void AutoCompleteTasks()
        {
            DateTime cutoff   = DateTime.Today;
            string   cutoffS  = DateUtil.ToYMD(cutoff);
            var      toDelete = new List <long>();

            for (int i = ScheduledBoxes.Count - 1; i >= 0; --i)
            {
                var box = ScheduledBoxes[i];
                if (box.Importance == Constants.IMPORTANCE_LOW && box.BoxTime != null && DateUtil.IsBefore(box.BoxTime, cutoffS))
                {
                    ScheduledBoxes.RemoveAt(i);
                    toDelete.Add(box.RowId);
                }
            }

            if (toDelete.Count == 0)
            {
                return;
            }
            using var db = new SystematizerContext();
            string rowids = string.Join(',', toDelete);

            db.Database.ExecuteSqlRaw($"update Box set DoneDate='{cutoffS}' where RowId in ({rowids})");
        }