public ActionResult Index(string type) { Word[] words; switch (type) { case "new": words = db.Words.Find(x => x.ProcessDate == null).Take(5).ToArray(); break; case "old": words = db.Words.All.OrderBy(x => x.ProcessDate).Take(5).ToArray(); break; case "error": words = db.Words.All.OrderBy(x => x.Status).Take(5).ToArray(); break; case "repeat": words = Session["words"] as Word[]; break; default: return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Session["words"] = words; //todo //if no words redirect to another page List <LearnViewModel> viewModels = new List <LearnViewModel>(); foreach (var word in words) { LearnViewModel model = new LearnViewModel(); model.Word = word; model.NativeOptions = db.Words.All.Where(x => x.Id != word.Id).Take(4).Select(x => x.Name) .ToArray(); model.ForeignOptions = db.Words.All.Where(x => x.Id != word.Id).Take(4).Select(x => x.Translation) .ToArray(); viewModels.Add(model); } return(View(viewModels.ToArray())); }
public LearnPage() { InitializeComponent(); BindingContext = new LearnViewModel(); }