public IActionResult OnPost() { if (ModelState.IsValid) { var author = personData.GetPersonById(Book.PersonId.Value); Book.Author = author; if (Book.Id == 0) { Book = bookData.Create(Book); TempData["Message"] = "The Object is created!"; } else { Book = bookData.Update(Book); TempData["Message"] = "The Object is updated!"; } bookData.Commit(); return(RedirectToPage("./List")); } var authors = personData.GetPersons().ToList().Select(p => new { Id = p.Id, Display = $"{p.FirstName} {p.LastName}" }); Authors = new SelectList(authors, "Id", "Display"); return(Page()); }
public IActionResult Edit(BookViewModel model) { if (ModelState.IsValid) { var author = personData.GetPersonById(model.Book.PersonId.Value); model.Book.Author = author; if (model.Book.Id == 0) { model.Book = bookData.Create(model.Book); TempData["Message"] = "The Object is created!"; } else { model.Book = bookData.Update(model.Book); TempData["Message"] = "The Object is updated!"; } bookData.Commit(); return(RedirectToAction("Index")); } var authors = personData.GetPersons().ToList().Select(p => new { Id = p.Id, Display = $"{p.FirstName} {p.LastName}" }); model.Authors = new SelectList(authors, "Id", "Display"); return(View(model)); }
public RedirectToActionResult Create(Book b) { _tracker.Add("Home.Create.Post"); _bda.Create(b); return(RedirectToAction("Index")); }