public ActionResult Register(ThiSinh entity) { if (ModelState.IsValid) { var dao = new ThiSinhData(); var user = new ThiSinh(); user.GioiTinh = entity.GioiTinh; user.NgaySinh = entity.NgaySinh; user.DiaChi = entity.DiaChi; user.Image = entity.Image; user.Password = entity.Password; tn.SaveChanges(); if (dao.Insert(user) > 0) { ViewBag.Success = "Đăng ký thành công!"; entity = new ThiSinh(); } else { ModelState.AddModelError("", "Đăng ký không thành công!"); } } return(RedirectToAction("Index", "Login")); }
public ActionResult AddQuizs(MultiQuizModel collection, int id) { try { TracNghiemEntities tn = new TracNghiemEntities(); if (ModelState.IsValid) { for (int i = 0; i < collection.Quiz.Count; i++) { if (collection.Quiz[i].table_records) { tn.ch_db.Add(new ch_db() { MaDe = id, MaCauHoi = collection.Quiz[i].MaCauHoi }); tn.SaveChanges(); } } return(RedirectToAction("Details", "DeThi", new { id = id })); } return(View(collection)); } catch { return(View()); } }
public ActionResult StartContest(int id, ContestModel collection) { int socau = tn.ch_db.Count(x => x.MaDe == id); float hesodiem = 100 / socau; float diem; int bodem = 0; for (int i = 0; i < collection.ListQuiz.Count; i++) { var quizid = tn.Quizs.Find(collection.ListQuiz[i].MaCauHoi); if (quizid.DapAn == collection.ListQuiz[i].SelectedAnswer) { bodem = bodem + 1; } } diem = bodem * hesodiem; var session = (TracNghiemLTK.Common.ThiSinhInfo)Session[TracNghiemLTK.Common.CommonConstantsStudent.STUDENT_SESSION]; tn.KetQuas.Add(new KetQua() { MaDe = id, MaThiSinh = session.MaThiSinh, Diem = diem, NgayThi = DateTime.Now }); tn.SaveChanges(); return(RedirectToAction("Index", "ContestResult", new { area = "Contest", @maThiSinh = session.MaThiSinh, @maDe = id })); }