Reputation: 8359
How can I check if current objects datetime property is 2 days older then current date, if it is want to delete it from the database.
I have to implement it inside this method,
public void AddNews(News news)
{
var exists = db.News.Any(x => x.Title == news.Title);
if (exists == false)
{
db.News.AddObject(news);
}
else
{
db.News.DeleteObject(news);
}
}
Any kind of help is appreciated
Upvotes: 1
Views: 3008
Reputation: 25231
Assuming the property is called News.Date
...
if(news.Date <= DateTime.Now.AddDays(-2))
{
db.News.DeleteObject(news);
}
Upvotes: 2