예제 #1
0
 private void ChangeEntities(Record record, Publisher publisher, AdminEditModel model)
 {
     record.RecordName = model.record.RecordName;
     record.RecordDescription = model.record.RecordDescription;
     record.Author = model.record.Author;
     publisher.PublisherName = model.publisher.PublisherName;
     publisher.Address = model.publisher.Address;
     publisher.Email = model.publisher.Email;
     publisher.Number = model.publisher.Number;
     record.Author = publisher;
 }
예제 #2
0
 public ActionResult Edit(int id, AdminEditModel viewModel)
 {
     if (ModelState.IsValid)
     {
         using (LibraryContext db = new LibraryContext())
         {
             var recordQuery = (from r in db.Records
                                where r.RecordId == id
                                select r).First();
             var publisherQuery = (from p in db.Publishers
                                   where p.PublisherId == recordQuery.PublisherId
                                   select p).First();
             ChangeEntities(recordQuery, publisherQuery, viewModel);
             db.SaveChanges();
             return Redirect("/Admin/Index");
         }
     }
     else
     {
         return View(viewModel);
     }
 }
예제 #3
0
 public ActionResult Edit(int? id)
 {
     int realId;
     if (id == null)
     {
         return new HttpStatusCodeResult(400, "Expected books id");
     }
     else
     {
         realId = (int)id;
     }
     using (LibraryContext db = new LibraryContext())
     {
         bool idIsValid = (from r in db.Records
                           select r.RecordId).Contains(realId);
         if (!idIsValid)
         {
             return new HttpStatusCodeResult(404, "No book with such id: " + realId);
         }
         Record currentBook = (from r in db.Records where r.RecordId == realId select r).First();
         Publisher currentPublisher = (from p in db.Publishers where p.PublisherId == currentBook.PublisherId select p).First();
         AdminEditModel viewModel = new AdminEditModel(currentBook, currentPublisher);
         return View(viewModel);
     }
 }