private void LoadNextCard() { using (ForGoodEntities db = new ForGoodEntities()) { DateTime earliestReviewDate = DateTime.Now.AddMinutes(-1); var query = from c in db.Cards where c.LastUpdate < earliestReviewDate orderby c.ReviewDate select c; _nextCard = query.FirstOrDefault(); if (_nextCard == null) { ForgotBtn.Enabled = AgainBtn.Enabled = OkayBtn.Enabled = ForGoodBtn.Enabled = false; FlipBtn.Enabled = false; CardText.Text = "No more card for now!"; } else { Session["NextCard"] = _nextCard; CardText.Text = _nextCard.Front; if (string.IsNullOrEmpty(_nextCard.Back)) FlipBtn.Enabled = false; else FlipBtn.Enabled = true; } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["NextCard"] != null) _nextCard = (Card)Session["NextCard"]; if (!IsPostBack) { LoadNextCard(); } }
protected void AddBtn_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(FrontText.Text)) return; using (ForGoodEntities db = new ForGoodEntities()) { Card newCard = new Card() { Front = FrontText.Text, LastUpdate = DateTime.Now }; if (!String.IsNullOrEmpty(BackText.Text)) newCard.Back = BackText.Text; newCard.ReviewDate = Util.GetReviewDate(Util.ReviewDuration.Forgot); db.AddToCards(newCard); db.SaveChanges(); } FrontText.Text = ""; BackText.Text = ""; }
private void RefreshAndSafeReviewDate(Card _nextCard, Util.ReviewDuration reviewDuration) { using (ForGoodEntities db = new ForGoodEntities()) { Card card = db.Cards.Where(c => c.CardId == _nextCard.CardId).FirstOrDefault(); card.ReviewDate = Util.GetReviewDate(reviewDuration); card.LastUpdate = DateTime.Now; db.SaveChanges(); } }