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)); }
public IActionResult Edit(int publisherId) { var publisher = publisherData.GetPubliserById(publisherId); if (publisher == null) { return(RedirectToAction("Index")); } return(View(publisher)); }