我有2张彼此无关的表。员工和病人。
注意(两个实体的数据库调用都在同一个Controller,EmployeeController中调用。请检查我在下面链接的要点)
我尝试从员工成功登录尝试后获取患者列表。以下是工作流程:
要点:https://gist.github.com/anonymous/95ffda179eb690e8a9efbdc5cb1aa15c
[HttpPost]
public ActionResult Login(Employee MyEmployee)
{
EmployeeBusinessLayer MyEmployeeBusinessLayer = new EmployeeBusinessLayer();
List<Employee> MyEmployeeLst = MyEmployeeBusinessLayer.GetEmployeesByID(MyEmployee.UserName, MyEmployee.Password);
if (MyEmployeeLst.Count > 0)
{
Session["EmployeeID"] = MyEmployeeLst[0].ID;
Session["UserName"] = MyEmployeeLst[0].UserName;
return RedirectToAction("Main");
}
else
{
ModelState.AddModelError("", "Username or password is wrong");
}
return View();
}
Main()函数:
public ActionResult Main()
{
if (Session["EmployeeID"] != null)
{
PatientBusinessLayer PBL = new PatientBusinessLayer();
List<Patient> MyPatientLst = PBL.GetPatients();
return View();
}
else
{
return RedirectToAction("Login");
}
}