笔试在线考试系统-管理员登录、考生管理
1、管理员登录
页面效果
实现步骤:
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);
}
}
2、考生管理
2.1考生信息列表
页面效果:
实现步骤:
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);
}
}
2.2添加考生信息
页面效果:
实现步骤:
/// <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");
}
}
2.3编辑考生信息
页面效果:
实现步骤:
/// <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");
}
}