Exemple #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();
        }
        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"));
        }
        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;
                }
            }
        }