public ActionResult RegisterRecruiter([Bind("FirstName, LastName, Email, Password, PhoneNumber, Name, Description, StartDate")] RecruiterRegisterViewModel recruiterRegisterViewModel) { if (ModelState.IsValid) { if (!_usersRepository.UserEmailExists(recruiterRegisterViewModel.Email)) { JobFinderUser jobFinderUser = new JobFinderUser { Password = recruiterRegisterViewModel.Password, FirstName = recruiterRegisterViewModel.FirstName, LastName = recruiterRegisterViewModel.LastName, Email = recruiterRegisterViewModel.Email, PhoneNumber = recruiterRegisterViewModel.PhoneNumber, UserAddedAt = DateTime.Now, UserUpdatedAt = DateTime.Now, UserRoleId = 2, IsApproved = false, IsActive = true }; int newUserId = _usersRepository.addUser(jobFinderUser); if (_companiesRepository.CompanyExistsByName(recruiterRegisterViewModel.Name)) { Company company = _companiesRepository.GetCompanyByName(recruiterRegisterViewModel.Name); _companyUsersRepository.AssignUserToCompany(new CompanyUser { UserId = newUserId, CKCompanyId = company.CompanyId }); SendEmail(jobFinderUser.LastName + " " + jobFinderUser.FirstName, jobFinderUser.Email, company.Name); } else { Company company = new Company { Name = recruiterRegisterViewModel.Name, StartDate = recruiterRegisterViewModel.StartDate, Description = recruiterRegisterViewModel.Description }; int newCompanyId = _companiesRepository.AddCompany(company); _companyUsersRepository.AssignUserToCompany(new CompanyUser { UserId = newUserId, CKCompanyId = newCompanyId }); SendEmail(jobFinderUser.LastName + " " + jobFinderUser.FirstName, jobFinderUser.Email, company.Name); } ViewBag.Message = "Your account needs to be approved by the system administrator."; ViewBag.SelectedNav = "Home"; return(Redirect("/")); } else { ModelState.AddModelError("", "Email already exists in database!"); } } ViewBag.SelectedNav = "Register"; return(View()); }