//[ValidateAntiForgeryToken] public async Task <IActionResult> LoginUser(Dashboard dashboard) { //Check if model is valid if (ModelState.IsValid) { //Get & store inputs String inputUsername = HttpContext.Request.Form["Username"]; String inputPassword = HttpContext.Request.Form["Password"]; //Create String to store List of logins String loginList = ""; //Create variables to store data int employeeID = 0; int loginID = 0; DateTime loginDate = DateTime.Now; bool isMatch = false; String role = ""; //Store List of existing Login details var loginDetails = from lD in _context.Login select lD; //Loop through List of existing login details foreach (var login in loginDetails) { //Compare inputs if (login.Username.ToString().Equals(inputUsername) && login.Password.ToString().Equals(inputPassword)) { //Store data employeeID = login.EmployeeId; loginID = login.LoginId; //Set boolean isMatch = true; /* * //Print message * return Content(LOG_TAG + ": Alright !" + * "\nThe inputs and login details are equal" + * "\nInputs" + * "\n- Username: "******"\n- Password: "******"\nLogin Details" + * "\n- Username: "******"\n- Password: "******"\n- Employee ID: " + login.EmployeeId + * "\n- Login ID: " + login.LoginId * ); */ } /* * //Store logins * loginList += "Employee ID: " + login.EmployeeId + ": " + * "\n- Login ID: " + login.LoginId + * "\n- Username: "******"\n- Password: "******"\n\n"; */ } //Check boolean value if (isMatch == true) { //Set new values for login trails var employeLoginTrail = new LoginTrail { LogInId = loginID, LogInTime = loginDate }; //Use context to add recored in login trails _context.LoginTrail.Add(employeLoginTrail); _context.SaveChanges(); //Store query var employeeDetails = from emp in _context.Employees join l in _context.Login on emp.EmployeeId equals l.EmployeeId where emp.EmployeeId == employeeID select emp; //Loop through List foreach (var detail in employeeDetails) { //Check employee role if (detail.UserRole.Equals("Admin")) { //Redirect to dashboard & pass employee ID return(RedirectToAction("AdminDashboard", "Dashboard", new { id = employeeID })); } else if (detail.UserRole.Equals("Manager")) { //Redirect to dashboard & pass employee ID return(RedirectToAction("ManagerDashboard", "Dashboard", new { id = employeeID })); } else if (detail.UserRole.Equals("Employee")) { //Redirect to dashboard & pass employee ID return(RedirectToAction("EmployeeDashboard", "Dashboard", new { id = employeeID })); } /* * //Print message * return Content(LOG_TAG + ": Logged In Employee Details" + * "\n- Role: " + detail.UserRole * ); */ } } else { //Print error } /* * //Print message * return Content(LOG_TAG + ": List of existing Login Details content" + * "\n" + loginList * ); */ } //Redirect to view return(View("~/Views/Logins/Index.cshtml")); }