笔试在线考试系统-管理员登录、考生管理

1、管理员登录

页面效果

笔试在线考试系统-管理员登录、考生管理_第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考生信息列表

页面效果:

笔试在线考试系统-管理员登录、考生管理_第2张图片

 

 实现步骤:

public ActionResult StudentList()
{
using (OnLineExamDB db = new OnLineExamDB())
{
List 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添加考生信息

页面效果:

笔试在线考试系统-管理员登录、考生管理_第3张图片

 

 实现步骤:

///


/// 添加学生-视图
///

///
public ActionResult AddStudent()
{
ViewBag.Institution = GetInstitutionForDDL();
return View();
}
///
/// 添加考生信息--实现功能
///

/// 学生信息
///
[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编辑考生信息

页面效果:

笔试在线考试系统-管理员登录、考生管理_第4张图片

 

 实现步骤:

///


/// 修改考生信息-视图
///

/// 主键编号
///
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);
}
}
///
/// 修改学生信息-实现功能
///

/// 学生信息
///
[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删除考生信息(逻辑删除)

笔试在线考试系统-管理员登录、考生管理_第5张图片

 

 实现步骤:

///


/// 删除学生信息
///

/// 主键编号
///
[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");
}
}

你可能感兴趣的:(笔试在线考试系统-管理员登录、考生管理)