/// <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})"); }
/// <summary> /// Delete boxes older than one year after they are done /// </summary> internal static void DeleteVeryOldBoxes() { using var db = new SystematizerContext(); DateTime cutoff = DateTime.Today.AddYears(-1); string cutoffS = DateUtil.ToYMD(cutoff); var boxes = db.Box.FromSqlRaw($"select RowId,* from Box where DoneDate is not null and DoneDate < '{cutoffS}'"); db.Box.RemoveRange(boxes); db.SaveChanges(); }