public ActionResult Create() { Choice currentUser = new Choice(); currentUser.StudentId = User.Identity.GetUserName(); ViewBag.FirstChoiceOptionId = new SelectList(db.Options.Where(c => c.isActive == true), "OptionsId", "Title"); ViewBag.FourthChoiceOptionId = new SelectList(db.Options.Where(c => c.isActive == true), "OptionsId", "Title"); ViewBag.SecondChoiceOptionId = new SelectList(db.Options.Where(c => c.isActive == true), "OptionsId", "Title"); ViewBag.ThirdChoiceOptionId = new SelectList(db.Options.Where(c => c.isActive == true), "OptionsId", "Title"); // ViewBag.YearTermId = new SelectList(db.YearTerms, "YearTermId", "YearTermId"); return View(currentUser); }
// Check to make sure that the user has entered unique choices private bool validChoices(Choice choice) { // Make sure the values aren't null if (choice.FirstChoiceOptionId == null || choice.SecondChoiceOptionId == null || choice.ThirdChoiceOptionId == null || choice.FourthChoiceOptionId == null) { return false; } // Check for non-duplicate options var list = new List<int>(); list.Add((int)choice.FirstChoiceOptionId); list.Add((int)choice.SecondChoiceOptionId); list.Add((int)choice.ThirdChoiceOptionId); list.Add((int)choice.FourthChoiceOptionId); if (list.Count != list.Distinct().Count()) { return false; } else { return true; } }