// GET: Admin/HocSinhManagement/Delete/5 public ActionResult Delete(int id) { HocSinh hocSinh = hocSinhRepository.GetById(id); if (hocSinh.TaiKhoanID != null) { TaiKhoan taiKhoan = taiKhoanRepository.GetById((int)hocSinh.TaiKhoanID); hocSinhRepository.Delete(hocSinh); taiKhoanRepository.Delete(taiKhoan); } else { hocSinhRepository.Delete(hocSinh); } return(RedirectToAction("Index")); }
private void btnXoaHS_Click(object sender, EventArgs e) { string oldHS = dgvHocSinh.SelectedRows[0].Cells["MaHS"].Value.ToString(); HocSinh hs = _hocSinhRepository.FindByCondition(p => p.MaHS.Equals(oldHS)).Single(); int nguoiDungID = hs.NguoiDungID; _hocSinhRepository.Delete(hs); _hocSinhRepository.Update(); NguoiDung nguoiDung = _nguoiDungRepository.FindByCondition(p => p.IDNguoiDung.Equals(nguoiDungID)).Single(); _nguoiDungRepository.Delete(nguoiDung); _nguoiDungRepository.Update(); LoadHocSinh(); }