public ActionResult EditTitles(int id, AdminControllerTitleVM titleModel) { TryUpdateModel(titleModel); if (ModelState.IsValid) { Title title = null; TitleRepository titleRepository = new TitleRepository(); if (id > 0) { title = titleRepository.GetById(id); title.Name = titleModel.Title; titleRepository.Save(title); return(RedirectToAction("ManageTitles")); } else { title = titleRepository.GetAll(filter: t => t.Name == titleModel.Title).FirstOrDefault(); if (title == null) { title = new Title(); title.Name = titleModel.Title; titleRepository.Save(title); return(RedirectToAction("ManageTitles")); } else { throw new ArgumentException("Invalid Title"); } } } return(View(titleModel)); }
public void SaveTestExistingChangeName() { // Arrange var title = titleRepository.FindById(1); var original = title.Name; title.Name = "Mr.."; // Act var result = titleRepository.Save(title); // Assert Assert.AreEqual("Mr..", result.Name); // Tear Down title.Name = original; titleRepository.Save(title); }
public ActionResult AddTitle(UniversitySystem.ViewModel.Titles.AddTitle model) { if (!ModelState.IsValid) { return View(); } TitleRepository titleRepo = new TitleRepository(); Title title = new Title(); title.Name = model.TitlteName; titleRepo.Save(title); return RedirectToAction("ListTeachers", "Teacher"); }
public ActionResult EditTitles(int id, AdminControllerTitleVM titleModel) { TryUpdateModel(titleModel); if (ModelState.IsValid) { Title title = null; TitleRepository titleRepository = new TitleRepository(); if (id > 0) { title = titleRepository.GetById(id); title.Name = titleModel.Title; titleRepository.Save(title); return RedirectToAction("ManageTitles"); } else { title = titleRepository.GetAll(filter: t => t.Name == titleModel.Title).FirstOrDefault(); if (title == null) { title = new Title(); title.Name = titleModel.Title; titleRepository.Save(title); return RedirectToAction("ManageTitles"); } else { throw new ArgumentException("Invalid Title"); } } } return View(titleModel); }