Exemple #1
0
        public void AddBookWithAuthors(BookVM book)
        {
            var _book = new Book()
            {
                Title       = book.Title,
                Description = book.Description,
                IsRead      = book.IsRead,
                DateRead    = book.IsRead ? book.DateRead.Value : null,
                Rate        = book.IsRead ? book.Rate.Value : null,
                Genre       = book.Genre,
                CoverURL    = book.CoverURL,
                DateAdded   = DateTime.Now,
                PublisherId = book.PublisherId
            };

            _context.Books.Add(_book);
            _context.SaveChanges();

            foreach (var id in book.AuthorsId)
            {
                var _book_author = new Book_Author()
                {
                    BookId   = _book.Id,
                    AuthorId = id
                };

                _context.Books_Authors.Add(_book_author);
                _context.SaveChanges();
            }
        }
Exemple #2
0
        public async Task <IActionResult> PutBook_Author(int id, Book_Author book_Author)
        {
            if (id != book_Author.AuthorId)
            {
                return(BadRequest());
            }

            _context.Entry(book_Author).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Book_AuthorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public void AddBookWithAuthors(BookDTO bookDTO)
        {
            var _book = new Book()
            {
                Title       = bookDTO.Title,
                Description = bookDTO.Description,
                isRead      = bookDTO.isRead,
                DateRead    = bookDTO.isRead ? bookDTO.DateRead.Value : null,
                Rating      = bookDTO.isRead ? bookDTO.Rating.Value : null,
                Genre       = bookDTO.Genre,
                CoverUrl    = bookDTO.CoverUrl,
                DateAdded   = DateTime.Now,
                PublisherId = bookDTO.PublisherId
            };

            _context.Books.Add(_book);
            _context.SaveChanges();

            foreach (var Id in bookDTO.AuthorsId)
            {
                var _book_author = new Book_Author()
                {
                    BookId   = _book.Id,
                    AuthorId = Id
                };
                _context.Book_Authors.Add(_book_author);
                _context.SaveChanges();
            }
        }
        public void AddBookWithAuthors(BookVM book)
        {
            var _book = new LibBook()
            {
                Book_Title  = book.Book_Title,
                Description = book.Description,
                Edition     = book.Edition,
                isRead      = book.isRead,
                readTime    = book.isRead ? book.readTime.Value : null,
                Genre       = book.Genre,
                addedDate   = DateTime.Now,
                PublisherId = book.PublisherId
            };

            _context.LibBook.Add(_book);
            _context.SaveChanges();

            foreach (var item in book.Authorids)
            {
                var _book_author = new Book_Author()
                {
                    BookId   = _book.BookId,
                    AuthorId = item
                };
                _context.Book_Authors.Add(_book_author);
                _context.SaveChanges();
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("ISBN_Number,AuthorID")] Book_Author book_Author)
        {
            if (id != book_Author.ISBN_Number)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(book_Author);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Book_AuthorExists(book_Author.ISBN_Number))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorID"] = new SelectList(_context.Authors, "AuthorID", "FullName", book_Author.AuthorID);
            return(View(book_Author));
        }
Exemple #6
0
 public static bool DeleteAllCategoryAndAuthor(int ID)
 {
     try
     {
         using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities())
         {
             Book_Author book_author = context.Book_Author.FirstOrDefault(t => t.book_ID == ID);
             while (book_author != null)
             {
                 context.Book_Author.Remove(book_author);
                 context.SaveChanges();
                 book_author = context.Book_Author.FirstOrDefault(t => t.book_ID == ID);
             }
             Book_Category book_category = context.Book_Category.FirstOrDefault(t => t.book_ID == ID);
             while (book_category != null)
             {
                 context.Book_Category.Remove(book_category);
                 context.SaveChanges();
                 book_category = context.Book_Category.FirstOrDefault(t => t.book_ID == ID);
             }
             if (book_author == null && book_category == null)
             {
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception ex)
     {
         LogService.log("BOOK", ex.StackTrace);
         return(false);
     }
 }
        public async Task <IActionResult> Create([Bind("ISBN_Number,AuthorID")] Book_Author book_Author)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book_Author);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorID"] = new SelectList(_context.Authors, "AuthorID", "FullName", book_Author.AuthorID);
            return(View(book_Author));
        }
Exemple #8
0
        public static bool UpDateBook(BookData b)
        {
            try
            {
                DeleteAllCategoryAndAuthor(b.ID);
                Console.WriteLine("ok go here");
                using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities())
                {
                    Book book = context.Books.FirstOrDefault(bo => bo.ID == b.ID);
                    if (book != null)
                    {
                        book.ISBN         = b.ISBN;
                        book.name         = b.Name;
                        book.price        = b.Price;
                        book.quantity     = b.Quantity;
                        book.status       = b.Status;
                        book.year         = b.Year;
                        book.publisher_ID = b.Publisher_ID;
                        book.description  = b.Description;
                        for (int i = 0; i < b.Author.Count; i++)
                        {
                            int         ID     = b.Author[i].ID;
                            Author      author = context.Authors.FirstOrDefault(a => a.ID == ID);
                            Book_Author BA     = new Book_Author();
                            BA.Author = author;
                            BA.Book   = book;
                            book.Book_Author.Add(BA);
                        }
                        for (int i = 0; i < b.Category.Count; i++)
                        {
                            int           ID       = b.Category[i].ID;
                            Category      category = context.Categories.FirstOrDefault(c => c.ID == ID);
                            Book_Category temp     = new Book_Category();
                            temp.Category = category;
                            temp.Book     = book;
                            book.Book_Category.Add(temp);
                        }
                        context.SaveChanges();
                    }

                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogService.log("Erro at Book Service", ex.StackTrace);
                return(false);
            }
        }
        public async Task <IActionResult> Create(Book_Author book_author)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            using (var db = new SakurAniLibContext(this.ConnectionString))
            {
                await db.Book_Author.AddAsync(book_author);

                await db.SaveChangesAsync();

                return(Created($"/api/book_author/{book_author.Id}", book_author));
            }
        }
Exemple #10
0
        public static bool AddBook(BookData b)
        {
            Book book = new Book();

            book.ISBN         = b.ISBN;
            book.description  = b.Description;
            book.name         = b.Name;
            book.price        = b.Price;
            book.quantity     = b.Quantity;
            book.status       = b.Status;
            book.year         = b.Year;
            book.publisher_ID = b.Publisher_ID;
            try
            {
                using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities())
                {
                    for (int i = 0; i < b.Author.Count; i++)
                    {
                        int         ID     = b.Author[i].ID;
                        Author      author = context.Authors.FirstOrDefault(a => a.ID == ID);
                        Book_Author BA     = new Book_Author();
                        BA.Author = author;
                        BA.Book   = book;
                        book.Book_Author.Add(BA);
                    }
                    for (int i = 0; i < b.Category.Count; i++)
                    {
                        int           ID       = b.Category[i].ID;
                        Category      category = context.Categories.FirstOrDefault(c => c.ID == ID);
                        Book_Category temp     = new Book_Category();
                        temp.Category = category;
                        temp.Book     = book;
                        book.Book_Category.Add(temp);
                    }

                    context.Books.Add(book);
                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogService.log("BOOK", ex.StackTrace);
                return(false);
            }
        }
Exemple #11
0
        public async Task <ActionResult <Book_Author> > PostBook_Author(Book_Author book_Author)
        {
            _context.Book_Authors.Add(book_Author);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (Book_AuthorExists(book_Author.AuthorId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetBook_Author", new { id = book_Author.AuthorId }, book_Author));
        }
        public static void Initialize(BookContext context)
        {
            context.Database.EnsureCreated();


            if (context.Authors.Any())
            {
                return;   // DB has been seeded
            }


            var authors = new Author[]
            {
                new Author {
                    AuthorFirstName = "Kira", AuthorLastName = "Cass"
                },
                new Author {
                    AuthorFirstName = "R.J", AuthorLastName = "Palacio"
                }
            };

            foreach (Author s in authors)
            {
                context.Authors.Add(s);
            }
            context.SaveChanges();

            var publisher = new Publisher[]
            {
                new Publisher {
                    PublisherName = Publisher.editorial.RocaEditorial
                },
                new Publisher {
                    PublisherName = Publisher.editorial.Oceano
                }
            };

            foreach (Publisher s in publisher)
            {
                context.publishers.Add(s);
            }
            context.SaveChanges();

            var format = new BookFormat[]
            {
                new BookFormat {
                    FormatDescription = Format.EBUP
                },
                new BookFormat {
                    FormatDescription = Format.PDF
                }
            };

            foreach (BookFormat s in format)
            {
                context.BookFormats.Add(s);
            }
            context.SaveChanges();

            var category = new Category[]
            {
                new Category {
                    CategoryDescription = Categories.Drama
                },
                new Category {
                    CategoryDescription = Categories.Romance
                }
            };

            foreach (Category s in category)
            {
                context.Categories.Add(s);
            }
            context.SaveChanges();

            var BookTitles = new BookTitle[]
            {
                new BookTitle {
                    ISBN_Number  = 1234, Title = "La seleccion", PublisherID = publisher.Single(i => i.PublisherName == Publisher.editorial.RocaEditorial).PublisherID, Published = DateTime.Parse("2007-09-01"),
                    BookFormatID = format.Single(i => i.FormatDescription == Format.EBUP).BookFormatID,
                    Pages        = 234, Price = 459, Comments = ""
                },

                new BookTitle {
                    ISBN_Number  = 4321, Title = "La leccion de august", PublisherID = publisher.Single(i => i.PublisherName == Publisher.editorial.Oceano).PublisherID, Published = DateTime.Parse("2006-11-11"),
                    BookFormatID = format.Single(i => i.FormatDescription == Format.PDF).BookFormatID,
                    Pages        = 347, Price = 255, Comments = ""
                }
            };

            /* foreach (BookTitle s in BookTitles)
             * {
             *   context.BookTitles.Add(s);
             * }
             * context.SaveChanges();*/

            foreach (BookTitle e in BookTitles)
            {
                var bookindatabase = context.BookTitles.Where(
                    s =>
                    s.Publisher.PublisherID == e.PublisherID &&
                    s.BookFormat.BookFormatID == e.BookFormatID).SingleOrDefault();
                if (bookindatabase == null)
                {
                    context.BookTitles.Add(e);
                }
            }
            context.SaveChanges();

            var AuthorBookTitle = new Book_Author[] {
                new Book_Author {
                    AuthorID    = authors.Single(i => i.AuthorLastName == "Cass").AuthorID,
                    ISBN_Number = BookTitles.Single(i => i.Title == "La seleccion").ISBN_Number
                },

                new Book_Author {
                    AuthorID    = authors.Single(i => i.AuthorLastName == "Palacio").AuthorID,
                    ISBN_Number = BookTitles.Single(i => i.Title == "La leccion de august").ISBN_Number
                }
            };

            foreach (Book_Author s in AuthorBookTitle)
            {
                context.Book_Authors.Add(s);
            }
            context.SaveChanges();



            var BooksCategory = new BookCategory[]
            {
                new BookCategory {
                    CategoryID  = category.Single(i => i.CategoryDescription == Categories.Drama).CategoryID,
                    ISBN_Number = BookTitles.Single(i => i.Title == "La seleccion").ISBN_Number
                },

                new BookCategory {
                    CategoryID  = category.Single(i => i.CategoryDescription == Categories.Romance).CategoryID,
                    ISBN_Number = BookTitles.Single(i => i.Title == "La leccion de august").ISBN_Number
                }
            };

            foreach (BookCategory s in BooksCategory)
            {
                context.BookCategories.Add(s);
            }
            context.SaveChanges();
        }
        public void BookGive(BookViewModel bookVm, string session)
        {
            TimeSpan?interval;
            DateTime?receivingDate, givingDate;

            receivingDate = null;
            interval      = null;
            BookOperation bkO = null;

            if (bookVm.PublisherName == null)
            {
                bkO = (from bo in bookDC.BookOperations
                       where bo.UserName == session && bo.BookName == bookVm.BookName && bo.ReceivingDate != null
                       select bo).FirstOrDefault();
            }
            else
            {
                bkO = (from bo in bookDC.BookOperations
                       where bo.UserName == session && bo.BookName == bookVm.BookName
                       select bo).FirstOrDefault();
            }

            var authr = (from a in bookDC.Authors
                         where a.AuthorName == bookVm.AuthorName
                         select a).FirstOrDefault();

            Penalty       penalty = new Penalty();
            BookOperation BO      = new BookOperation();

            if (bkO == null)
            {
                BO.UserName      = session;
                BO.CategoryName  = bookVm.CategoryName;
                BO.BookName      = bookVm.BookName;
                BO.PublisherName = bookVm.PublisherName;
                BO.GivingDate    = DateTime.Now;
                if (!string.IsNullOrEmpty(bookVm.AuthorName))
                {
                    BO.AuthorName = bookVm.AuthorName;
                }
                else
                {
                    BO.AuthorName = "-";
                }

                bookDC.BookOperations.Add(BO);
                bookDC.SaveChanges();

                penalty.BookOperationId = BO.Id;
                penalty.PenaltyQuantity = 0;
                bookDC.Penalties.Add(penalty);
            }
            else
            {
                if (bkO.ReceivingDate == null)
                {
                    BO.UserName      = session;
                    BO.CategoryName  = bookVm.CategoryName;
                    BO.BookName      = bookVm.BookName;
                    BO.PublisherName = bookVm.PublisherName;
                    BO.GivingDate    = DateTime.Now;
                    BO.ReceivingDate = null;
                    if (!string.IsNullOrEmpty(bookVm.AuthorName))
                    {
                        BO.AuthorName = bookVm.AuthorName;
                    }
                    else
                    {
                        BO.AuthorName = "-";
                    }

                    bookDC.BookOperations.Add(BO);
                    bookDC.SaveChanges();

                    penalty.BookOperationId = BO.Id;
                    penalty.PenaltyQuantity = 0;
                    bookDC.Penalties.Add(penalty);
                }
                else
                {
                    receivingDate  = bkO.ReceivingDate;
                    bkO.GivingDate = DateTime.Now;
                    givingDate     = bkO.GivingDate;
                    interval       = givingDate - receivingDate;
                    foreach (var item in bookDC.Penalties)
                    {
                        if (item.BookOperationId == bkO.Id)
                        {
                            if (interval.Value.Days <= 7)
                            {
                                item.PenaltyQuantity = 0;
                            }
                            else
                            {
                                item.PenaltyQuantity = (double)interval.Value.Days * 0.50;
                                break;
                            }
                        }
                    }
                }

                var bk = (from b in bookDC.Books
                          where b.BookName == bookVm.BookName
                          select b).FirstOrDefault();
                Book book = new Book();
                if (bk == null)
                {
                    book.BookName   = bookVm.BookName;
                    book.CategoryId = (from item in bookDC.Categories
                                       where item.CategoryName == bookVm.CategoryName
                                       select item.CategoryId).FirstOrDefault();
                    book.BookQuantity = 1;
                    bookDC.Books.Add(book);
                }
                else
                {
                    bk.BookQuantity++;
                }



                Author author = new Author();
                if (authr == null)
                {
                    if (bookVm.AuthorName != null)
                    {
                        author.AuthorName = bookVm.AuthorName;
                        bookDC.Authors.Add(author);
                        Book_Author BA = new Book_Author();
                        BA.AuthorId = author.AuthorId;
                        BA.BookId   = book.BookId;
                        bookDC.Book_Author.Add(BA);
                    }
                    else
                    {
                        if (bkO.GivingDate != null)
                        {
                        }
                        else
                        {
                            author.AuthorName = "-";
                            bookDC.Authors.Add(author);
                            Book_Author BA = new Book_Author();
                            BA.AuthorId = author.AuthorId;
                            BA.BookId   = book.BookId;
                            bookDC.Book_Author.Add(BA);
                        }
                    }
                }


                var publishr = (from p in bookDC.Publishers
                                where p.PublisherName == bookVm.PublisherName
                                select p).FirstOrDefault();
                Publisher publshr = new Publisher();
                if (publishr == null)
                {
                    if (bookVm.PublisherName != null)
                    {
                        publshr.PublisherName = bookVm.PublisherName;
                        bookDC.Publishers.Add(publshr);
                        Book_Publisher BP = new Book_Publisher();
                        BP.PublisherId = publshr.PublisherId;
                        BP.BookId      = book.BookId;
                        bookDC.Book_Publisher.Add(BP);
                    }
                    else
                    {
                        if (bkO.GivingDate != null)
                        {
                        }
                        else
                        {
                            publshr.PublisherName = "-";
                            bookDC.Publishers.Add(publshr);
                            Book_Publisher BP = new Book_Publisher();
                            BP.PublisherId = publshr.PublisherId;
                            BP.BookId      = book.BookId;
                            bookDC.Book_Publisher.Add(BP);
                        }
                    }
                }

                bookDC.SaveChanges();
            }
        }
Exemple #14
0
 public override void Get_Info()
 {
     Console.WriteLine("Наименование - " + Good_Name.ToString() + "; Заголовок -  " + Book_Title.ToString() + "; Цена - " + Price.ToString() + "; Автор - " + Book_Author.ToString() + "; Жанр -  " + Book_Genre.ToString() + "; Издательство -  " + Book_Publisher.ToString());
 }