i am currently doing a Login page which directs to whichever page according to their StaffRole. Eg, if StaffRole = Manager, direct to manager page. Here is my code below for my controller method. However my controller method shows an error which says not all code paths return a value. I am unsure how to solve this.
` [HttpPost]
public ActionResult Verify(Account acc)
{
connectionString();
con.Open();
com.Connection = con;
com.CommandText = "select * from Staff where StaffNRIC='" + acc.StaffNRIC + "' and StaffContact='" + acc.StaffContact + "' and StaffAccountStatus = 'Approved'";
dr = com.ExecuteReader();
if (dr.Read())
{
if (dr.HasRows)
{
while (dr.Read())
{
if (dr["StaffRole"].ToString() == "Manager")
{
dr.Close();
return RedirectToAction("Manager/ManagerHome", "ManagerController");//wherever you want to return the user to
}
else if (dr["StaffRole"].ToString() == "Admin")
{
dr.Close();
return RedirectToAction("Admin/AdminHome", "AdminController");
}
else if (dr["StaffRole"].ToString() == "Part-Timer")
{
dr.Close();
return RedirectToAction("PartTimer/PartTimerHome", "PartTimerController");
}
else
{
con.Close();
return View("Login");
}
}
}
}
}`
' SqlConnection con = new SqlConnection(); SqlCommand com = new SqlCommand(); SqlDataReader dr;