public async Task LoadBook(BookInfo info) { await _loadingPopup.Show(); _bookshelfBook = info; _bookshelfBook.LastRead = DateTime.Now; _bookshelfBook.ReadStats.OpenedBook(); var loader = EbookFormatHelper.GetBookLoader(info.Format); _ebook = await loader.OpenBook(info); var position = _bookshelfBook.Position; Title = _ebook.Title + " - " + _ebook.Author; var chapter = _ebook.HtmlFiles.First(); var positionInChapter = 0; if (position != null) { var loadedChapter = _ebook.HtmlFiles[position.Spine]; if (loadedChapter != null) { chapter = loadedChapter; positionInChapter = position.SpinePosition; } } SendChapter(chapter, positionInChapter); _chapterListPopup.SetBook(_ebook, _bookshelfBook); }
public virtual async Task <Ebook> OpenBook(string path) { var folder = await FileSystem.Current.LocalStorage.GetFolderAsync(path); var titleFile = await folder.GetFileAsync(TitlePath); var title = await titleFile.ReadAllTextAsync(); var epub = new Ebook() { Title = title, Spines = new List <Spine>() { new Spine { Idref = "content" } }, Files = new List <Model.Format.File>() { new Model.Format.File { Id = "content", Href = ContentPath } }, Folder = path, Navigation = new List <Model.Navigation.Item>(), }; return(epub); }
public EbookDTO Create(IndexUnit unit) { _indexManager.Index(unit); var keywords = string.Empty; foreach (var item in unit.Keywords) { keywords += item + " "; } keywords = keywords.Trim(); var language = _languageManager.GetByName(unit.Language); var ebook = new Ebook() { Author = unit.Author, CategoryId = unit.Category, Filename = unit.Filename, Keywords = keywords, MIME = "application/pdf", PublicationYear = int.Parse(unit.FileDate), Title = unit.Title, UserId = 1, LanguageId = language.LanguageId }; int newEbookId = 0; newEbookId = _ebookProvider.Create(ebook); return(ConverterExtension.ToDTO(_ebookProvider.GetById(newEbookId))); }
public int Create(Ebook ebook) { int newEbookId = 0; using (var sqlConnection = new MySqlConnection(_connectionString)) { string query = String.Format("INSERT INTO {0}" + "(Title,Author,Keywords,PublicationYear,Filename,MIME,UserId,CategoryId,LanguageId)" + "VALUES(@Title,@Author,@Keywords,@PublicationYear,@Filename,@MIME,@UserId,@CategoryId,@LanguageId); Select LAST_INSERT_ID();", _tableName); sqlConnection.Open(); using (MySqlCommand sqlCommand = new MySqlCommand(query, sqlConnection)) { sqlCommand.Parameters.AddWithValue("Title", ebook.Title); sqlCommand.Parameters.AddWithValue("Author", ebook.Author); sqlCommand.Parameters.AddWithValue("Keywords", ebook.Keywords); sqlCommand.Parameters.AddWithValue("PublicationYear", ebook.PublicationYear); sqlCommand.Parameters.AddWithValue("Filename", ebook.Filename); sqlCommand.Parameters.AddWithValue("MIME", ebook.MIME); sqlCommand.Parameters.AddWithValue("UserId", ebook.UserId); sqlCommand.Parameters.AddWithValue("CategoryId", ebook.CategoryId); sqlCommand.Parameters.AddWithValue("LanguageId", ebook.LanguageId); newEbookId = int.Parse(sqlCommand.ExecuteScalar().ToString()); } } return(newEbookId); }
public IEnumerable <Ebook> GetAll() { List <Ebook> ebooks = new List <Ebook>(); using (MySqlConnection sqlConnection = new MySqlConnection(_connectionString)) { string query = String.Format("SELECT * FROM {0};", _tableName); sqlConnection.Open(); using (MySqlCommand sqlCommand = new MySqlCommand(query, sqlConnection)) { using (MySqlDataReader reader = sqlCommand.ExecuteReader()) { if (reader.HasRows) { Ebook ebook = null; while (reader.Read()) { ebook = MapTableEnityToObject(reader); ebooks.Add(ebook); } } } } } return(ebooks); }
public Ebook GetById(int id) { Ebook ebook = new Ebook(); using (var sqlConnection = new MySqlConnection(_connectionString)) { string query = String.Format("SELECT * FROM {0} WHERE EbookId = @Id;", _tableName); sqlConnection.Open(); using (MySqlCommand sqlCommand = new MySqlCommand(query, sqlConnection)) { sqlCommand.Parameters.AddWithValue("Id", id); using (MySqlDataReader reader = sqlCommand.ExecuteReader()) { if (reader.HasRows) { if (reader.Read()) { ebook = MapTableEnityToObject(reader); } } } } } return(ebook); }
public void addEbook(Ebook ebookP) { ebooks ebook = new ebooks(); ebook.Title = ebookP.Title; ebook.Author = ebookP.Author; ebook.Format = (int)ebookP.Format; context.ebooks.Local.Add(ebook); try { context.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } GetEbooks(); }
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 async Task <IActionResult> Edit(int EbookID, [Bind("EbookID,Path,PathFileID,Name,Version,FkProductID")] Ebook ebook) { if (EbookID != ebook.EbookID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ebook); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EbookExists(ebook.EbookID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(ebook)); }
public async void LoadBook(Book book) { _bookshelfBook = book; _ebook = await EbookFormatHelper.GetBookLoader(book.Format).OpenBook(book.Path); var position = _bookshelfBook.Position; QuickPanel.PanelContent.SetNavigation(_ebook.Navigation); this.RefreshBookmarks(); var chapter = _ebook.Spines.First(); var positionInChapter = 0; if (position != null) { var loadedChapter = _ebook.Spines.ElementAt(position.Spine); if (loadedChapter != null) { chapter = loadedChapter; positionInChapter = position.SpinePosition; } } this.SendChapter(chapter, position: positionInChapter); }
public void EbookInsert(string name, int authorId, string description, int publisherId, string isbn, int year, int pages, int languageId, decimal size, int formatId, string path, int typeId, string url, string urlDownload) { Ebook obj; bool insert = true; try { obj = db.Ebooks.Where(v => v.Name == name).First(); insert = false; } catch (Exception) { obj = new Ebook(); insert = true; } obj.Name = name; obj.AuthorId = authorId; obj.Description = description; obj.PublisherId = publisherId; obj.ISBN = isbn; obj.Year = year; obj.Pages = pages; obj.LanguageId = languageId; obj.Size = size; obj.FormatId = formatId; obj.Path = path; obj.TypeId = typeId; obj.Url = url; obj.UrlDownload = urlDownload; if (insert) { db.Ebooks.InsertOnSubmit(obj); } db.SubmitChanges(); }
public void EbookInsert(Ebook sourceObj) { Ebook obj; bool insert = true; try { obj = db.Ebooks.Where(v => v.Name == sourceObj.Name).First(); insert = false; } catch (Exception) { obj = new Ebook(); insert = true; } obj.Name = sourceObj.Name; obj.AuthorId = sourceObj.AuthorId; obj.Description = sourceObj.Description; obj.PublisherId = sourceObj.PublisherId; obj.ISBN = sourceObj.ISBN; obj.Year = sourceObj.Year; obj.Pages = sourceObj.Pages; obj.LanguageId = sourceObj.LanguageId; obj.Size = sourceObj.Size; obj.FormatId = sourceObj.FormatId; obj.Path = sourceObj.Path; obj.TypeId = sourceObj.TypeId; obj.Url = sourceObj.Url; obj.UrlDownload = sourceObj.UrlDownload; if (insert) { db.Ebooks.InsertOnSubmit(obj); } db.SubmitChanges(); }
public void EbookDelete(int iId) { Ebook obj = db.Ebooks.Where(v => v.Id == iId).First(); db.Ebooks.DeleteOnSubmit(obj); db.SubmitChanges(); }
public HttpResponseMessage Add(HttpRequestMessage request, EbookViewModel entityVM) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { Ebook newEntity = new Ebook(); newEntity.UpdateEbook(entityVM); ebookService.Create(newEntity); ebookService.Save(); // Update view model entityVM = Mapper.Map <Ebook, EbookViewModel>(newEntity); response = request.CreateResponse <EbookViewModel>(HttpStatusCode.Created, entityVM); } return response; })); }
public virtual Book CreateBookshelfBook(Ebook book) { return(new Book { Title = book.Title, Format = EbookFormat, Path = book.Folder, }); }
public void Add(Ebook ebook) { using (var db = new LiteDatabase(Properties.EbookLibrary.Default.ConnectionString)) { var ebooks = db.GetCollection <Ebook>("ebooks"); ebooks.Insert(ebook); } }
public BookInfoPopup(Ebook book) { Book = book; BindingContext = this; InitializeComponent(); DisplayInfo(); }
//Sprawdza czy ebook jest danej kategorii private bool DoesEbookContainCategory(Ebook e, Genre category) { foreach (EbookGenre ebookCategories in e.EbookGenres) { return(ebookCategories.Genre == category); } return(false); }
public void AddEBook(EbookInputModel book) { if (!CheckIsbn(book.Isbns)) { CheckAuthor(book.Authors); var ebook = new Ebook { Price = book.Price, Name = book.Name, Image = book.Image, Description = book.Description, Size = book.Size, ReleaseDate = book.ReleaseDate, Publisher = book.Publisher, Isbn = book.Isbns }; ebook.BookAgeGroups = new List <BookAgeGroup>(); foreach (var ageGroup in book.AgeGroups) { ebook.BookAgeGroups.Add(new BookAgeGroup { Book = ebook, AgeGroup = ageGroup }); } ; ebook.BookAuthors = new List <BookAuthor>(); foreach (var author in book.Authors) { ebook.BookAuthors.Add(new BookAuthor { Book = ebook, Author = author }); } ; ebook.BookGenres = new List <BookGenre>(); foreach (var genre in book.Genres) { ebook.BookGenres.Add(new BookGenre { Book = ebook, Genre = genre }); } ; ebook.BookLanguages = new List <BookLanguage>(); foreach (var language in book.Languages) { ebook.BookLanguages.Add(new BookLanguage { Book = ebook, Language = language }); } ; _db.Ebooks.AddRange(ebook); _db.SaveChanges(); } }
//Sprawdza czy dany autor jest autorem danego ebooka private bool DoesEbookContainAuthor(Ebook e, Author author) { foreach (AuthorEbooks ebookCategories in e.AuthorEbooks) { return(ebookCategories.Author == author); } return(false); }
//Sprawdza czy dana fraza zawiera się w nazwie kategorii ebooka private bool DoesEbookContainCategory(Ebook e, string category) { foreach (EbookCategories ebookCategories in e.EbookCategories) { return(ebookCategories.Category.CategoryName.Contains(category)); } return(false); }
//Sprawdza czy dana fraza zawiera się w imieniu bądź nazwisku autora private bool DoesEbookContainAuthor(Ebook e, string author) { foreach (AuthorEbooks ebookCategories in e.AuthorEbooks) { return(ebookCategories.Author.FirstName.Contains(author) || ebookCategories.Author.LastName.Contains(author)); } return(false); }
//Sprawdza czy ebook jest danej kategorii private bool DoesEbookContainCategory(Ebook e, Category category) { foreach (EbookCategories ebookCategories in e.EbookCategories) { return(ebookCategories.Category == category); } return(false); }
public EbookViewModel(Ebook ebook) { _ebook = ebook; Title = ebook.Title; Isbn = ebook.Isbn; IsPinnable = !EbookTile.Exists(_ebook.Isbn); Download = new RelayCommand(async() => { IsDownloadable = false; IsDownloading = true; Messenger.Default.Register <DownloadStatusMessage>(this, _ebook.Isbn, msg => { DownloadStatus = $"{msg.Done} av {msg.Total} sidor nerladdade"; }); await EbookManager.DownloadEbookAsync(_ebook); IsDownloading = false; IsDownloaded = true; IsPinnable = await Task.Run(() => !EbookTile.Exists(_ebook.Isbn)); FrontPagePath = await PageStorage.GetPagePathAsync(_ebook, 1); _ = _watchForDirectoryRemoval(); }); Pin = new RelayCommand(async() => { IsPinnable = !(await EbookTile.RequestCreateAsync(_ebook)); }); _ = Task.Run(async() => { if (!await PageStorage.EbookExistsAsync(_ebook)) { if (NetworkInformation.GetInternetConnectionProfile() != null) { _ = UIThread.RunAsync(() => IsDownloadable = true); } } else { _ = UIThread.RunAsync(() => IsDownloaded = true); try { _ = UIThread.RunAsync(async() => FrontPagePath = await PageStorage.GetPagePathAsync(_ebook, 1)); } catch { } _ = _watchForDirectoryRemoval(); } }); }
//---------------------------------------------------------- ebooks public IActionResult AddEbook() { if (HttpContext.Session.GetString("auth") != "true") { return(RedirectToAction("Index", "Login")); } ViewBag.Current = ""; Ebook ebook = new Ebook(); return(View(ebook)); }
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 <IActionResult> Create([Bind("EbookID,Path,PathFileID,Name,Version,FkProductID")] Ebook ebook) { if (ModelState.IsValid) { _context.Add(ebook); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(ebook)); }
public virtual async Task <string> PrepareHtml(string html, Ebook book, EbookChapter chapter) { return(await Task.Run(() => { var doc = new HtmlDocument(); doc.LoadHtml(html); HtmlHelper.StripHtmlTags(doc, new[] { "script", "style", "iframe" }); return HtmlHelper.GetBody(doc).InnerHtml; })); }
public JsonResult UpdateEbook(Ebook ebookObj) { try { _ebookService.Update(ebookObj); return(Json(new { success = true, message = "Sửa thành công", idbook = ebookObj.BookID }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = ex.ToString(), idbook = ebookObj.BookID }, JsonRequestBehavior.AllowGet)); } }
public IActionResult DeleteEbook(int id) { if (HttpContext.Session.GetString("auth") != "true") { return(RedirectToAction("Index", "Login")); } ViewBag.Current = ""; Ebook ebook = new Ebook(); ebook = bookManager.getEbook(id); return(View(ebook)); }
public string SaveEbook(Ebook ebook) { try { db_command = SYSTEM_DB.GetStoredProcCommand("SaveEbook", ebook.EbookId, ebook.AppUserId, ebook.Title, ebook.Author, ebook.FilePath); DataTable dt=SYSTEM_DB.ExecuteDataSet(db_command).Tables[0]; return dt.Rows[0][0].ToString(); } catch (Exception e) { throw; } }
protected void Page_Load(object sender, EventArgs e) { if (Session.IsNewSession) { string redirectURL = "/Default.aspx"; Response.Redirect(redirectURL); } else { string EbookName = Request.QueryString["EbookName"]; if (EbookName != null) { List<Ebook> allEbooks = (List<Ebook>)Session["AllUploadesEbooks"]; this.selectedEbook = allEbooks.Find(Ebook => Ebook.Title == EbookName); DisplayEbookContent(); ((HtmlAnchor)Master.FindControl("TitleLbl")).InnerText = selectedEbook.Title; } else { string redirectURL = "/Default.aspx"; Response.Redirect(redirectURL); } } }
public static List<Ebook> GetAll() { List<Ebook> allEbooks = new List<Ebook>(); DatabaseHandler dh = new DatabaseHandler(); DataTable dt = dh.GetAllEbooks(); foreach (DataRow dr in dt.Rows) { string filePath = dr["EbookFilePath"].ToString(); Ebook ebook = new Ebook(filePath); ebook.AppUserId = dr["AppUserId"].ToString(); ebook.EbookId = dr["EbookId"].ToString(); allEbooks.Add(ebook); } return allEbooks; }