Пример #1
0
        public async Task <IActionResult> Login(LoginViewModel loginViewModel)
        {
            if (ModelState.IsValid)
            {
                var user   = _userManager.GetUserAsync(User);
                var result = await _signInManager.PasswordSignInAsync(loginViewModel.Email, loginViewModel.Password, loginViewModel.RememberMe, lockoutOnFailure : false);


                if (result.Succeeded)
                {
                    _logger.LogInformation("User logged in.");

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User logged in.");


                        if (User.IsInRole("Company"))
                        {
                            return(RedirectToAction("Index", "Company", new { id = user.Result.Id }));
                        }

                        if (User.IsInRole("Employee"))
                        {
                            var employee = _iEmployeeAppService.FindEmployee(user.Result.Id);

                            if (employee.Active == true)
                            {
                                return(RedirectToAction("Lockout", "Account"));
                            }

                            else
                            {
                                return(RedirectToAction("Index", "Employee", new { id = user.Result.Id }));
                            }
                        }
                    }
                }


                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(View());
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(loginViewModel));
        }
Пример #2
0
        public IActionResult Index(Guid id)
        {
            if (id == Guid.NewGuid() || id == Guid.Empty)
            {
                return(NotFound());
            }

            var employee = _iEmployeeAppService.FindEmployee(id);

            if (employee == null)
            {
                return(NotFound());
            }

            return(View("Index", employee));
        }