public ActionResult Edit(int? id) { var _book = Book.Get(id ?? 0); var _categories = Category.Get(); var book = Mapper.Map<BookModel>(_book); var categories = Mapper.Map<CategoryModel[]>(_categories); var view = new BookEditContainer { Book = book, Categories = categories }; return View("edit", view); }
public ActionResult Create() { var _book = new Book(); var _categories = Category.Get(); var book = Mapper.Map<BookModel>(_book); book.Number = null; var categories = Mapper.Map<CategoryModel[]>(_categories); var view = new BookEditContainer { Book = book, Categories = categories }; return View("edit", view); }
public ActionResult Edit(BookModel model) { if (!ModelState.IsValid) { var _categories = Category.Get(); var categories = Mapper.Map<CategoryModel[]>(_categories); var view = new BookEditContainer { Book = model, Categories = categories }; return View("edit", view); } var book = Mapper.Map<Book>(model); var _book = Book.Set(book); if (model.Image != null || model.Remove) { if (model.Remove) { _book.SetImage(null); } else if (model.Image != null) { var filename = ImageStore.Save(model.Image.InputStream); if (!String.IsNullOrEmpty(filename)) { _book.SetImage(filename); } else { ModelState.AddModelError("image", "Fehler beim speichern des Bildes."); } } } return RedirectToAction("view", "book", new { id = _book.Id }); }