I have a table with name "Loggs" as you see in image.
I want to create action that delete all records that is older than two weeks. For example today is 2017-11-20 and LoggId 1 , 2 and 3 have old Loggdate. How to create to delete them? I tried to put those LoggId's in Array , and I tried even old dates in Array but then I don't know how to do ....
Here is Array of old dates
public DateTime[] OldDates()
{
var oldDate = DateTime.Now.AddDays(-14);
return context.Loggs.Where(u => u.LoggDate < oldDate).Select(d => d.LoggDate).ToArray();
}
And tried by Id's too
public int[] OldDateId()
{
var oldDate = DateTime.Now.AddDays(-14);
return context.Loggs.Where(u => u.LoggDate < oldDate).Select(d => d.LoggId).ToArray();
}
But then How to create delete action....? I tried like this but I don't how to complite it
public ActionResult DeleteOldLogs()
{
var datesToRemove = OldDates();
using (context)
{
context.Loggs.Remove(.....) // I don't know how to formulate here ..;)
}
}
Thank you in advance!