//[ValidateAntiForgeryToken] public IActionResult Create(string memberId, string movieId, DateTime startDate, DateTime endDate) { ObjectId memberOId = new ObjectId(memberId); ObjectId movieOId = new ObjectId(movieId); Movie movie = MovieRepository.GetMovieById(movieOId); Loan loan = CreateLoan(memberOId, movie.Id, startDate, endDate); int copiesRemaining = CheckLoansToCopies.Movie(movie.Id, movie.NumberOfCopies, startDate, endDate); if (copiesRemaining > 0) { MovieLoanRepository.InsertMovie(loan); return(Redirect("/MovieLoan")); } else if (copiesRemaining <= 0) { SerilogMVC(movie); string errorMessage = "No availiable copies at that date. Please try an other one"; MovieLoanModel movieLoanModel = new MovieLoanModel(); movieLoanModel.ErrorMessage = errorMessage; return(View(movieLoanModel)); } return(Redirect("/MovieLoan")); }
public void GetTheRightNumberOfCopiesTest(int selectedBook, int i, int expected) { DateTime date1 = DateTime.Today; DateTime date = date1.AddYears(1); Book book = SelectBookById.ValidateSelectedBook(selectedBook, i); int result = CheckLoansToCopies.Book(book.Id, expected, date1, date); Assert.AreEqual(expected, result); }
public IActionResult Create(string memberId, string bookId, DateTime startDate, DateTime endDate) { ObjectId memberOId = new ObjectId(memberId); ObjectId bookOId = new ObjectId(bookId); Book book = BookRepository.GetBookById(bookOId); int copiesRemaining = CheckLoansToCopies.Book(book.Id, book.NumberOfCopies, startDate, endDate); if (copiesRemaining > 0) { Loan loan = CreateLoan(memberOId, book.Id, startDate, endDate); BookLoanRepository.InsertBookLoan(loan); } else if (copiesRemaining <= 0) { string errorMessage = "No availiable copies at that date. Please try an other one"; BookLoanModel bookLoanModel = new BookLoanModel(); bookLoanModel.ErrorMessage = errorMessage; return(View(bookLoanModel)); } return(Redirect("/BookLoan")); }