public void AddNewGenre_NewGenreToBeAdded_ReturnOneMoreToBeCount() { // Arrange var service = new BookGenreService(); var totalBeforeAdd = service.Count(); // Act var model = new BookGenre(); model.Description = "Test"; var result = service.AddNewBookGenreValidation(model); var totalAfterAdded = service.Count(); bool validation; // Assert if (result == true) { if (totalBeforeAdd < totalAfterAdded) { validation = true; } else { validation = false; } } else { validation = false; } Assert.IsTrue(validation); }
public BookGenre randomGenre() { Array values = Enum.GetValues(typeof(BookGenre)); BookGenre randomGenre = (BookGenre)values.GetValue(random.Next(values.Length)); return(randomGenre); }
public void Insert(BookGenre model) { using (var connection = new SqlConnection(_connectionString)) { connection.Insert <BookGenre>(model); } }
public async Task <IActionResult> PutBookGenre(int id, BookGenre bookGenre) { var bookGenres = _context.BookGenres.Where(sg => sg.GenreId == bookGenre.GenreId && sg.BookId == bookGenre.BookId).Include(sg => sg.Book).Include(sg => sg.Genre).ToList().Count(); if (bookGenres != 0) { return(BadRequest("Книга з таким жанром вже існує")); } if (id != bookGenre.Id) { return(BadRequest()); } _context.Entry(bookGenre).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookGenreExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult ManageGenre(List <ManageGenreViewModel> model, int bookId) { var book = _systemContext.Books.Include(g => g.BookGenres).ThenInclude(g => g.Genre).FirstOrDefault(b => b.Id == bookId); if (book == null) { return(View()); } List <String> genres = book.BookGenres.Select(c => c.Genre.GenreName).ToList(); foreach (BookGenre bookGenre in book.BookGenres) { _systemContext.Entry(bookGenre).State = EntityState.Deleted; } var gen = model.Where(x => x.Selected).ToList(); foreach (var g in gen) { BookGenre newBookGenre = new BookGenre { Book = book, GenreId = g.GenreId }; _systemContext.BookGenres.Add(newBookGenre); } _systemContext.SaveChanges(); return(RedirectToAction("EditBook", new { bookId = bookId })); }
public void AddNewBookGenreValidation(BookGenre bookGenre) { if (!String.IsNullOrEmpty(bookGenre.Description)) { int exist = GetBookGenreId(bookGenre.Description); if (exist != 0) { MessageBox.Show("The genre already exist!", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { try { AddNewBookGenre(bookGenre); } catch (Exception ex) { MessageBox.Show("Error when trying to add new genre, details: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Please type the new book genre. ", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,IdBook,IdGenre")] BookGenre bookGenre) { if (id != bookGenre.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(bookGenre); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookGenreExists(bookGenre.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdBook"] = new SelectList(_context.Books, "Id", "Name", bookGenre.IdBook); ViewData["IdGenre"] = new SelectList(_context.Genres, "Id", "Name", bookGenre.IdGenre); return(View(bookGenre)); }
public async Task <int> Handle(CreateBookAdminCommand request, CancellationToken cancellationToken) { var entity = new Book { Title = request.Title, Description = request.Description, Image = request.Image, Slug = request.Slug, AuthorId = request.AuthorID }; _context.Books.Add(entity); foreach (var idCateBook in request.CategoriesID) { var categoryBook = new BookCategory { BookId = entity.Id, CategoryId = idCateBook }; _context.BookCategories.Add(categoryBook); } foreach (var idGenre in request.GenreID) { var genreBook = new BookGenre { BookId = entity.Id, GenreId = idGenre }; _context.BookGenres.Add(genreBook); } await _context.SaveChangesAsync(cancellationToken); return(entity.Id); }
public bool AddNewBookGenreValidation(BookGenre bookGenre) { if (!String.IsNullOrEmpty(bookGenre.Description)) { int exist = GetBookGenreId(bookGenre.Description); if (exist != 0) { return(false); } else { try { AddNewBookGenre(bookGenre); return(true); } catch (Exception ex) { return(false); } } } else { return(false); } }
public void Update(BookGenre model) { using (var connection = new SqlConnection(_connectionString)) { connection.Update <BookGenre>(model); } }
/// <summary> /// GetBookGenreList /// </summary> /// <param name="model">model</param> /// <returns> return List Of BookGenre to display in grid </returns> public List <BookGenre> GetBookGenreList(BookGenre model) { using (ServiceContext service = new ServiceContext()) { return(service.Search <BookGenre>(model, model.StartRowIndex, model.EndRowIndex, model.SortExpression, model.SortDirection).ToList()); } }
public async Task MatchGenresToBookAsync(IEnumerable <string> genres, string bookId) { foreach (var genreName in genres) { var genre = await this.genreRepository.GetByExpressionAsync(g => g.Name == genreName); if (genre == null) { var genreNew = new Genre() { GenreId = Guid.NewGuid().ToString(), Name = genreName }; genre = genreNew; await this.genreUpdateService.AddAsync(genre); } var genreId = genre.GenreId; var bookGenreRecord = new BookGenre() { BookId = bookId, GenreId = genreId }; await this.bookGenreUpdateService.AddAsync(bookGenreRecord); } }
public void SetAspect() { TxtPrinter.PrintInformation("Now we'll get information regarding books you've read.", '-', ConsoleColor.DarkGreen); NumberOfBooksRead = Asker.GetValue <int>("How many books have you read?"); FavoriteGenre = (BookGenre)(Asker.GetChoiceFromList("What is your favorite genre of book?", TypParser.GetEnumValuesList <BookGenre>())); }
} // When the book is issued ( DateTime is the type since we are working with dates ) // [Constructor] We created a constructor because we want to created objects from this class easier public HardCoverBook(int isbn, string title, string author, BookGenre genre, int pages, int inStock, DateTime dateIssued) // we used base so we don't have to connect the first 5 prperties since we have them in the Author constructor : base(isbn, title, author, genre, pages) // EQUIVALENT -> new Author(isbn, title, author, genre, pages) { // We only connect the unique properties, the others are set in base() InStock = inStock; DateIssued = dateIssued; }
private void AddNewBookGenre(BookGenre bookGenre) { using (Context db = new Context()) { db.BookGenres.Add(bookGenre); db.SaveChanges(); } }
public Book(int bookId, string bookTitle, string bookAuthor, int bookYear, BookGenre genre) { Id = bookId; Title = bookTitle; Author = bookAuthor; PublishmentYear = bookYear; Genre = genre; }
public Book(int isbn, string title, string author, BookGenre genre, int pages) { ISBN = isbn; Title = title; Author = author; Genre = genre; Pages = pages; }
public Book(Guid id, string title, int year, int price, BookGenre genre) { Id = id; Title = title; Year = year; Price = price; Genre = genre; }
public Book(BookGenre genre, string title, string author, decimal price) { Id = Guid.NewGuid(); Genre = genre; Title = title.Trim(); Author = author.Trim(); Price = price; }
/// <summary> /// A constructor, creates an object of the /// Book class, and initiates it's instance /// variables with argument values. It has /// five parameters. /// </summary> /// <param name="myISBN">myISBN as string</param> /// <param name="myAuthor">myAuthor as an Author object</param> /// <param name="myTitle">myTitle as an Title object</param> /// <param name="myBookGenre">myBookGenre as BookGenre</param> /// <param name="myReturnDate">myReturnDate as DateTime</param> public Book(string myISBN, Author myAuthor, Title myTitle, BookGenre myBookGenre, DateTime myReturnDate) { _ISBN = myISBN; author = myAuthor; title = myTitle; bookGenre = myBookGenre; returnDate = myReturnDate; }
public Book(string title, string author, BookGenre genre, int numberOfPages, double price) { this.Title = title; this.Author = author; this.Genre = genre; this.NumberOfPages = numberOfPages; this.Price = price; }
public void AddBookGenre(int bookId, int genreId) { BookGenre bookGenre = new BookGenre(); bookGenre.BookId = bookId; bookGenre.GenreId = genreId; applicationDbContext.Add(bookGenre); applicationDbContext.SaveChanges(); }
public ActionResult EditBookGenre(BookGenre bookGenre, int?id) { if (ModelState.IsValid) { db.Entry(bookGenre).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("ViewBookGenre")); }
public ActionResult AddBookGenre(BookGenre bookGenre) { if (ModelState.IsValid) { db.BookGenre.Add(bookGenre); db.SaveChanges(); } return(RedirectToAction("ViewBookGenre")); }
public Book(string title, string author, BookGenre genre, double Price, DateTime publishedDate, int NumberOfPages) { this.Title = title; this.Author = author; this.genre = genre; this.Price = Price; this.PublishedDate = publishedDate; this.NumberOfPages = NumberOfPages; }
public Book(string title, string isbn, string author, string publisher, double price, BookGenre genre) { bookTitle = title; bookIsbn = isbn; bookAuthor = author; bookPublisher = publisher; bookPrice = price; bookGenre = genre; }
public Book(int id, string title, string author, int pages, BookGenre genre, DateTime date_of_publication) { Id = id; Title = title; Author = author; Pages = pages; Genre = genre; Date_of_publication = date_of_publication; State = new State(); }
public Book(string title, string author, BookGenre genre, double price, DateTime publishedDate, int numberOfPages) { this.BookId = SetBookId(); this.Title = title; this.Author = author; this.Genre = genre; this.Price = price; this.PublishedDate = publishedDate; this.NumberOfPages = numberOfPages; }
public Book(string title, List <int> authorID, string publisher, BookGenre genre, string isbn, string description, int lendingMonths = 1) : this() { Title = title; AuthorID = authorID; Publisher = publisher; ISBN = isbn; Description = description; Genre = genre; LendingMonths = lendingMonths; }
public void ShowBooksByGenre(BookGenre genre) { var res = queryFactory .ResolveQuery <BooksByGenreQuery>() .Execute(genre); foreach (var book in res) { Console.WriteLine($"{book.BookId}. {book.Title} - {book.Genre}"); } }
public static void SetGenres(BooksDataContext db, string bookArg) { int bookId; if (!int.TryParse(bookArg, out bookId)) { Console.WriteLine("Invalid book ID! Operation aborted!"); return; } var bookForUpdate = (from book in db.Books where book.BookID == bookId select book).SingleOrDefault(); if (bookForUpdate == null) { Console.WriteLine("No such book! Operation aborted!"); return; } Console.WriteLine("Found book: "); Console.WriteLine($"BookID: {bookForUpdate.BookID}"); Console.WriteLine($"Title: {bookForUpdate.Title}"); Console.WriteLine($"Description: {bookForUpdate.Description}"); Console.WriteLine($"Publisher: {bookForUpdate.Publisher}"); Console.WriteLine($"Pages: {bookForUpdate.Pages}"); Console.WriteLine($"ISBN: {bookForUpdate.ISBN}"); Console.WriteLine(); HashSet<int> genreIds = new HashSet<int>(); foreach (var genre in db.Genres) { Console.WriteLine($"{genre.GenreID} - {genre.Name}"); genreIds.Add(genre.GenreID); } Console.WriteLine("Please write IDs of genres you want to add, separated by comma or space"); int[] idsToAdd; try { idsToAdd = Console.ReadLine().Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray(); } catch (FormatException) { Console.WriteLine("Invalid ids format! Operation aborted!"); return; } bool allExist = true; foreach (var id in idsToAdd) { if (!genreIds.Contains(id)) { allExist = false; break; } } if (!allExist) { Console.WriteLine("Invalid ids format! Operation aborted!"); return; } foreach (var genreId in idsToAdd) { var newGenre = new BookGenre(); newGenre.GenreID = genreId; bookForUpdate.BookGenres.Add(newGenre); } try { db.SubmitChanges(); } catch (ChangeConflictException ex) { Console.WriteLine("Cannot update book genres! Operation exited with message:"); Console.WriteLine(ex.Message); return; } Console.WriteLine("Book genres updated successfully!"); }