public async Task<ActionResult> Add(AddEbookModel model) { if (!ModelState.IsValid) return View(model); using (var db = new EbookManagerDbContext()) { var catalogRepository = new CatalogRepository(db); var ebook = new Ebook(); ebook.Id = Guid.NewGuid(); ebook.Summary = model.Summary; ebook.Title = model.Title; ebook.Thumbnail = new byte[model.Thumbnail.ContentLength]; model.Thumbnail.InputStream.Read(ebook.Thumbnail, 0, ebook.Thumbnail.Length); try { await catalogRepository.AddEbookAsync(ebook); return RedirectToRoute("editEbook", new { ebookId = ebook.Id }); } catch (Exception e) { ModelState.AddModelError("InsertError", e); return View(model); } } }
public ActionResult Add() { var model = new AddEbookModel(); return View(model); }