// // GET: /Textbook/Details/5 public ActionResult Details(int id) { using (InstManager) { using (PublishersManager) { using (AuthorsManager) { using (PeopleManager) { var tb = TBManager.GetTextbookbyID(id); var disp = Mapper.Map <vmTextbook>(tb); if (disp != null) { disp.Publisher = Mapper.Map <vmPublisher>(PublishersManager.GetPublisherbyID(tb.PublisherID)); disp.Author = Mapper.Map <vmAuthor>(AuthorsManager.GetAuthorbyID(tb.AuthorID)); disp.Author.Person = Mapper.Map <vmPerson>(PeopleManager.GetPersonbyID(disp.Author.PersonID)); } else { disp = new vmTextbook(); ModelState.AddModelError("", "Failed to load details for requested item."); } return(View(disp)); } } } } }
public ActionResult Delete(vmTextbook tb) { try { using (TBManager) { var item = TBManager.GetTextbookbyID(tb.ID); var success = TBManager.RemoveTextbook(item); if (success) { return(RedirectToAction("Index")); } throw new DataException("Enable to delete textbook " + tb.Name + ". Please try again."); } } catch (DataException ex) { ModelState.AddModelError("", ex.Message); } return(View(tb)); }
public ActionResult Details(int id) { using (DeptManager) { using (InstManager) { using (PeopleManager) { using (TBManager) { var item = InstManager.GetInstructorbyID(id); var disp = Mapper.Map <vmInstructor>(item); if (disp != null) { disp.Person = Mapper.Map <vmPerson>(PeopleManager.GetPersonbyID(item.PersonID)); disp.Department = Mapper.Map <vmDepartment>(DeptManager.GetDepartmentbyID(item.DepartmentID)); disp.Textbooks = TBManager.GetAllTextbooks().ToList(); var books = InstManager.FindInstructorBooks(i => i.InstructorID == id).Select(i => i.TextBookID); foreach (var b in books) { var t = TBManager.GetTextbookbyID(b); if (t != null) { disp.InstructorTextbooks.Add(Mapper.Map <vmTextbook>(t)); } } } else { disp = new vmInstructor(); ModelState.AddModelError("", "Failed to load details for requested item."); } return(View(disp)); } } } } }
public ActionResult Edit(vmTextbook tb) { try { using (InstManager) { using (PublishersManager) { using (AuthorsManager) { using (PeopleManager) { var text = TBManager.GetTextbookbyID(tb.ID); text.Name = tb.Name; text.PublishDate = tb.PublishDate; var success = TBManager.UpdateTextbook(text); if (success) { var auth = AuthorsManager.GetAuthorbyID(text.AuthorID); var pers = PeopleManager.GetPersonbyID(auth.PersonID); pers.FirstMidName = tb.Author.Person.FirstMidName; pers.LastName = tb.Author.Person.LastName; success = PeopleManager.UpdatePerson(pers); if (success) { var pub = PublishersManager.GetPublisherbyID(text.PublisherID); pub.Name = tb.Publisher.Name; pub.City = tb.Publisher.City; pub.State = tb.Publisher.State; success = PublishersManager.UpdatePublisher(pub); if (success) { return(RedirectToAction("Details", new { id = tb.ID })); } else { throw new DataException("Failed to save publisher. Please try again."); } } else { throw new DataException("Failed to save author. Please try again."); } } else { throw new DataException("Failed to save textbook. Please try again."); } } } } } } catch (DataException ex) { //Log the error (add a variable name after DataException) ModelState.AddModelError("", ex.Message); } tb.Publisher = Mapper.Map <vmPublisher>(PublishersManager.GetPublisherbyID(tb.PublisherID)); tb.Author = Mapper.Map <vmAuthor>(AuthorsManager.GetAuthorbyID(tb.AuthorID)); tb.Author.Person = Mapper.Map <vmPerson>(PeopleManager.GetPersonbyID(tb.Author.PersonID)); return(View(tb)); }