// // GET: /Logs/ public ActionResult Index() { OSMLogsContext context = new OSMLogsContext(); DeleteYesterday(context); return View(context.LogsItem.ToList()); }
public void DeleteAll() { OSMLogsContext context = new OSMLogsContext(); var tempLog = context.LogsItem.ToList(); tempLog.ForEach(item => context.LogsItem.Remove(item)); context.SaveChanges(); }
public void DeleteYesterday(OSMLogsContext context) { DateTime dtNow = DateTime.Now.AddDays(-1); List<OSMLogs> items = (from c in context.LogsItem where c.When < dtNow select c).ToList(); for (int i=0; i < items.Count; i++) { context.Entry(items[i]).State = System.Data.EntityState.Deleted; } context.SaveChanges(); }
public void AddLog(string sSectionName, string sDescription) { try { OSMLogsContext logs = new OSMLogsContext(); OSMLogs item = new OSMLogs() { Description = sDescription, SectionName = sSectionName, When = DateTime.Now, ID = Guid.NewGuid().ToString() }; logs.LogsItem.Add(item); logs.SaveChanges(); } catch { } }