Exemplo n.º 1
0
        public ActionResult CreateBook(BOOK bk)
        {
            BOOKS bks = new BOOKS();

            bks.createBook(bk);
            return(View());
        }
Exemplo n.º 2
0
        private void BtnAddedBook_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                Logger.Info("Getting started: BtnAddedBook_OnClick");

                BOOK book = GetWindowFields();

                ThreadPool.QueueUserWorkItem(obj =>
                {
                    Manager.Entity = book;

                    Manager.AddNewRow();

                    if (Manager.IsOk)
                    {
                        this.GuiSync(Close);
                    }
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 3
0
        public IHttpActionResult PutBOOK(long id, BOOK bOOK)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bOOK.ID)
            {
                return(BadRequest());
            }

            db.Entry(bOOK).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BOOKExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 4
0
        public void Update(BOOK bookObj)
        {
            using (var db = new LibDb())
            {
                var b = db.BOOKs.Include(x => x.AUTHORs).ToList().Find(d => d.ISBN ==
                                                                       bookObj.ISBN);
                b.AUTHORs.Clear();

                db.SaveChanges();
            }

            var newAuthors = bookObj.AUTHORs;

            bookObj.AUTHORs = new List <AUTHOR>();

            using (var db = new LibDb())
            {
                db.BOOKs.Attach(bookObj);
                db.Entry(bookObj).State = EntityState.Modified;

                foreach (var author in newAuthors)
                {
                    db.AUTHORs.Attach(author);
                    bookObj.AUTHORs.Add(author);
                }
                db.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public IHttpActionResult PutBOOK(long id, [FromBody] BOOK bOOK)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
                //return Json(new { success = false,  errors = ModelState.Values.Where(i => i.Errors.Count > 0) });
            }

            if (id != bOOK.ID)
            {
                return(BadRequest());
            }

            db.Entry(bOOK).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BOOKExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 6
0
 public void Delete(BOOK bookObj)
 {
     using (var db = new LibDb())
     {
         using (DbContextTransaction transaction = db.Database.BeginTransaction())
         {
             db.BOOKs.Attach(bookObj);
             foreach (var au in bookObj.AUTHORs)
             {
                 db.AUTHORs.Attach(au);
             }
             try
             {
                 bookObj.AUTHORs.Clear();
                 db.BOOKs.Remove(bookObj);
                 db.SaveChanges();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
             }
         }
     }
 }
Exemplo n.º 7
0
        public void Delete(BOOK bookObj)
        {
            using (var db = new LibraryDBEntities1())
            {
                using (DbContextTransaction transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        _bookObj = db.BOOKs.Find(bookObj.ISBN);

                        foreach (var item in _bookObj.AUTHORs.ToList())
                        {
                            _bookObj.AUTHORs.Remove(item);
                        }
                        db.BOOKs.Remove(_bookObj);
                        Shared.save(db);
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                    }
                }
            }
        }
        public void DeleteBook(int?bookid)
        {
            BOOK book = dataAccess.BOOKs.Single(b => b.BOOKID == bookid);

            dataAccess.BOOKs.DeleteOnSubmit(book);
            dataAccess.SaveChanges();
        }
Exemplo n.º 9
0
        public ActionResult Insert(BOOK entity)
        {
            var dao = new BookDAO();

            dao.handleInsert(entity);
            return(RedirectToAction("Management"));
        }
Exemplo n.º 10
0
        public void TestBook()
        {
            using (LibraryDb db = LibraryDb.GetDbContext())
            {
                var books = BooksBl.GetBooks();

                //add book test
                BOOK book = new BOOK {
                    ISBN = "test", COUNT = 0, NAME = "test", PRICE = 0
                };
                BooksBl.AddNewCard(book);
                BOOK dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                Assert.IsNotNull(dbBook);

                //Change book test
                dbBook.DESCRIPTION = someText;
                BooksBl.UpdateBook(dbBook);
                dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                Assert.AreEqual(true, dbBook?.DESCRIPTION == someText);

                //deleted test book
                BooksBl.BooksRemove(new[] { book.ID });
                dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                Assert.IsNull(dbBook);
            }
        }
Exemplo n.º 11
0
        public void Update(BOOK bookObj)
        {
            using (var db = new swagbaseEntities1())
            {
                BOOK dummyBook = db.BOOKs.Include("AUTHORs").FirstOrDefault(a => a.ISBN == bookObj.ISBN);
                db.BOOKs.Attach(dummyBook);
                db.CLASSIFICATIONs.Attach(db.CLASSIFICATIONs.Find(bookObj.SignId));

                dummyBook.pages           = bookObj.pages;
                dummyBook.Title           = bookObj.Title;
                dummyBook.publicationinfo = bookObj.publicationinfo;
                dummyBook.PublicationYear = bookObj.PublicationYear;
                dummyBook.ISBN            = bookObj.ISBN;

                dummyBook.AUTHORs.Clear();
                List <int> authorsToDummy = bookObj.AUTHORs.Select(a => a.Aid).ToList();



                foreach (int auth in authorsToDummy)
                {
                    db.AUTHORs.Attach(db.AUTHORs.Find(auth));
                    dummyBook.AUTHORs.Add(db.AUTHORs.Find(auth));
                }
                dummyBook.pages           = bookObj.pages;
                dummyBook.Title           = bookObj.Title;
                dummyBook.publicationinfo = bookObj.publicationinfo;
                dummyBook.PublicationYear = bookObj.PublicationYear;
                dummyBook.SignId          = bookObj.SignId;
                //dummyBook.CLASSIFICATION = bookObj.CLASSIFICATION;

                db.SaveChanges();
            }
        }
Exemplo n.º 12
0
        public static void UpdateBook(BOOK book, LibraryDb dbContext = null)
        {
            using (LibraryDb db = LibraryDb.GetDbContext(dbContext))
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    if (book == null)
                    {
                        throw new ArgumentNullException($"book: {nameof(book)}");
                    }

                    BOOK dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                    if (dbBook == null)
                    {
                        throw new Exception($"Книга с {book.ID} не найдена!");
                    }

                    dbBook.ISBN        = book.ISBN;
                    dbBook.NAME        = book.NAME;
                    dbBook.AUTHOR      = book.AUTHOR;
                    dbBook.PUBLISHING  = book.PUBLISHING;
                    dbBook.COUNT       = book.COUNT;
                    dbBook.STATUS      = book.STATUS;
                    dbBook.PRICE       = book.PRICE;
                    dbBook.DESCRIPTION = book.DESCRIPTION;

                    db.SaveChanges();
                    transaction.Complete();
                }
            }
        }
Exemplo n.º 13
0
        public void WithBookTest()
        {
            using (LibraryDb db = LibraryDb.GetDbContext())
            {
                BOOK book = new BOOK {
                    ISBN = "test", COUNT = 0, NAME = "test", PRICE = 0
                };

                using (DbManager <BOOK> manager = new DbManager <BOOK>(new ManagerBook(), book))
                {
                    manager.AddNewRow();
                    BOOK dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                    Assert.IsNotNull(dbBook);

                    //Change book test
                    dbBook.DESCRIPTION = someText;
                    manager.Entity     = dbBook;
                    manager.UpdateRow();
                    dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                    Assert.AreEqual(true, dbBook?.DESCRIPTION == someText);

                    //deleted test book
                    manager.RemoveRow();
                    dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                    Assert.IsNull(dbBook);
                }
            }
        }
Exemplo n.º 14
0
 public BOOK EditBook(BOOK eBook)
 {
     using (DbLibrary db = new DbLibrary())
     {
         db.Configuration.LazyLoadingEnabled = false;
         BOOK book = db.BOOKs.Include(b => b.AUTHORs).FirstOrDefault(x => x.ISBN.Equals(eBook.ISBN));
         book.AUTHORs.Clear();
         db.SaveChanges();
     }
     using (DbLibrary db = new DbLibrary())
     {
         db.Configuration.LazyLoadingEnabled = false;
         BOOK book = db.BOOKs.Include(b => b.CLASSIFICATION).FirstOrDefault(x => x.ISBN.Equals(eBook.ISBN));
         db.Entry(book).CurrentValues.SetValues(eBook);
         db.ChangeTracker.Entries <CLASSIFICATION>().ToList().ForEach(a => a.State = EntityState.Unchanged);
         book.AUTHORs = new List <AUTHOR>();
         foreach (var author in eBook.AUTHORs)
         {
             db.AUTHORs.Attach(author);
             book.AUTHORs.Add(author);
         }
         db.SaveChanges();
         return(book);
     }
 }
Exemplo n.º 15
0
        public void GetBestBooks()
        {
            int quantity = db.BOOK.Count();
            //The number of people for each score level
            int num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0;
            //Use dictionary to save the average score of each book
            Dictionary <int, float> scores        = new Dictionary <int, float>();

            for (int i = 1; i <= quantity; i++)
            {
                num1 = db.Database.SqlQuery <int>("select count(*) from COMMENTS where SCORE=1 and BOOK_ID=" + i.ToString()).FirstOrDefault();
                num2 = db.Database.SqlQuery <int>("select count(*) from COMMENTS where SCORE=2 and BOOK_ID=" + i.ToString()).FirstOrDefault();
                num3 = db.Database.SqlQuery <int>("select count(*) from COMMENTS where SCORE=3 and BOOK_ID=" + i.ToString()).FirstOrDefault();
                num4 = db.Database.SqlQuery <int>("select count(*) from COMMENTS where SCORE=4 and BOOK_ID=" + i.ToString()).FirstOrDefault();
                num5 = db.Database.SqlQuery <int>("select count(*) from COMMENTS where SCORE=5 and BOOK_ID=" + i.ToString()).FirstOrDefault();
                float total_score  = num1 * 1 + num2 * 2 + num3 * 3 + num4 * 4 + num5 * 5;
                float total_people = num1 + num2 + num3 + num4 + num5;
                float average      = total_score / total_people;
                scores[i] = average;
            }

            //Sort the dictionary by value
            Dictionary <int, float> sorted_scores = scores.OrderByDescending(o => o.Value).ToDictionary(p => p.Key, o => o.Value);
            List <int> index = new List <int>(sorted_scores.Keys);

            BOOK[] best_Books = new BOOK[5];

            for (int i = 0; i < 5; i++)
            {
                best_Books[i] = db.BOOK.Find(index[i]);
            }

            //Use ViewBag to transfer the data
            ViewBag.bBooks = best_Books;
        }
Exemplo n.º 16
0
 public static void addNewBook(BOOK book)
 {
     using (var dtbEntity = new QLTVEntities1())
     {
         dtbEntity.BOOKS.Add(book);
         dtbEntity.SaveChanges();
     }
 }
Exemplo n.º 17
0
        public void testBOK()
        {
            BOOKS bks = new BOOKS();
            BOOK  bk  = new BOOK();

            bk.NAME = "ali";
            bks.createBook(bk);
        }
Exemplo n.º 18
0
        public ActionResult DeleteConfirmed(long id)
        {
            BOOK bOOK = db.BOOKs.Find(id);

            db.BOOKs.Remove(bOOK);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 19
0
        // GET: BOOKTAGs/TAG[功能点20:按名称查书籍标签表]
        public ActionResult SearchName(string bname)
        {
            BOOK temp = db.BOOK.Find(bname);
            IQueryable <BOOKTAG> Que  = from q in db.BOOKTAG where q.BOOKID == temp.BOOKID select q;
            List <BOOKTAG>       list = Que.ToList();

            return(View(list));
        }
Exemplo n.º 20
0
        public void Post(BOOK book)
        {
            book.state    = true;
            book.url      = "";
            book.isRemove = false;

            _context.BOOKS.Add(book);
        }
Exemplo n.º 21
0
 public IEnumerable <BOOK> getBook()
 {
     using (EntitiDBContext db = new EntitiDBContext())
     {
         BOOK sch = new BOOK();
         return(db.BOOKS.OrderBy(x => x.NAME).ToList());
     }
 }
Exemplo n.º 22
0
        public ActionResult AddBook(BOOK book, List <int> Authors, List <int> Categories,
                                    List <HttpPostedFileBase> bookImages, List <HttpPostedFileBase> bookSoftCopy)
        {
            try
            {
                book.CREATED_DATE = DateTime.Now;
                book = BookModel.AddBook(book);

                foreach (int aID in Authors)
                {
                    BOOK_AUTHOR bookAuthor = new BOOK_AUTHOR();
                    bookAuthor.BOOKID   = book.BOOKID;
                    bookAuthor.AUTHORID = aID;
                    AuthorModel.AddBookAuthor(bookAuthor);
                }

                foreach (int bCID in Categories)
                {
                    BOOK_CATEGORY bookCat = new BOOK_CATEGORY();
                    bookCat.BOOKID     = book.BOOKID;
                    bookCat.CATEGORYID = bCID;
                    CategoryModel.AddBookCategory(bookCat);
                }

                foreach (HttpPostedFileBase image in bookImages)
                {
                    String     fname     = Generator.RandomString(10) + "." + image.FileName.Split('.')[image.FileName.Split('.').Length - 1];
                    string     path      = Server.MapPath("~/UserImages/") + fname;
                    BOOK_IMAGE bookImage = new BOOK_IMAGE();
                    bookImage.BOOKID    = book.BOOKID;
                    bookImage.IMAGEPATH = "/UserImages/" + fname;
                    image.SaveAs(path);
                    BookModel.AddBookImage(bookImage);
                }
                if (bookSoftCopy != null)
                {
                    foreach (HttpPostedFileBase bookSC in bookSoftCopy)
                    {
                        String        fname = Generator.RandomString(10) + "." + bookSC.FileName.Split('.')[bookSC.FileName.Split('.').Length - 1];
                        string        path  = Server.MapPath("~/UserImages/") + fname;
                        BOOK_SOFTCOPY bSC   = new BOOK_SOFTCOPY();
                        bSC.BOOKID   = book.BOOKID;
                        bSC.FILEPATH = "/UserImages/" + fname;
                        bSC.FILESIZE = bookSC.ContentLength;
                        bookSC.SaveAs(path);
                        BookModel.AddBookSoftCopy(bSC);
                    }
                }
                ViewBag.Message = SuccessMessage.BOOK_ADDED;
            }
            catch (Exception e)
            {
                ViewBag.Message = e.Message;
            }

            initialiseViewBag();
            return(View(book));
        }
Exemplo n.º 23
0
        public ActionResult ByPublisherDisplay(OptionSelected model)
        {
            string optionSelected;

            if (model.optionSelected != null)
            {
                optionSelected = model.optionSelected;
            }
            else
            {
                optionSelected = "";
            }

            var allBooks = db.BOOKs.ToList();

            List <BOOK> booksToDisplay = new List <BOOK>();

            foreach (var book in allBooks)
            {
                BOOK myBook = new BOOK();

                if (model.optionSelected == book.PUBLISHER_CODE)
                {
                    myBook.BOOK_CODE = book.BOOK_CODE;
                    myBook.PAPERBACK = book.PAPERBACK;
                    myBook.PRICE     = book.PRICE;
                    myBook.TYPE      = book.TYPE;
                    myBook.TITLE     = book.TITLE;
                }

                booksToDisplay.Add(myBook);
            }

            // #5 LINQ Statement
            var data    = from p in db.PUBLISHERs select new { p.PUBLISHER_CODE, p.PUBLISHER_NAME };
            int size    = 0;
            int counter = 0;

            foreach (var publisher in data)
            {
                size++;
            }

            string[] publisherNames = new string[size];
            string[] publisherCodes = new string[size];

            foreach (var publisher in data)
            {
                publisherNames[counter] = publisher.PUBLISHER_NAME;
                publisherCodes[counter] = publisher.PUBLISHER_CODE;
                counter++;
            }

            ViewBag.publisherNames = publisherNames;
            ViewBag.publisherCodes = publisherCodes;
            ViewBag.booksToDisplay = booksToDisplay;
            return(View());
        }
Exemplo n.º 24
0
 public bool createBook(BOOK book)
 {
     using (EntitiDBContext db = new EntitiDBContext())
     {
         db.BOOKS.Add(book);
         db.SaveChanges();
         return(true);
     }
 }
Exemplo n.º 25
0
 public static void addNewBook(BOOK book)
 {
     using (var dtbEntity = new QLTVEntities1())
     {
         dtbEntity.BOOKS.Add(book);
         dtbEntity.SaveChanges();
         MessageBox.Show("Add successfully!");
     }
 }
Exemplo n.º 26
0
 public void Update(BOOK bookObj)
 {
     using (var db = new LibraryDBEntities1())
     {
         db.BOOKs.Attach(bookObj);
         db.Entry(bookObj).State = EntityState.Modified;
         Shared.save(db);
     }
 }
Exemplo n.º 27
0
 public void Update(BOOK bookObj)
 {
     using (var db = new Libdb())
     {
         db.BOOK.Attach(bookObj);
         db.Entry(bookObj).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Exemplo n.º 28
0
 // Begin action commands
 private void registerCommand()
 {
     DeleteCommand = new RelayCommand <BOOK>(u => u != null, u => { Model.Books.handleDelete(u.ID); Refresh(); });
     AddCommand    = new RelayCommand <BOOK>(null, u => { Model.Books.handleInsert(u); Refresh(); });
     UpdateCommand = new RelayCommand <BOOK>(u => u != null, u => { Model.Books.handleUpdate(u); Refresh(); });
     EmptyCommand  = new RelayCommand <BOOK>(u => u != null, u => { SelectedBook = new BOOK(); });
     SetPicCommand = new RelayCommand <BOOK>(null, u => { this._setPic(); });
     SearchCommand = new RelayCommand <USER>(null, u => { this.sortByName(); });
 }
Exemplo n.º 29
0
 public void Delete(BOOK bookObj)
 {
     using (var db = new swagbaseEntities1())
     {
         BOOK bISBN = db.BOOKs.Find(bookObj.ISBN);
         db.BOOKs.Remove(bISBN);
         db.SaveChanges();
     }
 }
Exemplo n.º 30
0
        public ActionResult Create([Bind(Include = "BOOKNAME,PRICEPERCHAPTER")] BOOK book)
        {
            var value = Request.Form[3];

            if (ModelState.IsValid)
            {
                //bookID:查book表
                var que    = db.BOOK.Count();
                var bookID = (que + 1).ToString();
                for (int i = 0; i < 8 - bookID.Length; i++)
                {
                    bookID = '0' + bookID;
                }
                book.BOOKID = bookID;
                //writerID:当前
                string userid = Request.Cookies["_userid"].Value;
                //starttime,updateTime:当前时间
                book.STARTTIME  = DateTime.Now.ToString("yyyy-MM-dd");
                book.UPDATETIME = DateTime.Now.ToString("yyyy-MM-dd");
                //downloadnum,collcectnum:0
                book.DOWNLOADNUM = 0;
                book.COLLECTNUM  = 0;
                //ifend:0
                book.IFEND = 0;
                //其余字段留空
                db.BOOK.Add(book);

                BOOKTAG booktag = new BOOKTAG();
                booktag.BOOKID = bookID;
                if (value == "0")
                {
                    booktag.BOOKTAG1 = "玄幻";
                }
                else if (value == "1")
                {
                    booktag.BOOKTAG1 = "仙侠";
                }
                else
                {
                    booktag.BOOKTAG1 = "二次元";
                }

                //改作者表
                WRITER writer = db.WRITER.Find(userid);
                writer.NUMPRODUCTION = writer.NUMPRODUCTION + 1;
                db.BOOKTAG.Add(booktag);
                db.SaveChanges();


                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }
Exemplo n.º 31
0
 partial void DeleteBOOK(BOOK instance);
Exemplo n.º 32
0
 partial void UpdateBOOK(BOOK instance);
Exemplo n.º 33
0
 partial void InsertBOOK(BOOK instance);