private int GetQuoteCounts() { using( var db = new QuoteDBEntities()) { return db.Quotes.Count(); } }
// // GET: /Quote/ public ActionResult Index() { using(var db = new QuoteDBEntities()) { return View(db.Quotes.ToList()); } }
public ActionResult RandomQuote() { using(var db = new QuoteDBEntities()) { Random rnd = new Random((int)DateTime.Now.Ticks); var model = db.Quotes.Find(rnd.Next(1, GetQuoteCounts()+1)); return View(model); } }