示例#1
0
        public async Task <IActionResult> RegisterEmployer(RegisterEmployerViewmodel model)
        {
            if (ModelState.IsValid)
            {
                var user = new IdentityUser()
                {
                    UserName = model.User.Email,
                    Email    = model.User.Email
                };
                var result = await _userManager.CreateAsync(user, model.User.Password);

                if (result.Succeeded)
                {
                    await _userManager.AddToRoleAsync(user, "Employer");

                    var addToCompanyResult = _companyHandler.AddEmployee(user.Id, _companyHandler.GetById(model.CompanyId));
                    if (addToCompanyResult)
                    {
                        return(RedirectToAction("ListCompanies", "Company"));
                    }
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }

            return(View(model));
        }
示例#2
0
        public async Task <IActionResult> DeleteCompany(string id)
        {
            foreach (var userid in _companyHandler.GetAllEmployees(_companyHandler.GetById(id).CompanyId))
            {
                var user = await _userManager.FindByIdAsync(userid);

                if (user != null)
                {
                    await _userManager.DeleteAsync(user);
                }
            }
            _companyHandler.Delete(_companyHandler.GetById(id).CompanyId);
            return(RedirectToAction("ListCompanies"));
        }