public ActionResult Register(RegisterViewModel registerViewModel) { ExamManagerEF examManager = examUtil.GetExamManager(); RegisterViewModel registerViewModelUpdated = examManager.RegisterUser(registerViewModel); if (!string.IsNullOrEmpty(registerViewModelUpdated.ErrorDescription)) return View(registerViewModelUpdated); else return this.RedirectToAction("Exam", "Exam"); }
public RegisterViewModel RegisterUser(RegisterViewModel registerViewModel) { OnlineExamAppDBEntities3 dbContext = new OnlineExamAppDBEntities3(); User existingUser = dbContext.Users.Where(u => u.UserName == registerViewModel.UserName).FirstOrDefault(); if (existingUser == null) { User user = new User(); user.FirstName = registerViewModel.FirstName; user.LastName = registerViewModel.LastName; user.UserName = registerViewModel.UserName; user.Password = registerViewModel.Password; dbContext.Users.Add(user); dbContext.SaveChanges(); _candidate = new ViewModel.CandidateViewModel() { Name = registerViewModel.UserName }; registerViewModel.ErrorDescription = string.Empty; } else registerViewModel.ErrorDescription = "The User Name already exists. Please supply a new User Name"; return registerViewModel; }