//Remove question from de thi public ActionResult RemoveQuestion(int id) { CauHoi cauHoi = cauHoiRepository.GetById(id); DeThi deThi = deThiRepository.GetById((int)Session["DeThiID"]); deThi.CauHois.Remove(cauHoi); deThiRepository.Update(deThi); return(RedirectToAction("Details", new { id = (int)Session["DeThiID"] })); }
private void btnSuaDT_Click(object sender, EventArgs e) { string maDT = dgvDeThi.SelectedRows[0].Cells["MaDT"].Value.ToString(); DeThi dt = _deThiRepository.FindByCondition(p => p.MaDeThi.Equals(maDT)).Single(); dt.MaDeThi = maDeThiTextBox.Text; dt.TenDeThi = tenDeThiTextBox.Text; dt.MaMH = maMHComboBox.SelectedValue.ToString(); dt.ThoiGian = int.Parse(thoiGianTextBox.Text); dt.MaCapHoc = int.Parse(maCapHocComboBox.SelectedValue.ToString()); _deThiRepository.Update(); List <DeThi_CauHoi> deThi_CauHois = _dt_chRepository.FindByCondition(p => p.MaDT.Equals(maDT)).ToList(); foreach (var item in deThi_CauHois) { _dt_chRepository.Delete(item); } _dt_chRepository.Update(); foreach (DataGridViewRow item in dgvDSCauHoi.Rows) { var cell = item.Cells["Chon"] as DataGridViewCheckBoxCell; if (cell.Value == cell.TrueValue) { string cauhoi = item.Cells["DeThiCauHoi"].Value.ToString(); CauHoi idCauHoi = _cauHoiRepository.FindByCondition(p => p.CauHoiDeBai.Equals(cauhoi)).Single(); _dt_chRepository.Create(new DeThi_CauHoi { MaDT = dgvDeThi.SelectedRows[0].Cells["MaDT"].Value.ToString(), IDCauHoi = idCauHoi.IDCauHoi }); } } _dt_chRepository.Update(); ReLoad(); }
private void btnThemDT_Click(object sender, EventArgs e) { string maDT = maDeThiTextBox.Text; maDeThiTextBox.Undo(); if (_deThiRepository.FindByCondition(p => p.MaDeThi.Equals(maDT)).Count() > 0) { MessageBox.Show("Mã đề thi đã tồn tại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);; return; } _deThiRepository = new DeThiRepository(); DeThi deThi = new DeThi(); deThi.MaDeThi = maDT; deThi.TenDeThi = tenDeThiTextBox.Text; deThi.MaMH = maMHComboBox.SelectedValue.ToString(); deThi.ThoiGian = int.Parse(thoiGianTextBox.Text); deThi.MaCapHoc = int.Parse(maCapHocComboBox.SelectedValue.ToString()); deThi.MaGV = lblMaGV.Text; deThi.NgayTao = DateTime.Now; _deThiRepository.Create(deThi); _deThiRepository.Update(); foreach (DataGridViewRow item in dgvDSCauHoi.Rows) { var cell = item.Cells["Chon"] as DataGridViewCheckBoxCell; if (cell.Value == cell.TrueValue) { string cauhoi = item.Cells["DeThiCauHoi"].Value.ToString(); CauHoi idCauHoi = _cauHoiRepository.FindByCondition(p => p.CauHoiDeBai.Equals(cauhoi)).Single(); _dt_chRepository.Create(new DeThi_CauHoi { MaDT = maDT, IDCauHoi = idCauHoi.IDCauHoi }); } } _dt_chRepository.Update(); ReLoad(); }