public IActionResult Login(int login, string password) { Driver selectedDriver = DriverDataMapper.FindByLicenseNumber(login); if (selectedDriver == null) { Employee employee = EmployeeDataMapper.FindByID(login); if (employee == null) { ModelState.AddModelError("Login", "User not found in DB"); } else if (employee.Password != password) { ModelState.AddModelError("Password", "Wrong password"); } else { if (ModelState.IsValid) { HttpContext.Session.SetString("user", employee.ID.ToString()); HttpContext.Session.SetString("userType", "employee"); return(RedirectToAction("EmployeeInterface", "Home")); } } } else if (selectedDriver.Password != password) { ModelState.AddModelError("Password", "Wrong password"); } else { if (ModelState.IsValid) { HttpContext.Session.SetString("user", selectedDriver.ID.ToString()); HttpContext.Session.SetString("userType", "driver"); return(RedirectToAction("DriverInterface", "Home")); } } return(View()); }
private void loginButton_Click(object sender, EventArgs e) { int login = -1; try { login = Convert.ToInt32(loginBox.Text); } catch { errorProvider.SetError(loginBox, "Wrong credentials"); } string password = passBox.Text; Employee employee = null; Driver driver = null; driver = DriverDataMapper.FindByLicenseNumber(login); if (driver == null) { employee = EmployeeDataMapper.FindByID(login); } if (driver != null) { if (driver.Password == password) { //prihlasen ridic manager.login = login; manager.password = password; manager.userType = "driver"; DriverProfile form = new DriverProfile(); form.Show(); this.Hide(); } } else if (employee != null) { if (employee.Password == password) { //prihlasen zamestnanec manager.login = login; manager.password = password; manager.userType = "employee"; EmployeeInterfaceForm form = new EmployeeInterfaceForm(); form.Show(); this.Hide(); } } else { errorProvider.SetError(loginBox, "Wrong credentials"); errorProvider.SetError(passBox, "Wrong credentials"); return; } //EmployeeInterfaceForm form = new EmployeeInterfaceForm(); //form.Show(); //this.Hide(); }