I'm working on an application with mvc5 and want that when I load a page, it will check if datetime of data equals DateTime.Today
in table, and if so, that it will then set a boolean value to true.
public ActionResult Index()
{
Detail v = db.Details.Single(emp => emp.DateExpired.Value.Equals( DateTime.Today));
v.Expire = true;
db.SaveChanges();
return View();
}
It gives me this error
because there was more than one for which this date equals DateTime.Today
,
What can be done to take this possibility into account?
public ActionResult Index()
{
foreach (var r in db.Details.Where(emp => emp.DateExpired.HasValue && emp.DateExpired.Value == DateTime.Today))
{
r.Expire = true;
}
db.SaveChanges();
return View();
}