public override void Update() { Thread.Sleep(3000); System.Diagnostics.Debug.WriteLine(string.Format("kitap ebook ekleme başlıyor.... ID : {0}", EbookNo)); try { string path = string.Format("~/Files/{0}/epub_{0}.epub", EbookNo); using (var fs = new FileStream(HostingEnvironment.MapPath(path), FileMode.Open)) { EpubBook epubBook = EpubReader.ReadBook(fs); foreach (EpubTextContentFile textContentFile in epubBook.ReadingOrder) { // HTML of current text content file string htmlContent = textContentFile.Content; HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument(); htmlDocument.LoadHtml(htmlContent); // Insert to db using (VBSContext db = new VBSContext()) { BookPage bp = new BookPage(); bp.BookId = BookId; bp.HtmlContent = htmlContent; bp.Description = htmlDocument.DocumentNode.InnerText.Replace("\n", "<br/>"); db.BookPages.Add(bp); db.SaveChanges(); } } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.InnerException.Message); } }
public ActionResult Recovery(int?id) { var LibraryId = id; using (VBSContext db = new VBSContext()) { try { Library library = db.Libraries.AsQueryable().FirstOrDefault(x => x.LibraryId == id); if (library != null) { db.Configuration.AutoDetectChangesEnabled = true; db.ChangeTracker.Entries(); library.PageNumber = 0; library.DeletedAt = null; db.SaveChanges(); } TempData.Add("BookRecoverySuccess", "Book was recovery successfully."); } catch (Exception ex) { TempData.Add("BookRecoveryError", "Book was not recovery successfully."); } } return(RedirectToAction("Index", "MyLibrary")); }
public ActionResult Profile(ProfileViewModel model) { if (ModelState.IsValid) { using (VBSContext db = new VBSContext()) { try { User user = db.Users.AsQueryable().FirstOrDefault(c => c.Email == model.Email); user.Name = model.Name; user.Surname = model.Surname; user.UpdatedAt = DateTime.Now; db.SaveChanges(); TempData.Add("UserProfileSuccess", "User profile was update successfully."); } catch (Exception ex) { TempData.Add("UserProfileFail", "User profile was not update successfully."); } return(RedirectToAction("Profile", "Account")); } } return(View()); }
public ActionResult SoftDelete(int?id) { var LibraryId = id; using (VBSContext db = new VBSContext()) { try { Library library = db.Libraries.AsQueryable().FirstOrDefault(x => x.LibraryId == id); if (library != null) { db.Configuration.AutoDetectChangesEnabled = true; db.ChangeTracker.Entries(); library.DeletedAt = System.DateTime.Now; db.SaveChanges(); TempData.Add("BookSoftDeleteSuccess", "Book was deleted successfully."); } } catch (Exception ex) { TempData.Add("BookSoftDeleteError", "Book was not deleted successfully."); } } return(RedirectToAction("Index", "MyLibrary")); }
public ActionResult ResetPassword(ResetPasswordModel model) { var message = ""; if (ModelState.IsValid) { using (VBSContext db = new VBSContext()) { var user = db.Users.AsQueryable().FirstOrDefault(a => a.ResetPasswordCode == model.ResetCode); if (user != null) { user.Password = GVBSHelpers.GVBSHelperClass.CreateMD5Password(model.NewPassword); user.ResetPasswordCode = ""; db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); ViewBag.SuccessMessage = "New password updated successfully."; } } } else { ViewBag.ErrorMessage = "Something invalid."; } return(View(model)); }
public ActionResult ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { using (VBSContext db = new VBSContext()) { var user = db.Users.AsQueryable().FirstOrDefault(u => u.Email == model.Email && u.IsAdmin == false); if (user == null) { ViewBag.UserNotFound = "User didn't find in the system."; } else { string resetCode = Guid.NewGuid().ToString(); GVBSHelpers.GVBSHelperClass.SendVerificationLinkEmail(model.Email, resetCode, "ResetPassword"); user.ResetPasswordCode = resetCode; db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); ViewBag.UserSendEmailSuccess = string.Format("Verification email was send your {0} email address.", model.Email); } return(View(model)); } } return(View()); }
public ActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { using (VBSContext db = new VBSContext()) { User control = db.Users.AsQueryable().FirstOrDefault(c => c.Email == model.Email); // If user is not exists then save the user if (control == null) { var password = GVBSHelpers.GVBSHelperClass.CreateMD5Password(model.Password); User user = new User() { Name = model.Name, Surname = model.Surname, Email = model.Email, Password = password, IsAdmin = false, CreatedAt = DateTime.Now }; db.Users.Add(user); db.SaveChanges(); TempData["UserCreateSuccess"] = string.Format("Dear {0}, welcome to visual bookshelf.", model.Name + " " + model.Surname); string redirectToBack = Session["RedirectToBack"] == null ? "" : Session["RedirectToBack"].ToString(); if (Session["RedirectToBack"] != null) { Session.Remove("RedirectToBack"); return(Redirect(redirectToBack)); } else { return(RedirectToAction("Login", "Account")); } } else { ViewBag.UserExists = string.Format("User ({0}) is already exist in system.", model.Email); model.Name = null; model.Surname = null; model.Email = null; model.Password = null; model.PasswordConfirm = null; return(View(model)); } } } return(View()); }
public ActionResult ReadBook(int?id, int?page) { ReadBookViewModel readBookViewModel = new ReadBookViewModel(); using (VBSContext db = new VBSContext()) { // Library Library library = db.Libraries .Include(s => s.Book) .Include(a => a.Book.Authors) .Include(c => c.Book.Categories) .Include(l => l.Book.Languages) .AsQueryable() .FirstOrDefault(x => x.LibraryId == id); readBookViewModel.LibraryDetail = library; library.PageNumber = Convert.ToInt32(page); db.SaveChanges(); int bookPageCount = db.BookPages.AsQueryable().Where(x => x.BookId == library.BookId).Count(); int pageNumber = 0; int firstIndex = db.BookPages.AsQueryable().Where(x => x.BookId == library.BookId).FirstOrDefault().BookPageId; if (page > bookPageCount) { pageNumber = (Convert.ToInt32(firstIndex) + Convert.ToInt32(bookPageCount)) - 1; } else { pageNumber = (page == 1 ? firstIndex : (Convert.ToInt32(firstIndex) + Convert.ToInt32(page))); } BookPage bookPage = db.BookPages .AsQueryable() .Where(x => x.BookId == library.BookId) .Where(y => y.BookPageId == pageNumber) .FirstOrDefault(); readBookViewModel.BookPages = bookPage; } return(View(readBookViewModel)); }
public ActionResult Delete(int?id) { var LibraryId = id; using (VBSContext db = new VBSContext()) { try { Library library = db.Libraries.AsQueryable().FirstOrDefault(x => x.LibraryId == id); db.Libraries.Remove(library); db.SaveChanges(); TempData.Add("BookDeleteSuccess", "Book was deleted successfully."); } catch (Exception ex) { TempData.Add("BookDeleteError", "Book was not deleted successfully."); } } return(RedirectToAction("Index", "MyLibrary")); }
public ActionResult Create(int BookId, int EbookNo) { var userId = CurrentSession.User.Id; using (VBSContext db = new VBSContext()) { Book getBook = db.Books.AsQueryable().Where(b => b.EbookNo == EbookNo).FirstOrDefault(); var bookControl = db.Libraries.AsQueryable().Where(x => x.BookId == BookId && x.UserId == userId).FirstOrDefault(); if (bookControl == null) { Library newLibrary = new Library() { BookId = BookId, UserId = userId, PageNumber = 0, CreatedAt = System.DateTime.Now, Book = getBook }; List <Author> getAuthors = getBook.Authors.ToList(); List <Category> getCategories = getBook.Categories.ToList(); List <Language> getLanguages = getBook.Languages.ToList(); newLibrary.Book.Authors = getAuthors; newLibrary.Book.Categories = getCategories; newLibrary.Book.Languages = getLanguages; db.Libraries.Add(newLibrary); db.SaveChanges(); return(RedirectToAction("Index", "MyLibrary")); } else { TempData.Add("EbookExistInLibrary", "This book has already exist in your library."); return(RedirectToAction("View", "Ebooks", new { id = EbookNo })); } } }
/*Populates book items*/ public static void AddBooks(VBSContext context) { var isbn = "123456"; var title = "This is the title of book #"; var genres = new List <string>() { "male", "female" }; var synopsis = "This book is the book #"; var value = 20; var books = new List <BookItem>(); var pagination = new PaginationItem(); pagination.Limit = 40; pagination.Offset = 20; pagination.Total = 1000; for (int i = 0; i < 10; i++) { // Select the genre according to current index var index = (i % 2) == 0? 0 : 1; BookItem book = new BookItem() { Isbn = isbn + i, Title = title + i, Genre = genres[index], Synopsis = synopsis + i, Value = (long)value / (i + 1), Pagination = pagination }; context.BookItems.Add(book); } context.SaveChanges(); }
/// <summary> /// Author Thread Method /// </summary> /// <param name="authorResults"></param> private void BookSaveThreadMethod(SearchResult book) { try { HashSet <Author> authors = new HashSet <Author>(); HashSet <Category> categories = new HashSet <Category>(); HashSet <Language> languages = new HashSet <Language>(); // Download Files if (!Directory.Exists(Server.MapPath("~/Files/" + book.Id))) { Directory.CreateDirectory(Server.MapPath("~/Files/" + book.Id)); } string imageUrl = string.Format("http://www.gutenberg.org/files/{0}/{0}-h/images/cover.jpg", book.Id); string epubUrl = string.Format("http://www.gutenberg.org/ebooks/{0}.epub.images", book.Id); string newImageUrl = null; string newEpubUrl = null; // Download Image try { WebClient wcImage = new WebClient(); wcImage.DownloadFile(imageUrl, Server.MapPath("~/Files/" + book.Id + "/" + ("cover_" + book.Id + ".jpg"))); newImageUrl = "/Files/" + book.Id + "/" + ("cover_" + book.Id + ".jpg"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("############# book image error #############" + ex.Message); } // Download Epub try { WebClient wcEpub = new WebClient(); wcEpub.DownloadFile(epubUrl, Server.MapPath("~/Files/" + book.Id + "/" + ("epub_" + book.Id + ".epub"))); newEpubUrl = "/Files/" + book.Id + "/" + ("epub_" + book.Id + ".epub"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("############# book epub error #############" + ex.Message); } // Book Save using (VBSContext db = new VBSContext()) { // Authors foreach (AuthorResult ar in book.Authors) { Author author = db.Authors.AsQueryable().Where(a => a.AuthorName == ar.Name).FirstOrDefault(); if (author == null) { Author newAuthor = new Author() { AuthorName = ar.Name, BirthYear = ar.Birth_year, DeathYear = ar.Death_year, CreatedAt = DateTime.Now }; db.Authors.Add(newAuthor); authors.Add(newAuthor); } else { authors.Add(author); } } // Categories foreach (var c in book.Subjects) { Category category = db.Categories.AsQueryable().Where(mc => mc.CategoryTitle == c).FirstOrDefault(); if (category == null) { Category newCategory = new Category() { CategoryTitle = c, CreatedAt = DateTime.Now }; db.Categories.Add(newCategory); categories.Add(newCategory); } else { categories.Add(category); } } // Languages foreach (var lang in book.Languages) { Language language = db.Languages.AsQueryable().Where(ml => ml.LanguageCode == lang).FirstOrDefault(); if (language == null) { Language newLanguage = new Language() { LanguageTitle = GVBSHelpers.GVBSHelperClass.ConvertLanguage(lang), LanguageCode = lang, CreatedAt = DateTime.Now }; db.Languages.Add(newLanguage); languages.Add(newLanguage); } else { languages.Add(language); } } // new book Book newBook = new Book() { BookTitle = book.Title, EbookNo = book.Id, BookContents = "", FileName = newImageUrl, FileEpub = newEpubUrl, MediaType = book.Media_type, DownloadCount = book.Download_count, Price = 0, CopyrightStatus = book.Copyright, Authors = authors, Categories = categories, Languages = languages, CreatedAt = DateTime.Now }; db.Books.Add(newBook); db.SaveChanges(); // Detail Book getBookDetail = db.Books.AsQueryable().FirstOrDefault(x => x.EbookNo == book.Id); if (getBookDetail != null) { getBookDetail.Attach(new EbookObserver(book.Id, getBookDetail.BookId)); getBookDetail.Notify(); //db.SaveChanges(); } } } catch (DbEntityValidationException ex) { System.Diagnostics.Debug.WriteLine(string.Format("############# book error : {0} #############", ex.Message)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("############# book error : {0} #############", ex.Message)); } }