Beispiel #1
0
        static void BuildChangelogBook(string dir)
        {
            Console.WriteLine("building book: Changelog");
            if (!FileExists(dir, "index.html"))
            {
                Console.WriteLine("please create index.html at /changelog");
                return;
            }

            var fileName = CombineDir(RootFolder, "Changelog.hhc");

            using (var fout = new StreamWriter(fileName, false, Encoding.UTF8))
            {
                // header
                fout.WriteLine(NewBook.Gen("\t", "Changelog", "changelog/index.html"));

                // pages
                var tab2 = "\t\t";
                var vers = Directory.GetFiles(dir, "*.???*.htm*")
                           .OrderByDescending(f => f);
                foreach (var fn in vers)
                {
                    var url   = fn.Replace(RootFolder, "");
                    var title = Titles[fn];
                    fout.WriteLine(BookPage.Gen(tab2, title, url));
                }

                //footer
                fout.WriteLine(EndBook.Gen("\t", "", ""));
            }
        }
Beispiel #2
0
        public ActionResult Index([Bind(Include = "Title, ISBN, AuthorName")] NewBook nb)
        {
            Author a = new Author();

            a.AuthorName = nb.AuthorName;
            db.Authors.Add(a);
            db.SaveChanges();

            Book b = new Book();

            b.BookTitle     = nb.Title;
            b.BookISBN      = nb.ISBN;
            b.BookEntryDate = DateTime.Now;

            Author author = db.Authors.FirstOrDefault
                                (x => x.AuthorName == nb.AuthorName);

            b.Authors.Add(author);

            db.Books.Add(b);
            db.SaveChanges();

            MessageClass m = new MessageClass();

            m.MessageText = "Thank you, the book has been added";

            return(View("Result", m));
        }
 public ActionResult Create(NewBook model)
 {
     try
     {
         using (var db = new AppContextForBook())
         {
             var book = new Book
             {
                 Name        = model.Name,
                 Author      = model.Author,
                 Price       = model.Price,
                 Popular     = model.Popular,
                 PublishDate = model.PublishDate
             };
             try
             {
                 db.Books.AddRange(book);
                 db.SaveChanges();
             }
             catch (Exception)
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Details)));
     }
     catch
     {
         return(View());
     }
 }
Beispiel #4
0
        public ActionResult Edit(HttpPostedFileBase fileUpload, [Bind(Include = "MaSach,MaTL,MaNXB,TenSach,TrangThai,GiaBia,HinhAnh,Moi")] Sach sach)
        {
            List <SachMoi> moi = new NewBook().sm();

            if (ModelState.IsValid)
            {
                //Upload file
                var fileName = Path.GetFileName(fileUpload.FileName);
                //Lưu đường dẫn file ảnh
                var path = Path.Combine(Server.MapPath("~/Content/image"), fileName);
                //Kiểm tra file đã tồn tại
                if (System.IO.File.Exists(path))
                {
                    ViewBag.ThongBao = "Hình ảnh đã tồn tại";
                }
                else
                {
                    fileUpload.SaveAs(path);
                }

                //Them Sach Moi
                sach.HinhAnh = fileUpload.FileName;
                db.Sach.Add(sach);

                db.Entry(sach).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("getListBook"));
            }

            ViewBag.m     = new SelectList(moi, "So", "Chu", sach.Moi);
            ViewBag.MaNXB = new SelectList(db.NhaXuatBan, "MaNXB", "TenNXB", sach.MaNXB);
            ViewBag.MaTL  = new SelectList(db.TheLoai, "MaTL", "TenTL", sach.MaTL);

            return(View(sach));
        }
Beispiel #5
0
        static async Task <int> Main(string[] args)
        {
            HttpClient client = new HttpClient();
            string     result = await client.GetStringAsync("http://localhost:5000/api/Books");

            var allbooks = JsonConvert.DeserializeObject <Book[]>(result);

            foreach (var b in allbooks)
            {
                Console.WriteLine($"{b.Title}");
            }

            var nb = new NewBook()
            {
                Title = "C", Pages = 400
            };
            var s = JsonConvert.SerializeObject(nb);
            var c = new StringContent(s);

            c.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
            await client.PutAsync("http://localhost:5000/api/books", c);


            return(0);
        }
Beispiel #6
0
        private void newToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            NewBook newBook = new NewBook();

            newBook.MdiParent = this;
            newBook.Show();
        }
Beispiel #7
0
            public Book(Book pred, string name)
            {
                _pred    = pred;
                _name    = name;
                PredTabs = pred?.Tabs ?? "\t";
                Tabs     = "\t" + PredTabs;

                var url   = PhobosFileName(_name);
                var file  = CombineDir(Context.RootFolder, url);
                var dots  = name.Replace('_', '.');
                var title = dots;

                if (!FileExists(Context.RootFolder, url))
                {
                    var htm = Context.Empty.Replace("%TITLE%", dots);
                    File.WriteAllText(file, htm, Encoding.UTF8);
                    Context.Titles[file] = dots;
                }
                else
                {
                    try { title = Context.Titles[file]; } catch { }
                }

                // header
                var hdr = NewBook.Gen(PredTabs, title, url);

                Context.File.WriteLine(hdr);
            }
Beispiel #8
0
        public IHttpActionResult AddNewBookToStore([FromBody] NewBook newBook)
        {
            if (!ModelState.IsValid)
            {
                return(new InvalidModelResult(Request, HttpStatusCode.BadRequest, ModelState));
            }

            var command = new AddNewBookCommand(newBook);

            if (!command.IsValidCommand())
            {
                return(BadRequest());
            }

            _addNewBookToStoreUseCase.Handle(command);

            var query = new GetBookQuery(newBook.Isbn);

            var result = _getBookInfoWithDetailsUseCase.Handle(query);

            if (result != null)
            {
                return(Created(result.Links.First(x => x.Rel == "self").Href, result));
            }

            return(NotFound());
        }
Beispiel #9
0
        public ActionResult Add()
        {
            NewBook newbook = new NewBook();

            newbook.book    = new Book();
            newbook.authors = database.Authors.ToList();
            return(View(newbook));
        }
Beispiel #10
0
        public void ShowWindow(object o)
        {
            this.ChangeIsActiv(false);
            NewBook nb = new NewBook();

            nb.Show();
            this.Window.Hide();
            nb.ShowInTaskbar = false;
        }
        private void CommandBinding_ChangeBookExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            Book book = this.booksDataGrid.SelectedItem as Book;

            book.IsNew = false;
            var bookWindow = new NewBook(book);

            bookWindow.ShowDialog();
            this.booksDataGrid.Items.Refresh();
        }
Beispiel #12
0
      private async void OnSaveBook()
      {
          bool checkTitle, checkAuthor, checkTags, checkEntries;

          string[] tags;

          checkTitle  = NewBook.Title == "" || NewBook.Title == null ? false : true;
          checkAuthor = NewBook.Author == "" || NewBook.Author == null ? false : true;
          checkTags   = BookTags == null || BookTags == "" ? false : true;

          if (!(checkTitle && checkAuthor && checkTags))
          {
              AlertManager.IncompleteInfo();
              return;
          }

          if (NewBook.Entries == null || NewBook.Entries.Count == 0)
          {
              checkEntries = await AlertManager.NoEntries();

              if (!checkEntries)
              {
                  return;
              }
          }

          tags = Regex.Split(BookTags, ", ");
          NewBook.BookTags.Clear();
          foreach (String s in tags)
          {
              NewBook.BookTags.Add(s);
          }

          HashSet <WorkTag> entryTags = new HashSet <WorkTag>();

          NewBook.EntryTags.Clear();

          foreach (WorkEntry e in NewBook.Entries)
          {
              if (e.ImageChanged)
              {
                  await FileManager.AddImage(e.ImagePath, e.NewImageData);
              }
              foreach (WorkTag t in e.Tags)
              {
                  NewBook.EntryTags.Add(t.Name);
              }
          }

          Debug.WriteLine(NewBook.ToString());
          RealmManager.AddBook(NewBook);

          await Navigation.PopAsync();
      }
Beispiel #13
0
 public AddNewBookCommand(NewBook newBook)
 {
     Author      = newBook.Author;
     Title       = newBook.Title;
     Isbn        = newBook.Isbn;
     Pages       = newBook.Pages;
     Description = newBook.Description;
     Price       = newBook.Price;
     Discount    = newBook.Discount;
     Amount      = newBook.Amount;
 }
        private void CommandBinding_NewBookExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var curAuth    = (Author)this.authorsListView.SelectedItem;
            var book       = new Book();
            var bookWindow = new NewBook(book);

            if ((bool)bookWindow.ShowDialog())
            {
                curAuth.Books.Add(book);
            }
        }
        public void AddNewBorrow()
        {
            NewBook m = new NewBook();

            m.BookNumber = "Book " + i.ToString();
            BorrowsList.Add(m);
            m.Books = new BindableCollection <BookDTO>(AvaibleBooks);
            m.SelectedBookChangeRemove += OnSelectedBookChangeRemove;
            m.SelectedBookChangeAdd    += OnSelectedBookChangeAdd;
            NotifyOfPropertyChange(() => CanAdd);
            i++;
        }
        /// <summary>
        ///  Saves New Book
        /// </summary>
        /// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="newBook">user to be added</param>
        /// <returns>ApiResponse of Object(void)</returns>
        public Org.OpenAPITools.Client.ApiResponse <Object> BookPostWithHttpInfo(NewBook newBook)
        {
            // verify the required parameter 'newBook' is set
            if (newBook == null)
            {
                throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'newBook' when calling BookApi->BookPost");
            }

            Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions();

            String[] _contentTypes = new String[] {
                "application/json"
            };

            // to determine the Accept header
            String[] _accepts = new String[] {
                "application/json"
            };

            var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes);

            if (localVarContentType != null)
            {
                localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
            }

            var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts);

            if (localVarAccept != null)
            {
                localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
            }

            localVarRequestOptions.Data = newBook;


            // make the HTTP request
            var localVarResponse = this.Client.Post <Object>("/book", localVarRequestOptions, this.Configuration);

            if (this.ExceptionFactory != null)
            {
                Exception _exception = this.ExceptionFactory("BookPost", localVarResponse);
                if (_exception != null)
                {
                    throw _exception;
                }
            }

            return(localVarResponse);
        }
Beispiel #17
0
        //Thêm sách mới
        public ActionResult CreateBook()
        {
            List <SachMoi> moi = new NewBook().sm();

            ViewBag.m = new SelectList(moi, "So", "Chu");

            if (db.TheLoai.ToList() != null && db.NhaXuatBan.ToList() != null)
            {
                ViewBag.nxb = db.NhaXuatBan.ToList();
                ViewBag.tl  = db.TheLoai.ToList();
            }
            else
            {
                ViewBag.orr = "loi";
            }

            return(View());
        }
Beispiel #18
0
        static void BuildArticlesBook(string dir)
        {
            Console.WriteLine("building book: Articles");
            var content = "index.html";

            if (!FileExists(dir, content))
            {
                content = "articles.html";
            }
            if (!FileExists(dir, content))
            {
                Console.WriteLine("please create articles- or index.html at /articles");
                return;
            }
            var prefx = dir.Replace(RootFolder, "");

            var fileName = CombineDir(RootFolder, "Articles.hhc");

            using (var fout = new StreamWriter(fileName, false, Encoding.UTF8))
            {
                // header
                var hdr = NewBook.Gen("\t", "Articles", Path.Combine(prefx, content));
                fout.WriteLine(hdr);

                // pages
                var doc = new HtmlDocument();
                doc.Load(CombineDir(dir, content), Encoding.UTF8);
                var tab2 = "\t\t";
                // <div class="boxes"> <div class="row">
                //		<div class="item"> <h4><a href="../articles/faq.html">FAQ</a></h4>
                var qry = "//div[@class=\"boxes\"]//a";
                foreach (var el in doc.DocumentNode.SelectNodes(qry))
                {
                    var url = el.GetAttributeValue("href", "");
                    url = CombineDir(dir, url).Replace(RootFolder, "");
                    var title = el.InnerText.ToLine();
                    fout.WriteLine(BookPage.Gen(tab2, title, url));
                }

                //footer
                fout.WriteLine(EndBook.Gen("\t", "", ""));
            }
        }
        public bool addNewSuggest(NewBook b)
        {
            string       SQL         = "Insert tblSuggest values(@username,@BookName,@author,@year,@description,@status)";
            SqlParameter username    = new SqlParameter("@username", b.username);
            SqlParameter BookName    = new SqlParameter("@BookName", b.BookName);
            SqlParameter author      = new SqlParameter("@author", b.author);
            SqlParameter year        = new SqlParameter("@year", b.year);
            SqlParameter description = new SqlParameter("@description", b.description);
            SqlParameter status      = new SqlParameter("@status", b.status);

            try
            {
                return(DataProvider.ExecuteNonQuery(SQL, CommandType.Text, username, BookName, author, year, description, status));
            }
            catch (SqlException se)
            {
                throw new Exception(se.Message);
            }
        }
Beispiel #20
0
        public IActionResult AddBook([FromBody] NewBook nb)
        {
            Book book = new Book()
            {
                Title       = nb.Title,
                PageCount   = nb.PageCount,
                Description = nb.Description,
                ImagePath   = nb.ImagePath,
                ISBN        = nb.ISBN
            };

            if (nb.DeweyDecimal != null && nb.FicID == null)
            {
                book.DeweyDecimal = nb.DeweyDecimal;
            }
            else if (nb.FicID != null && nb.DeweyDecimal == null)
            {
                book.FicID = nb.FicID;
            }
            else if (nb.DeweyDecimal == null && nb.FicID == null)
            {
                return(StatusCode(400, "Specify Dewey Decimal or Fiction ID"));
            }
            else
            {
                return(StatusCode(400, "Can not specify both Dewey Decimal and Fiction ID"));
            }
            _ctx.Books.Add(book);
            _ctx.SaveChanges();
            foreach (int authID in nb.AuthorIDs)
            {
                _ctx.AuthorBook_rel.Add(
                    new AuthorBook()
                {
                    BookID   = book.BookID,
                    AuthorID = authID
                }
                    );
            }
            _ctx.SaveChanges();
            return(Ok());
        }
Beispiel #21
0
        static void BuildSpecBook(string dir)
        {
            Console.WriteLine("building book: Specification");
            var content = "spec.html";

            if (!FileExists(dir, content))
            {
                content = "index.html";
            }
            if (!FileExists(dir, content))
            {
                Console.WriteLine("please create index- or spec.html at /spec");
                return;
            }
            var prefx = dir.Replace(RootFolder, "");

            var fileName = CombineDir(RootFolder, "Spec.hhc");

            using (var fout = new StreamWriter(fileName, false, Encoding.UTF8))
            {
                // header
                var hdr = NewBook.Gen("\t", "Language Reference", Path.Combine(prefx, content));
                fout.WriteLine(hdr);

                // pages
                var doc = new HtmlDocument();
                doc.Load(CombineDir(dir, content), Encoding.UTF8);
                var tab2 = "\t\t";
                // <div class="hyphenate" id="content"><ul><li><a>
                var qry = "//div[@id=\"content\"]/ul/li/a";
                foreach (var el in doc.DocumentNode.SelectNodes(qry))
                {
                    var url   = Path.Combine(prefx, el.GetAttributeValue("href", ""));
                    var title = el.InnerText.ToLine();
                    fout.WriteLine(BookPage.Gen(tab2, title, url));
                }

                //footer
                fout.WriteLine(EndBook.Gen("\t", "", ""));
            }
        }
Beispiel #22
0
        [ValidateAntiForgeryToken] //Security help
        public ActionResult CreateBook(Sach book, HttpPostedFileBase fileUpload)
        {
            List <SachMoi> moi = new NewBook().sm();

            ViewBag.nxb = db.NhaXuatBan.ToList();
            ViewBag.tl  = db.TheLoai.ToList();

            ViewBag.m = new SelectList(moi, "So", "Chu");
            try
            {
                if (ModelState.IsValid)
                {
                    //Upload file
                    var fileName = Path.GetFileName(fileUpload.FileName);
                    //Lưu đường dẫn file ảnh
                    var path = Path.Combine(Server.MapPath("~/Content/image"), fileName);
                    //Kiểm tra file đã tồn tại
                    if (System.IO.File.Exists(path))
                    {
                        ViewBag.ThongBao = "Hình ảnh đã tồn tại";
                    }
                    else
                    {
                        fileUpload.SaveAs(path);
                    }
                    //Them Sach Moi
                    book.HinhAnh = fileUpload.FileName;
                    db.Sach.Add(book);
                    db.SaveChanges();
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "Lỗi trùng Mã sách: " + book.MaSach);
                return(View());
            }

            //Cập nhật lại danh sách hiển thị
            //var list = from s in db.Sach select s;
            return(RedirectToAction("getListBook"));
        }
        public void Remove(NewBook book)
        {
            if (book.SelectedBook != null)
            {
                foreach (var item in BorrowsList)
                {
                    item.Books.Add(book.SelectedBook);
                }
                AvaibleBooks.Add(book.SelectedBook);
            }
            BorrowsList.Remove(book);
            int number = 1;

            foreach (var item in BorrowsList)
            {
                item.BookNumber = "Book " + number.ToString();
            }
            number = 1;
            NotifyOfPropertyChange(() => CanAdd);
            NotifyOfPropertyChange(() => BorrowsList);
        }
Beispiel #24
0
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            List <SachMoi> moi = new NewBook().sm();

            Sach sach = db.Sach.Find(id);

            if (sach == null)
            {
                return(HttpNotFound());
            }

            ViewBag.m     = new SelectList(moi, "So", "Chu", sach.Moi);
            ViewBag.MaNXB = new SelectList(db.NhaXuatBan, "MaNXB", "TenNXB", sach.MaNXB);
            ViewBag.MaTL  = new SelectList(db.TheLoai, "MaTL", "TenTL", sach.MaTL);

            return(View(sach));
        }
Beispiel #25
0
        private void OnSaveBook(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(titleBox.Text) && !string.IsNullOrWhiteSpace(isbnBox.Text) &&
                !string.IsNullOrWhiteSpace(publisherBox.Text) && !string.IsNullOrWhiteSpace(authorListBox.Text) &&
                !string.IsNullOrWhiteSpace(genreBox.Text) && !string.IsNullOrWhiteSpace(qtyBox.Text))
            {
                BookGenre  genres  = new BookGenre();
                List <int> authors = new List <int>();
                int.TryParse(qtyBox.Text, out int qty);

                foreach (var genre in genreBox.CheckedItems)
                {
                    genres = genres | (BookGenre)Enum.Parse(typeof(BookGenre), genre.ToString());
                }

                foreach (Author author in authorListBox.SelectedItems)
                {
                    authors.Add(author.ID);
                }

                for (int i = 0; i < qty; i++)
                {
                    Book = new Book(title: titleBox.Text, isbn: isbnBox.Text, authorID: authors,
                                    publisher: publisherBox.Text, genre: genres, description: descriptionBox.Text);

                    NewBook?.Invoke(this, new BookRelatedEventArgs {
                        Book = Book
                    });
                }
                MessageBox.Show(StringConstants.BookRegistered(titleBox.Text, isbnBox.Text));
                RefreshAndClear();
            }
            else
            {
                MessageBox.Show(StringConstants.missingInfo);
            }
            AutomaticFormPosition.SaveFormStatus(this);
        }
 public Book AddNewBook(NewBook nb)
 {
     throw new System.NotImplementedException();
 }
        /// <summary>
        ///  Saves New Book
        /// </summary>
        /// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="newBook">user to be added</param>
        /// <returns>Task of ApiResponse</returns>
        public async System.Threading.Tasks.Task <Org.OpenAPITools.Client.ApiResponse <Object> > BookPostAsyncWithHttpInfo(NewBook newBook)
        {
            // verify the required parameter 'newBook' is set
            if (newBook == null)
            {
                throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'newBook' when calling BookApi->BookPost");
            }


            Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions();

            String[] _contentTypes = new String[] {
                "application/json"
            };

            // to determine the Accept header
            String[] _accepts = new String[] {
                "application/json"
            };

            foreach (var _contentType in _contentTypes)
            {
                localVarRequestOptions.HeaderParameters.Add("Content-Type", _contentType);
            }

            foreach (var _accept in _accepts)
            {
                localVarRequestOptions.HeaderParameters.Add("Accept", _accept);
            }

            localVarRequestOptions.Data = newBook;


            // make the HTTP request

            var localVarResponse = await this.AsynchronousClient.PostAsync <Object>("/book", localVarRequestOptions, this.Configuration);

            if (this.ExceptionFactory != null)
            {
                Exception _exception = this.ExceptionFactory("BookPost", localVarResponse);
                if (_exception != null)
                {
                    throw _exception;
                }
            }

            return(localVarResponse);
        }
 /// <summary>
 ///  Saves New Book
 /// </summary>
 /// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="newBook">user to be added</param>
 /// <returns>Task of void</returns>
 public async System.Threading.Tasks.Task BookPostAsync(NewBook newBook)
 {
     await BookPostAsyncWithHttpInfo(newBook);
 }
 /// <summary>
 ///  Saves New Book
 /// </summary>
 /// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="newBook">user to be added</param>
 /// <returns></returns>
 public void BookPost(NewBook newBook)
 {
     BookPostWithHttpInfo(newBook);
 }
Beispiel #30
0
        static void Main(string[] args)
        {
            Console.WriteLine("One-to-one");
            using (var db = new BookContext())
            {
                Mother m1 = new Mother {
                    Name = "Marry"
                };
                Mother m2 = new Mother {
                    Name = "Jany"
                };

                db.Mothers.Add(m1);
                db.Mothers.Add(m2);

                db.SaveChanges();

                Child c1 = new Child {
                    Id = m1.Id, Name = "Jhon"
                };
                Child c2 = new Child {
                    Id = m2.Id, Name = "Jack"
                };

                db.Children.Add(c1);
                db.Children.Add(c2);

                db.SaveChanges();
            }

            using (var db = new BookContext())
                foreach (var mother in db.Mothers.Include("Child").ToList())
                {
                    Console.WriteLine($"Mother {mother.Name} and her kid {mother.Child.Name}");
                }

            Console.WriteLine("Many-to-many");
            using (var db = new BookContext())
            {
                NewAuthor ilf = new NewAuthor  {
                    Name = "Ilya Ilf"
                };
                NewAuthor petrov = new NewAuthor  {
                    Name = "Evgeny Petrov"
                };
                NewAuthor gaiman = new NewAuthor  {
                    Name = "Neil Gaiman"
                };
                NewAuthor pratchett = new NewAuthor  {
                    Name = "Terry Pratchett"
                };
                NewAuthor jolliffe = new NewAuthor  {
                    Name = "Gray Jolliffe"
                };

                db.NewAuthors.Add(ilf);
                db.NewAuthors.Add(petrov);
                db.NewAuthors.Add(gaiman);
                db.NewAuthors.Add(pratchett);
                db.NewAuthors.Add(jolliffe);

                db.SaveChanges();

                NewBook osa = new NewBook {
                    Name = "One-story America"
                };
                NewBook go = new NewBook {
                    Name = "Good omens"
                };
                NewBook tuc = new NewBook {
                    Name = "The Unadulterated Cat"
                };

                osa.NewAuthors.Add(ilf);
                osa.NewAuthors.Add(petrov);

                go.NewAuthors.Add(gaiman);
                go.NewAuthors.Add(pratchett);

                tuc.NewAuthors.Add(pratchett);
                tuc.NewAuthors.Add(jolliffe);

                db.NewBooks.Add(osa);
                db.NewBooks.Add(go);
                db.NewBooks.Add(tuc);

                db.SaveChanges();
            }

            Console.WriteLine("Books with authors:");
            int i = 1;

            using (var db = new BookContext())
                foreach (var book in db.NewBooks)
                {
                    Console.WriteLine($"{i++}. {book.Name}");
                    using (var middleContext = new BookContext())
                    {
                        var b = middleContext.NewBooks.FirstOrDefault(x => x.Id == book.Id);
                        foreach (var author in b.NewAuthors)
                        {
                            Console.WriteLine($"\t{author.Name}");
                        }
                    }
                }

            Console.WriteLine("Authors with books:");
            i = 1;
            using (var db = new BookContext())
                foreach (var author in db.NewAuthors)
                {
                    Console.WriteLine($"{i++}. {author.Name}");
                    using (var middleContext = new BookContext())
                    {
                        var a = middleContext.NewAuthors.FirstOrDefault(x => x.Id == author.Id);
                        foreach (var book in a.NewBooks)
                        {
                            Console.WriteLine($"\t{book.Name}");
                        }
                    }
                }

            Console.ReadLine();
        }