public ActionResult Add() { var model = new BookModel { IsEditMode = false }; model = Mapper.Map(_authorRepository.GetAll(), model); return View("Edit", model); }
public ActionResult Add(BookModel model) { if (ModelState.IsValid) { var book = Mapper.Map<BookModel, Book>(model); _bookRepository.Insert(book); return RedirectToAction("Index", "Home", new { message = (int)BooksListSuccessMessage.BookAddedSuccesfully }); } return Add(); }
public ActionResult Edit(BookModel model) { if (ModelState.IsValid) { var book = _bookRepository.Get(model.Id); if (book == null) return RedirectToAction("Index", "Home"); book = Mapper.Map(model, book); _bookRepository.Save(book); return RedirectToAction("Index", "Home", new { message = (int)BooksListSuccessMessage.BookEditedSuccesfully }); } return Edit(model.Id); }