public IActionResult Create(CreateCaseManagerViewModel createCMVM) { if (ModelState.IsValid) { CaseManager cm = new CaseManager() { LastName = createCMVM.LastName, FirstName = createCMVM.FirstName, Email = createCMVM.Email, PhoneNumber = createCMVM.PhoneNumber, ProgramID = createCMVM.ProgramID }; _context.Add(cm); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } createCMVM.Programs = _context.Programs.Select(p => new SelectListItem() { Value = p.ID.ToString(), Text = p.Name }).ToList(); return(View(createCMVM)); }
// GET: CaseManagers/Create public IActionResult Create() { //Check if user logged in: if (HttpContext.Session.GetString("Username") == null) { return(Redirect("/Home/Login")); } CreateCaseManagerViewModel createCMVM = new CreateCaseManagerViewModel(); createCMVM.Programs = _context.Programs.Select(p => new SelectListItem() { Value = p.ID.ToString(), Text = p.Name }).ToList(); return(View(createCMVM)); }