Exemplo n.º 1
0
 //
 // 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));
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 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));
 }