345 lines
12 KiB
C#
345 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using Church.Net.DAL.EF;
|
|
using Church.Net.Entity;
|
|
|
|
namespace Chruch.Net.Areas.English.Controllers
|
|
{
|
|
public class VocabulariesController : Controller
|
|
{
|
|
private ChurchNetContext db = new ChurchNetContext();
|
|
|
|
// GET: English/Vocabularies
|
|
public ActionResult Index()
|
|
{
|
|
var query = db.Vocabulary.Where(v => v.PracticeStage !=Enumeration.PracticeStage.FlashCard);
|
|
|
|
return View(query.OrderBy(v => v.PracticeStage).ThenByDescending(v=>v.InsertDate).ToList());
|
|
}
|
|
|
|
// GET: English/Vocabularies/Details/5
|
|
public ActionResult Details(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
Vocabulary vocabulary = db.Vocabulary.Find(id);
|
|
if (vocabulary == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(vocabulary);
|
|
}
|
|
|
|
// GET: English/Vocabularies/Create
|
|
public ActionResult Create()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
// POST: English/Vocabularies/Create
|
|
// 若要免於過量張貼攻擊,請啟用想要繫結的特定屬性,如需
|
|
// 詳細資訊,請參閱 https://go.microsoft.com/fwlink/?LinkId=317598。
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult Create(Vocabulary vocabulary)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
vocabulary.Word = vocabulary.Word.ToLower();
|
|
vocabulary.Word = vocabulary.Word.Substring(0, 1).ToUpper() + vocabulary.Word.Substring(1, vocabulary.Word.Length - 1);
|
|
|
|
vocabulary.InsertDate = DateTime.Now;
|
|
vocabulary.PracticeDate = DateTime.Now;
|
|
vocabulary.PracticeStage = Enumeration.PracticeStage.Select;
|
|
if (vocabulary.PartOfSpeech == Enumeration.PartsOfSpeech.Verbs)
|
|
{
|
|
vocabulary.VerbPast = vocabulary.Word + "ed";
|
|
vocabulary.VerbParticiple = vocabulary.Word + "ed";
|
|
}
|
|
|
|
|
|
db.Vocabulary.Add(vocabulary);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Create");
|
|
}
|
|
|
|
return View(vocabulary);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ActionResult Memorized()
|
|
{
|
|
Vocabulary vocabulary;
|
|
vocabulary = db.Vocabulary.FirstOrDefault(v => v.PracticeDate <= DateTime.Today && (v.PracticeStage == Enumeration.PracticeStage.Select || v.PracticeStage == Enumeration.PracticeStage.Memorized));
|
|
if (vocabulary != null)
|
|
{
|
|
vocabulary.PracticeTimes = 5;
|
|
return View(vocabulary);
|
|
}
|
|
else
|
|
{
|
|
return RedirectToAction("Index");
|
|
}
|
|
}
|
|
|
|
// POST: English/Vocabularies/Create
|
|
// 若要免於過量張貼攻擊,請啟用想要繫結的特定屬性,如需
|
|
// 詳細資訊,請參閱 https://go.microsoft.com/fwlink/?LinkId=317598。
|
|
public ActionResult MemorizedNext(int id)
|
|
{
|
|
Vocabulary vocabulary;
|
|
vocabulary = db.Vocabulary.First(v => v.Id == id);
|
|
vocabulary.PracticeDate = DateTime.Now;
|
|
vocabulary.PracticeStage = Enumeration.PracticeStage.Visualize;
|
|
|
|
db.Entry(vocabulary).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return RedirectToAction("Memorized");
|
|
}
|
|
|
|
public ActionResult Visualize()
|
|
{
|
|
Vocabulary vocabulary;
|
|
vocabulary = db.Vocabulary.FirstOrDefault(v => v.PracticeDate <= DateTime.Today && v.PracticeStage ==Enumeration.PracticeStage.Visualize);
|
|
if (vocabulary != null)
|
|
{
|
|
vocabulary.PracticeTimes = 3;
|
|
return View(vocabulary);
|
|
}
|
|
else
|
|
{
|
|
return RedirectToAction("Index");
|
|
}
|
|
}
|
|
|
|
// POST: English/Vocabularies/Create
|
|
// 若要免於過量張貼攻擊,請啟用想要繫結的特定屬性,如需
|
|
// 詳細資訊,請參閱 https://go.microsoft.com/fwlink/?LinkId=317598。
|
|
public ActionResult VisualizeNext(int id)
|
|
{
|
|
Vocabulary vocabulary;
|
|
vocabulary = db.Vocabulary.First(v => v.Id == id);
|
|
vocabulary.PracticeDate = DateTime.Now;
|
|
vocabulary.PracticeStage = vocabulary.PracticeStage + 1;
|
|
|
|
db.Entry(vocabulary).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return RedirectToAction("Visualize");
|
|
}
|
|
|
|
|
|
public ActionResult Apply()
|
|
{
|
|
Vocabulary vocabulary;
|
|
vocabulary = db.Vocabulary.FirstOrDefault(v => v.PracticeDate <= DateTime.Today && v.PracticeStage==Enumeration.PracticeStage.Apply);
|
|
if (vocabulary != null)
|
|
{
|
|
vocabulary.PracticeTimes = 2;
|
|
return View(vocabulary);
|
|
}
|
|
else
|
|
{
|
|
return RedirectToAction("Index");
|
|
}
|
|
}
|
|
|
|
// POST: English/Vocabularies/Create
|
|
// 若要免於過量張貼攻擊,請啟用想要繫結的特定屬性,如需
|
|
// 詳細資訊,請參閱 https://go.microsoft.com/fwlink/?LinkId=317598。
|
|
public ActionResult ApplyNext(Vocabulary model)
|
|
{
|
|
Vocabulary vocabulary;
|
|
vocabulary = db.Vocabulary.First(v => v.Id == model.Id);
|
|
vocabulary.PracticeDate = DateTime.Now;
|
|
vocabulary.PracticeStage = vocabulary.PracticeStage + 1;
|
|
vocabulary.PracticeSentence = model.PracticeSentence;
|
|
db.Entry(vocabulary).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return RedirectToAction("Apply");
|
|
}
|
|
|
|
|
|
public ActionResult Review()
|
|
{
|
|
Vocabulary vocabulary;
|
|
vocabulary = db.Vocabulary.FirstOrDefault(v => v.PracticeDate <= DateTime.Today && v.PracticeStage == Enumeration.PracticeStage.Review);
|
|
if (vocabulary != null)
|
|
{
|
|
vocabulary.PracticeTimes = 1;
|
|
return View(vocabulary);
|
|
}
|
|
else
|
|
{
|
|
return RedirectToAction("Index");
|
|
}
|
|
}
|
|
|
|
// POST: English/Vocabularies/Create
|
|
// 若要免於過量張貼攻擊,請啟用想要繫結的特定屬性,如需
|
|
// 詳細資訊,請參閱 https://go.microsoft.com/fwlink/?LinkId=317598。
|
|
public ActionResult ReviewNext(int id)
|
|
{
|
|
Vocabulary vocabulary;
|
|
vocabulary = db.Vocabulary.First(v => v.Id == id);
|
|
vocabulary.PracticeDate = DateTime.Now;
|
|
vocabulary.PracticeStage = vocabulary.PracticeStage + 1;
|
|
|
|
db.Entry(vocabulary).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return RedirectToAction("Review");
|
|
}
|
|
public ActionResult ReviewRepracticeNext(int id)
|
|
{
|
|
Vocabulary vocabulary;
|
|
vocabulary = db.Vocabulary.First(v => v.Id == id);
|
|
vocabulary.PracticeDate = DateTime.Now;
|
|
vocabulary.PracticeStage = Enumeration.PracticeStage.Select;
|
|
|
|
db.Entry(vocabulary).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return RedirectToAction("Review");
|
|
}
|
|
// GET: English/Vocabularies/Edit/5
|
|
public ActionResult Edit(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
Vocabulary vocabulary = db.Vocabulary.Find(id);
|
|
if (vocabulary == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(vocabulary);
|
|
}
|
|
|
|
// POST: English/Vocabularies/Edit/5
|
|
// 若要免於過量張貼攻擊,請啟用想要繫結的特定屬性,如需
|
|
// 詳細資訊,請參閱 https://go.microsoft.com/fwlink/?LinkId=317598。
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult Edit(Vocabulary vocabulary)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
vocabulary.Word = vocabulary.Word.ToLower();
|
|
vocabulary.Word = vocabulary.Word.Substring(0, 1).ToUpper() + vocabulary.Word.Substring(1, vocabulary.Word.Length - 1);
|
|
db.Entry(vocabulary).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
return View(vocabulary);
|
|
}
|
|
|
|
// GET: English/Vocabularies/Delete/5
|
|
public ActionResult Delete(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
Vocabulary vocabulary = db.Vocabulary.Find(id);
|
|
if (vocabulary == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(vocabulary);
|
|
}
|
|
|
|
// POST: English/Vocabularies/Delete/5
|
|
[HttpPost, ActionName("Delete")]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult DeleteConfirmed(int id)
|
|
{
|
|
Vocabulary vocabulary = db.Vocabulary.Find(id);
|
|
db.Vocabulary.Remove(vocabulary);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult FlashCard()
|
|
{
|
|
Vocabulary vocabulary;
|
|
vocabulary = db.Vocabulary.OrderBy(v=>v.FlashCardTimes).FirstOrDefault(v => v.PracticeStage == Enumeration.PracticeStage.FlashCard);
|
|
if (vocabulary != null)
|
|
{
|
|
return View(vocabulary);
|
|
}
|
|
else
|
|
{
|
|
return RedirectToAction("Index");
|
|
}
|
|
}
|
|
|
|
public ActionResult FlashCardNext(int id)
|
|
{
|
|
Vocabulary vocabulary;
|
|
vocabulary = db.Vocabulary.First(v => v.Id == id);
|
|
vocabulary.PracticeDate = DateTime.Now;
|
|
vocabulary.FlashCardTimes +=1;
|
|
db.Entry(vocabulary).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return RedirectToAction("FlashCard");
|
|
}
|
|
|
|
public ActionResult FlashCardForgot(int id)
|
|
{
|
|
Vocabulary vocabulary;
|
|
vocabulary = db.Vocabulary.First(v => v.Id == id);
|
|
vocabulary.PracticeDate = DateTime.Now;
|
|
vocabulary.FlashCardTimes =0;
|
|
vocabulary.PracticeStage = Enumeration.PracticeStage.Select;
|
|
db.Entry(vocabulary).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return RedirectToAction("FlashCard");
|
|
}
|
|
|
|
public ActionResult UpdateDB()
|
|
{
|
|
|
|
|
|
|
|
db.Vocabulary.Where(v => v.PracticeMemorized == false).ToList().ForEach(v => v.PracticeStage = Enumeration.PracticeStage.Memorized);
|
|
db.Vocabulary.Where(v => v.PracticeMemorized == true && v.PracticeVisualize == false).ToList().ForEach(v => v.PracticeStage = Enumeration.PracticeStage.Visualize);
|
|
db.Vocabulary.Where(v => v.PracticeMemorized == true && v.PracticeVisualize == true && v.PracticeApply == false).ToList().ForEach(v => v.PracticeStage = Enumeration.PracticeStage.Apply);
|
|
|
|
db.SaveChanges();
|
|
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
db.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
protected override void OnActionExecuted(System.Web.Mvc.ActionExecutedContext filterContext)
|
|
{
|
|
ViewBag.P_Select = db.Vocabulary.Count(v => v.PracticeStage == Enumeration.PracticeStage.Select );
|
|
ViewBag.P_Memorized = db.Vocabulary.Count(v => v.PracticeStage == Enumeration.PracticeStage.Memorized && v.PracticeDate < DateTime.Today);
|
|
ViewBag.P_Visualize = db.Vocabulary.Count(v => v.PracticeStage == Enumeration.PracticeStage.Visualize && v.PracticeDate < DateTime.Today);
|
|
ViewBag.P_Apply = db.Vocabulary.Count(v => v.PracticeStage == Enumeration.PracticeStage.Apply && v.PracticeDate < DateTime.Today);
|
|
ViewBag.P_Review = db.Vocabulary.Count(v => v.PracticeStage == Enumeration.PracticeStage.Review && v.PracticeDate < DateTime.Today);
|
|
}
|
|
}
|
|
}
|