Exemplo n.º 1
0
 public ActionResult Create([Bind("Name,Description,StartDate")] Company company)
 {
     if (ModelState.IsValid)
     {
         _companiesRepository.AddCompany(company);
         ViewBag.SelectedNav = "Dashboard";
         return(RedirectToAction(nameof(Index)));
     }
     ViewBag.SelectedNav = "Dashboard";
     return(View(company));
 }
Exemplo n.º 2
0
        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());
        }