public async Task <IActionResult> Edit(int id, [Bind("TakenBookId,ReaderId,BookId,DateIssue,ReturnDate,IsReturned")] TakenBook takenBook) { if (id != takenBook.TakenBookId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(takenBook); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TakenBookExists(takenBook.TakenBookId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BookId"] = new SelectList(_context.Books, "BookId", "BookId", takenBook.BookId); ViewData["ReaderId"] = new SelectList(_context.Readers, "ReaderId", "ReaderId", takenBook.ReaderId); return(View(takenBook)); }
public void TakenBook_CreatedTakenBook_BookValuesShouldBeEqualToGiven() { string expectedName = "name"; string expectedAuthor = "author"; string expectedCategory = "category"; string expectedLanguage = "language"; string ecpectedPublicationDate = "1999"; string expectedIsbn = "isbn"; Book book = new Book(expectedName, expectedAuthor, expectedCategory, expectedLanguage, ecpectedPublicationDate, expectedIsbn); string expectedReaderName = "name reader"; int expectedReaderBookCount = 1; Reader reader = new Reader(expectedReaderName); DateTime expectetReturnDate = Convert.ToDateTime("2021-05-16"); TakenBook takenBook = new TakenBook(book, expectetReturnDate, reader); string actualName = takenBook.Name; string actualAuthor = takenBook.Author; string actualCategory = takenBook.Category; string actualLanguage = takenBook.Language; string actualPublicationDate = takenBook.PublicationDate; string actualIsbn = takenBook.ISBN; DateTime actualReturnDate = takenBook.ReturnDate; string actualReaderName = takenBook.Reader.Name; int actualReaderBookCount = takenBook.Reader.BookCount; Assert.AreEqual(expectedName, actualName); Assert.AreEqual(expectedAuthor, actualAuthor); Assert.AreEqual(expectedCategory, actualCategory); Assert.AreEqual(expectedLanguage, actualLanguage); Assert.AreEqual(ecpectedPublicationDate, actualPublicationDate); Assert.AreEqual(expectedIsbn, actualIsbn); Assert.AreEqual(expectetReturnDate, actualReturnDate); Assert.AreEqual(expectedReaderName, actualReaderName); Assert.AreEqual(expectedReaderBookCount, actualReaderBookCount); }
public bool UpdateTakenBook(TakenBook updateTakenBook) { using (LibraryContext db = new LibraryContext()) { db.TakenBooks.AddOrUpdate(updateTakenBook); db.SaveChanges(); return(true); } }
public bool CreateTakenBook(TakenBook newTakenBook) { using (LibraryContext db = new LibraryContext()) { db.TakenBooks.Add(newTakenBook); db.SaveChanges(); return(true); } }
public void Get_IndexMoreOrEqualZeroAndLessThanCount_ExpectedIsEqualActual() { TakenBookRegister register = new TakenBookRegister(); Book book = new Book("name", "author", "category", "language", "1999", "123"); Reader reader = new Reader("Name"); TakenBook expected = new TakenBook(book, Convert.ToDateTime("2021-05-12"), reader); register.Add(expected); TakenBook actual = register.Get(0); Assert.AreEqual(expected, actual); }
public void Add_AddBookToRegister_AddedBookShouldBeEqualToGiven() { TakenBookRegister register = new TakenBookRegister(); Book book = new Book("name", "author", "category", "language", "1999", "123"); Reader reader = new Reader("Name"); TakenBook expected = new TakenBook(book, Convert.ToDateTime("2021-05-12"), reader); register.Add(expected); TakenBook actual = register.Get(0); Assert.AreEqual(expected, actual); }
public void Get_RegisterContainsBookWithCertainIsbn_ExpectedIsEqualActual() { TakenBookRegister register = new TakenBookRegister(); Book book = new Book("name", "author", "category", "language", "1999", "123"); Reader reader = new Reader("Name"); TakenBook expected = new TakenBook(book, Convert.ToDateTime("2021-05-12"), reader); register.Add(expected); TakenBook actual = register.Get("123"); Assert.AreEqual(expected, actual); }
public async Task <IActionResult> Create([Bind("TakenBookId,ReaderId,BookId,DateIssue,ReturnDate,IsReturned")] TakenBook takenBook) { if (ModelState.IsValid) { _context.Add(takenBook); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BookId"] = new SelectList(_context.Books, "BookId", "BookId", takenBook.BookId); ViewData["ReaderId"] = new SelectList(_context.Readers, "ReaderId", "ReaderId", takenBook.ReaderId); return(View(takenBook)); }
public void Remove_GivenBookIsbnNotEqualToOneInRegister_DoesNotRemove() { BookRegister register = new BookRegister(); Book book1 = new Book("name", "author", "category", "language", "1999", "123"); Book book2 = new Book("n", "a", "c", "l", "1999", "789"); Reader reader1 = new Reader("Name"); Reader reader2 = new Reader("N"); TakenBook takenBook = new TakenBook(book1, Convert.ToDateTime("2021-05-12"), reader1); TakenBook bookToRemove = new TakenBook(book2, Convert.ToDateTime("2021-05-12"), reader2); register.Add(takenBook); register.Remove(bookToRemove); register.Count().Should().Be(1); }
public ActionResult ReservedBook(int Id) { var takenBook = new TakenBook { BookId = Id, UserId = _libraryService.GetUserByLogin(User.Identity.Name).Id, //Здесь нужно поставить пользователя, который авторезирован IsReserved = true }; _libraryService.RemoveTakenBookByBookId(Id); _libraryService.CreateTakenBook(takenBook); return(RedirectToAction("ListFreeBooks")); }
public bool ReturnTakenBookById(int id) { var takenBook = GetTakenBookById(id); takenBook.DateReturn = DateTime.Now; takenBook.IsDeleted = true; UpdateTakenBook(takenBook); var newTakenBook = new TakenBook { BookId = takenBook.BookId, DateTake = DateTime.Now, UserId = 1 }; CreateTakenBook(newTakenBook); return(true); }
public bool CreateBook(Book newBook) { using (LibraryContext db = new LibraryContext()) { db.Books.Add(newBook); db.SaveChanges(); } var takenBook = new TakenBook { BookId = newBook.Id, DateTake = DateTime.Now, IsReserved = false, UserId = 1 }; CreateTakenBook(takenBook); return(true); }
// метод для выдачи книги public TakenBook TakeBook(int bookId, int userId) { var book = context.Books.Find(bookId); var user = context.Users.Find(userId); book.IsAvailable = false; var takenBook = new TakenBook { Book = book, BookId = bookId, User = user, UserId = userId, Date = DateTime.Now }; var tb = context.TakenBooks.Add(takenBook); context.SaveChanges(); return(tb); }