public IActionResult Create() { if (HttpContext.Session.GetString("userID") == null) { ViewBag.IsLoggedIn = false; return(RedirectToAction("Login", "User")); } else { ViewBag.IsLoggedIn = true; var eraCtrl = new EraController(); ViewBag.Era = eraCtrl.GetListItemsOfEra(); return(View()); } }
public IActionResult Edit(string id) { if (HttpContext.Session.GetString("userID") == null) { ViewBag.IsLoggedIn = false; return(RedirectToAction("Login", "User")); } else { ViewBag.IsLoggedIn = true; Question question; try { using (WebClient wc = new WebClient()) { var json = wc.DownloadString("https://histocity.herokuapp.com/api/question/get/" + id); question = (Question)JsonConvert.DeserializeObject(json, typeof(Question)); } var eraCtrl = new EraController(); var eraList = eraCtrl.GetListItemsOfEra(); var idSelectedEra = eraList.Where(x => x.Value == question.eraName).First().Text; question.eraID = idSelectedEra; ViewBag.Era = eraList; } catch (Exception e) { question = null; ModelState.AddModelError(string.Empty, e.ToString()); } return(View(question)); } }