Hi,
You're using MVC so there is a server side application. If you want to do auto release system you should consider using system sheduler to perform special action on some interval. Most of hosting sites offers you that possibility.
One of solutions is to create controller with apriopriate automatic actions and call it via url.
Here you are example how to do this:
http://stackoverflow.com/questions/1987345/recommended-method-for-loading-a-url-via-a-scheduled-task-on-windows[
^]
Then your controller can look like this:
public class AutomatController : Controller
{
public string ReleaseReservedBooks()
{
var reservedBooks = from x in db.Books
where x.EndDate <= DateTime.Now.AddDays(-7)
select x;
foreach(var book in reservedBooks)
{
book.EndDate = null;
}
db.SaveChanges;
return string.Format("{0} - Unreserved books: {1}", DateTime.Now, reservedBooks.Count);
}
}
And then call URL http://yourdomain.com/Automat/ReleaseReservedBooks from scheduler.
Ofcourse you should take precautions for security reasons. For that you can make special routing (in RouteConfig.cs) leading to your controller.
[Update]
Above solutions applies to you 2nd point.
You can take similar steps while you're displaying books to logged user. Get all books, check if there are overdue reservations and remove reservations if exists:
public ActionResult Index()
{
var books = from x in db.Books
select x;
var changed = false;
foreach(var book in books)
{
if (book.EndDate <= DateTime.Now.AddDays(-7))
{
book.EndDate = null;
changed = true;
}
}
if (changed)
{
db.SaveChanges();
}
return View(books);
}
I hope it help you.