// // GET: /Account/ public ActionResult Index() { NameThatWrapEntities context = new NameThatWrapEntities(); var maxValue3 = (context.Wraps.Max(x => x.WrapID) ?? default(int)) + 1; Random rand = new Random(); ViewBag.WrapID = rand.Next(1, maxValue3); return View(); }
public ActionResult Register(User model) { NameThatWrapEntities context = new NameThatWrapEntities(); var maxValue5 = (context.Wraps.Max(x => x.WrapID) ?? default(int)) + 1; Random rand = new Random(); ViewBag.WrapID = rand.Next(1, maxValue5); if (ModelState.IsValid) { model.Password = model.Password.GetHashCode().ToString(); context.Users.Add(model); context.SaveChanges(); return View("ThanksReg", model); } else { return View(model); } }
public ActionResult SignIn(SignInModel model) { if (!ModelState.IsValid) { return View(model); } else { NameThatWrapEntities context = new NameThatWrapEntities(); var maxValue4 = (context.Wraps.Max(x => x.WrapID) ?? default(int)) + 1; string hashedPassword = model.Password.GetHashCode().ToString(); User user = context.Users.Where(u => u.Email == model.Email && u.Password == hashedPassword).SingleOrDefault(); if (user == null) { ModelState.AddModelError("", "Incorrect email or password"); return View(model); } Session["logged_in"] = "true"; Session["name"] = user.FirstName; Random rand = new Random(); model.WrapID = rand.Next(1, maxValue4); return View("WelcomeBack", model); } }
public ActionResult WrapList() { WrapListModel model = new WrapListModel(); NameThatWrapEntities context = new NameThatWrapEntities(); model.WrapList = context.Wraps.ToList(); return View(model); }
// // GET: /Home/ public ActionResult Level(int WrapID) { NameThatWrapEntities context = new NameThatWrapEntities(); var maxValue = (context.Wraps.Max(x => x.WrapID) ?? default(int)) + 1; Random rand = new Random(); var nextLevelID = rand.Next(1, maxValue); if (nextLevelID == WrapID) { while (nextLevelID == WrapID) { var anotherID = rand.Next(1, maxValue); nextLevelID = anotherID; } } var rightWrap = context.Wraps.Where(w => w.WrapID == WrapID).First(); ViewBag.rightWrap = rightWrap; var randID = rand.Next(1, maxValue); if (randID == WrapID) { while (randID == WrapID) { var backupID = rand.Next(1, maxValue); randID = backupID; } } var wrongWrap = context.Wraps.Where(w => w.WrapID == randID).First(); ViewBag.wrongWrap = wrongWrap; if (nextLevelID == randID) { while (nextLevelID == randID) { var extraID = rand.Next(1, maxValue); nextLevelID = extraID; } } ViewBag.NextLevelWrapID = nextLevelID; var nextLevelWrap = context.Wraps.Where(w => w.WrapID == nextLevelID).First(); ViewBag.nextLevelWrap = nextLevelWrap; var numCorrect = 0; ViewBag.numCorrect = numCorrect; var numAttempted = 1; ViewBag.numAttempted = numAttempted; var coin = rand.Next(1, 3); if (coin == 1) { ViewBag.TopWrap = rightWrap; ViewBag.BottomWrap = wrongWrap; ViewBag.topchoice = "rightchoice"; ViewBag.bottomchoice = "wrongchoice"; } else { ViewBag.TopWrap = wrongWrap; ViewBag.BottomWrap = rightWrap; ViewBag.topchoice = "wrongchoice"; ViewBag.bottomchoice = "rightchoice"; } ViewBag.coin = coin; return View(rightWrap); }
public ActionResult Details(int WrapID) { NameThatWrapEntities context = new NameThatWrapEntities(); var model = context.Wraps.Where(w => w.WrapID == WrapID).First(); return View(model); }