コード例 #1
0
        private void teacherDeleteButton_Click(object sender, EventArgs e)
        {
            var selectedRowIndex = GetSelectedRowIndex(teachersDataGridView);

            if (selectedRowIndex == null)
            {
                return;
            }
            TeachersRepository.Delete(TeachersRepository.GetAll()[(int)selectedRowIndex].Id);
            UpdateTeachersGrid();
        }
コード例 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Teacher teacher = teachersRepo.GetById(id);

            try
            {
                teachersRepo.Delete(teacher);
            }
            catch (Exception)
            {
                ViewBag.Message    = "Teacher " + teacher.FirstName + " " + teacher.LastName + " cannot be deleted. He has related courses. Delete courses first.";
                ViewBag.Related    = "Go to Courses";
                ViewBag.Controller = "Courses";
                return(View("DeleteError"));
            }
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public void DeleteTeacher(TeacherEntity teacher)
        {
            TeachersRepository teachRepo = new TeachersRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    teachRepo.Delete(teacher.Id, uow);
                    uow.ApplyChanges();
                }
                catch (Exception ex)
                {
                    DbLog.LogError("Error deleting teacher " + teacher.Id, ex);
                    throw ex;
                }
            }
        }