頁面效果3d
實現步驟:orm
public ActionResult AdminLogin(AdminLoginModel model)
{
if (FormsAuthentication.Authenticate(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, false);
return View("Index");
}
else
{
ViewBag.Message = "用戶名或密碼輸入有誤!";
return View(model);
}
}blog
頁面效果:it
實現步驟:io
public ActionResult StudentList()
{
using (OnLineExamDB db = new OnLineExamDB())
{
List<StudentListModel> list = db.StuInfo.Where(a => a.Status != 2).Select(a => new StudentListModel
{
stu_Id = a.stu_Id,
stu_No = a.stu_No,
stu_Name = a.stu_Name,
password = a.password,
LoginTimes = a.LoginTimes,
LoginDate = a.LoginDate,
Status = a.Status,
Institution_Name = a.Institution.i_Name
}).ToList();
return View(list);
}登錄
}date
頁面效果:List
實現步驟:model
/// <summary>
/// 添加學生-視圖
/// </summary>
/// <returns></returns>
public ActionResult AddStudent()
{
ViewBag.Institution = GetInstitutionForDDL();
return View();
}
/// <summary>
/// 添加考生信息--實現功能
/// </summary>
/// <param name="model">學生信息</param>
/// <returns></returns>
[HttpPost]
public ActionResult AddStudent(AddStudentModel model)
{
using (OnLineExamDB db = new OnLineExamDB())
{
StuInfo stu = new StuInfo
{
institution_Id = model.institution_Id,
password = model.stu_No,
Status = 1,
stu_No = model.stu_No,
stu_Name = model.stu_Name,
LoginTimes = 0
};
db.StuInfo.Add(stu);
db.SaveChanges();
ViewBag.Institution = GetInstitutionForDDL();
return View("StudentList");
}密碼
}
頁面效果:
實現步驟:
/// <summary>
/// 修改考生信息-視圖
/// </summary>
/// <param name="id">主鍵編號</param>
/// <returns></returns>
public ActionResult UpdateStudent(int id)
{
using (OnLineExamDB db = new OnLineExamDB())
{
UpdateStudentModel model = db.StuInfo.Where(a => a.stu_Id == id).Select(a => new UpdateStudentModel
{
institution_Id = a.institution_Id,
stu_Id = a.stu_Id,
LoginDate = a.LoginDate,
LoginTimes = a.LoginTimes,
password = a.password,
Status = a.Status,
stu_Name = a.stu_Name,
stu_No = a.stu_No
}).FirstOrDefault();
ViewBag.Status = GetStudentStatusForDDL();
ViewBag.Institution = GetInstitutionForDDL();
return View(model);
}
}
/// <summary>
/// 修改學生信息-實現功能
/// </summary>
/// <param name="model">學生信息</param>
/// <returns></returns>
[HttpPost]
public ActionResult UpdateStudent(UpdateStudentModel model)
{
using (OnLineExamDB db = new OnLineExamDB())
{
StuInfo stu = db.StuInfo.First(a => a.stu_Id == model.stu_Id);
stu.institution_Id = model.institution_Id;
stu.stu_Name = model.stu_Name;
stu.stu_No = model.stu_No;
stu.Status = model.Status;
stu.password = model.password;
db.SaveChanges();
return RedirectToAction("StudentList");
}
}
2.4刪除考生信息(邏輯刪除)
實現步驟:
/// <summary> /// 刪除學生信息 /// </summary> /// <param name="id">主鍵編號</param> /// <returns></returns> [HttpPost] public ActionResult DelStudent(int id) { using (OnLineExamDB db = new OnLineExamDB()) { StuInfo model = db.StuInfo.First(a => a.stu_Id == id); model.Status = 2; db.SaveChanges(); return Json("ok"); } }