Ejemplo n.º 1
0
 public IActionResult Create(BookCreateEditViewModel model)
 {
     if (ModelState.IsValid)
     {
         foreach (var publisher in model.AddPublisher)
         {
             if (publisher.Selected)
             {
                 model.Book.BookPublishers.Add(new BookPublishers
                 {
                     Publisher = publisherData.GetPubliserById(Convert.ToInt32(publisher.Value))
                 });
             }
         }
         bookData.CreateBook(model.Book);
         bookData.Commit();
         TempData["Message"] = "The object is edited";
         return(RedirectToAction("Index"));
     }
     model.AddPublisher = publisherData.GetPublisers().Select(x => new SelectListItem
     {
         Selected = false,
         Value    = x.Id.ToString(),
         Text     = x.Name
     }).ToList();
     return(View(model));
 }