Exemplo n.º 1
0
        public JsonResult SearchOneBook(Models.book book)
        {
            Models.bookService bookService = new Models.bookService();
            var result = bookService.getOneBookData(book.BOOK_ID);

            return(Json(result));
        }
Exemplo n.º 2
0
 public ActionResult BookListAddSave(string publishid, string name, string type, string price, string author)
 {
     if (name == "" || type == "")
     {
         return(Content("输入格式不对请重新输入"));
     }
     else
     {
         try
         {
             电商.Areas.Admin.Models.Entities4 db = new Models.Entities4();
             电商.Areas.Admin.Models.book      b  = new Models.book();
             b.pulish_id = Convert.ToInt32(publishid);
             b.name      = name;
             b.price     = Convert.ToInt32(price);
             b.type      = type;
             b.author    = author;
             db.book.Add(b);
             db.SaveChanges();
             return(Content("添加成功"));
         }
         catch (System.Data.Entity.Validation.DbEntityValidationException ex)
         {
             var msg    = string.Empty;
             var errors = (from u in ex.EntityValidationErrors select u.ValidationErrors).ToList();
             foreach (var item in errors)
             {
                 msg += item.FirstOrDefault().ErrorMessage;
             }
             return(Content(msg));
         }
     }
 }
Exemplo n.º 3
0
        public JsonResult DeleteBook(Models.book book)
        {
            Models.bookService bookService = new Models.bookService();
            var result = bookService.deleteBook(book.BOOK_ID);

            return(Json(result));
        }
Exemplo n.º 4
0
        public IActionResult Read(string path)
        {
            if (!System.IO.File.Exists(path))
            {
                return(NotFound("The book path was not found."));
            }
            var book            = EpubReader.Library.EpubReader.ReadBook(path);
            var bookFromLibrary = _bookRepository.GetAll().SingleOrDefault(b => b.Path.Equals(path, StringComparison.InvariantCultureIgnoreCase));

            if (bookFromLibrary != null)
            {
                bookFromLibrary.LastOpened = DateTime.Now;
                _bookRepository.Update(bookFromLibrary);
            }
            var bookModel = new Models.book
            {
                Title    = book.Title,
                Author   = book.Author,
                FileName = path
            };
            List <Models.Chapter>       chapters    = new List <Models.Chapter>();
            Func <EpubChapter, Chapter> funcConvert = null;

            funcConvert = new Func <EpubChapter, Chapter>((epChapter) =>
            {
                Chapter chapter = new Chapter {
                    FileName = epChapter.ContentFileName, Title = epChapter.Title, Book = bookModel
                };
                if (epChapter.SubChapters != null && epChapter.SubChapters.Any())
                {
                    foreach (var epSubChapter in epChapter.SubChapters)
                    {
                        chapter.Chapters.Add(funcConvert(epSubChapter));
                    }
                }
                return(chapter);
            });
            foreach (var epChapter in book.Chapters)
            {
                chapters.Add(funcConvert(epChapter));
            }
            bookModel.Chapters = chapters;

            if (HybridSupport.IsElectronActive)
            {
                Electron.IpcMain.On("export-book", async(args) =>
                {
                    var mainWindow = Electron.WindowManager.BrowserWindows.First();
                    var options    = new SaveDialogOptions
                    {
                        Filters = new FileFilter[] {
                            new FileFilter {
                                Extensions = new string[] { "*.txt" }, Name = "Archivos de texto plano(*.txt)"
                            }
                        },
                        Title = "Exportar libro a texto plano"
                    };

                    string file = await Electron.Dialog.ShowSaveDialogAsync(mainWindow, options);
                    if (!String.IsNullOrWhiteSpace(file))
                    {
                        try
                        {
                            var bookToExport = EpubReader.Library.EpubReader.ReadBook(path);
                            var regex        = new Regex(@"<[^>]*>", RegexOptions.IgnoreCase);
                            List <EpubChapter> allChapters = bookToExport.GetAllChapters();
                            string wholeBook = String.Join(Environment.NewLine, allChapters.Select(ch =>
                            {
                                return(regex.Replace(ch.HtmlContent, String.Empty));
                            }).ToArray());
                            System.IO.File.WriteAllText(file, wholeBook, Encoding.UTF8);

                            Electron.IpcMain.Send(mainWindow, "export-book-reply", true);
                        }
                        catch (Exception ex)
                        {
                            Electron.IpcMain.Send(mainWindow, "export-file-reply", ex.Message);
                        }
                    }
                });
            }

            return(View(bookModel));
        }
Exemplo n.º 5
0
        public static BookStoreAdmin.ViewModels.Book EditBook(BookStoreAdmin.ViewModels.BookRequest objBookRequest)
        {
            BookStoreAdmin.Models.book book = new Models.book();
            List <int> intAuthorids         = new List <int>();

            BookStoreAdmin.ViewModels.Book objBook = new ViewModels.Book();

            using (BookStoreAdmin.Models.BookStoreAdminEntities1 context = new BookStoreAdminEntities1())
            {
                book = context.books.Include("authors").Single(b => b.id == objBookRequest.id);

                foreach (var author in book.authors.ToList())
                {
                    if (!objBookRequest.authors.Contains(author.id))
                    {
                        book.authors.Remove(author);
                    }
                }

                foreach (var newAuthorId in objBookRequest.authors)
                {
                    // Add the roles which are not in the list of user's roles
                    if (!book.authors.Any(r => r.id == newAuthorId))
                    {
                        var newAuthor = new author {
                            id = newAuthorId
                        };
                        context.authors.Attach(newAuthor);
                        book.authors.Add(newAuthor);
                    }
                }

                book.title          = objBookRequest.title;
                book.description    = objBookRequest.description;
                book.price          = objBookRequest.price;
                book.fk_category_id = objBookRequest.category;
                context.SaveChanges();
            }


            using (BookStoreAdmin.Models.BookStoreAdminEntities1 context = new BookStoreAdminEntities1())
            {
                objBook = context.books
                          .Where(b => b.id == book.id)
                          .Select(book1 => new BookStoreAdmin.ViewModels.Book()
                {
                    id          = book1.id,
                    title       = book1.title,
                    description = book1.description,
                    category    = new ViewModels.Category()
                    {
                        id = book1.category.id, description = book1.category.description, name = book1.category.name
                    },
                    authors = book1.authors.Select((author) => new BookStoreAdmin.ViewModels.Author()
                    {
                        id          = author.id,
                        description = author.description,
                        first_name  = author.first_name,
                        last_name   = author.last_name
                    }).ToList(),
                    price = book1.price
                }).Single();
            }

            return(objBook);
        }