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 static EbookViewModel FromEbook(Ebook ebook)
 {
     return new EbookViewModel()
     {
         Id = ebook.Id,
         PartsCount = ebook.Parts != null ? ebook.Parts.Count : 0,
         Summary = ebook.Summary,
         Thumbnail = Convert.ToBase64String(ebook.Thumbnail),
         Title = ebook.Title
     };
 }
		public async Task UpdateBookAsync(Ebook ebook)
		{
			this.db.Entry(ebook).State = EntityState.Modified;
			await this.db.SaveChangesAsync();
		}
		public async Task AddEbookAsync(Ebook ebook)
		{
			this.db.Ebooks.Add(ebook);
			await this.db.SaveChangesAsync();
		}