예제 #1
0
        public JsonResult DeleteTitle(int id)
        {
            bool              TitleInUse        = false;
            Title             title             = new Title();
            TitleRepository   titleRepository   = new TitleRepository();
            TeacherRepository teacherRepository = new TeacherRepository();

            title = titleRepository.GetById(id);
            Teacher teacher = teacherRepository.GetAll(filter: t => t.Title.Id == id).FirstOrDefault();

            if (teacher == null)
            {
                titleRepository.Delete(title);
            }
            else
            {
                TitleInUse = true;
            }

            //return RedirectToAction("ManageTitles");
            return(Json(TitleInUse, JsonRequestBehavior.AllowGet));
        }
        public void SaveAndDeleteTestNew()
        {
            // Save new object into DB
            // Arrange
            var title = new Title
            {
                TitleId         = 999999,
                CreatedDateTime = DateTime.Now
            };

            // Act
            var saveResult = titleRepository.Save(title);

            // Assert
            Assert.IsInstanceOfType(saveResult, typeof(Title));

            // Delete saved object from DB
            // Act
            titleRepository.Delete(saveResult);

            // Assert
            Assert.IsNull(titleRepository.FindById(999999));
        }
        public JsonResult DeleteTitle(int id)
        {
            bool TitleInUse = false;
            Title title = new Title();
            TitleRepository titleRepository = new TitleRepository();
            TeacherRepository teacherRepository = new TeacherRepository();
            title = titleRepository.GetById(id);
            Teacher teacher = teacherRepository.GetAll(filter: t => t.Title.Id == id).FirstOrDefault();
            if (teacher == null)
            {
                titleRepository.Delete(title);
            }
            else
            {
                TitleInUse = true;
            }

            //return RedirectToAction("ManageTitles");
            return Json(TitleInUse, JsonRequestBehavior.AllowGet);
        }