// GET: Admin public ActionResult Index() { using (var db = new EbooksContext()) { if (!db.GetEbooksUser(User).IsAdmin) return RedirectToAction("Index", "Ebooks"); } return View(new AdminViewModel()); }
public ActionResult Download(int gutBookId, bool images) { using (var db = new EbooksContext()) { var gutBook = db.GutBooks.Single(b => b.GutBookId == gutBookId); // Check whether the book has already been downloaded var ef = db.EpubFiles.SingleOrDefault(e => e.GutBookId == gutBook.GutBookId && e.GutBookWithImages == images); Epub ep; if (ef != null) { ep = new Epub(ef.Contents); } else { ep = new Epub(images ? gutBook.GetEpubImages() : gutBook.GetEpubNoImages()); } try { var user = db.GetEbooksUser(User); var book = Book.Load(db, ep, user.UserId); if (book.Publisher == null) book.Publisher = Publisher.Get(db, "Project Gutenberg"); if (ef == null) { book.EpubFile.GutBookId = gutBook.GutBookId; book.EpubFile.GutBookWithImages = images; } db.SaveChanges(); } finally { ep.Dispose(); } } return RedirectToAction("Index", "Ebooks"); }
public ActionResult Download(int bookId) { using (var db = new EbooksContext()) { var user = db.GetEbooksUser(User); var book = db.Books.SingleOrDefault(b => b.BookId == bookId && b.UserId == user.UserId); if (book == null) return RedirectToAction("Index"); return File(book.EpubFile.Contents, System.Net.Mime.MediaTypeNames.Application.Octet, book.Title + ".epub"); } }
public ActionResult Cover(int bookId) { using (var db = new EbooksContext()) { var user = db.GetEbooksUser(User); var book = db.Books.SingleOrDefault(b => b.BookId == bookId && b.UserId == user.UserId); if (book == null) return RedirectToAction("Index"); var model = new CoverViewModel { BookId = book.BookId, Title = book.Title }; return View(model); } }
public ActionResult ImportGutCatalogue() { using (var db = new EbooksContext()) { if (!db.GetEbooksUser(User).IsAdmin) return RedirectToAction("Index", "Ebooks"); } TaskManager.AddTask<GutenbergLoadTask>(schedule => schedule.ToRunNow()); // Wait a second for it to start Thread.Sleep(1000); return RedirectToAction("Index"); }
public ActionResult Delete(int bookId) { using (var db = new EbooksContext()) { var user = db.GetEbooksUser(User); var book = db.Books.SingleOrDefault(b => b.BookId == bookId && b.UserId == user.UserId); if (book != null) { db.Books.Remove(book); db.SaveChanges(); } } return RedirectToAction("Index"); }
public ActionResult ReadContent() { int bookId = Convert.ToInt32(Request.Url.Segments[3].TrimEnd('/')); string file = HttpUtility.UrlDecode(string.Join("", Request.Url.Segments.Skip(4))); using (var db = new EbooksContext()) { var userId = db.GetEbooksUser(User).UserId; var book = db.Books.Single(b => b.BookId == bookId && b.UserId == userId); if (book == null) return null; using (var ep = new Epub(book)) { return new FileStreamResult(ep.GetContentFile(file), "text/html"); } } }
public ActionResult Edit(int? bookId) { if (bookId == null) return RedirectToAction("Index"); using (var db = new EbooksContext()) { var user = db.GetEbooksUser(User); var book = db.Books.SingleOrDefault(b => b.BookId == bookId && b.UserId == user.UserId); if (book == null) return Redirect(Request.UrlReferrer.ToString()); var model = new BookViewModel(book, db); // ListBoxFor is broken, see https://social.msdn.microsoft.com/Forums/vstudio/en-US/05ee3b35-f3d3-48b4-83f5-ca3d9073624e/mvc-htmlhelper-listboxfor-and-listbox-multiselectlist-bug?forum=netfxbcl ViewBag.Tags = model.TagList; return View(model); } }
// GET: ReadBook public ActionResult Index(int bookId = 0, int spineIndex = 0) { using (var db = new EbooksContext()) { var user = db.GetEbooksUser(User); var book = db.Books.SingleOrDefault(b => b.BookId == bookId && b.UserId == user.UserId); if (book == null) return RedirectToAction("Index", "Ebooks"); using (var ep = new Epub(book)) { var spine = ep.SpineRefs.ToArray(); spineIndex = Math.Max(0, Math.Min(spineIndex, spine.Length - 1)); string url = Url.Action($"ReadContent/{bookId}/{spine[spineIndex]}"); var model = new ReadBookViewModel { SpineRefs = ep.SpineRefs.ToArray(), Title = book.Title, Url = url, BookId = bookId, Toc = ep.Toc }; return View(model); } } }
// GET: Ebooks public ActionResult Index() { using (var db = new EbooksContext()) { var model = new DisplayBooksViewModel { BookSet = db.GetEbooksUser(User).Books }; model.Search = (string)Session["Search"]; model.HiddenColumns = Session["HiddenCols"] == null ? null : string.Join(", ", ((List<int>)Session["HiddenCols"]).Select(c => c.ToString())); return View(model); } }
public ActionResult UploadFiles() { using (var db = new EbooksContext()) { var user = db.GetEbooksUser(User); foreach (string f in Request.Files) { HttpPostedFileBase hpf = Request.Files[f] as HttpPostedFileBase; if (hpf.ContentLength == 0) continue; using (var m = new MemoryStream(hpf.ContentLength)) { hpf.InputStream.CopyTo(m); var epub = new Epub(m); Book.Load(db, epub, user.UserId); db.SaveChanges(); } } } return Redirect("~/Ebooks"); }