Пример #1
0
        public ActionResult RegisterBorrowing([FromBody] BorrowingRequest borrowingToRegister)
        {
            if (borrowingToRegister is null)
            {
                return(BadRequest());
            }
            if (!borrowingToRegister.BookId.HasValue || !borrowingToRegister.AccountId.HasValue)
            {
                return(BadRequest());
            }
            var book    = BookService.Read(borrowingToRegister.BookId.GetValueOrDefault());
            var account = AccountService.Read(borrowingToRegister.AccountId.GetValueOrDefault());

            if ((book is null) || (account is null))
            {
                return(BadRequest());
            }
            var justAdded = BorrowingService.Create(book.Title, account.Name);

            if (justAdded is null)
            {
                return(BadRequest($"The book {book.Title} is already borrowed."));
            }
            else
            {
                return(Ok(justAdded));
            }
        }
Пример #2
0
        public IActionResult TestGet()
        {
            AuthorizationLevelService.Create("Admin");
            AuthorizationLevelService.Create("Librarian");
            AuthorizationLevelService.Create("Client");

            CategoryService.Create("Scifi");
            CategoryService.Create("History");
            CategoryService.Create("Politics");
            CategoryService.Create("Humor");

            AccountService.Create("Von Neumann", "0123456789abcdf", "Admin");
            AccountService.Create("Guthenberg", "1415", "Librarian");
            AccountService.Create("Marilyn Monroe", "12345", "Client");
            AccountService.Create("Elvis Presley", "01114", "Client");
            AccountService.Create("Michael Jackson", "11111", "Client");

            BookService.CreateIfNotExist("Hector Servadac");
            BookCategoryService.Create("Hector Servadac", "Scifi", "Guthenberg");
            BookService.Create("Neuromancer");
            BookCategoryService.Create("Neuromancer", "Scifi", "Guthenberg");
            BookService.Create("Terminator");
            BookCategoryService.Create("Terminator", "Scifi", "Guthenberg");
            BookService.Create("Diplomacy");
            BookCategoryService.Create("Diplomacy", "Politics", "Guthenberg");
            BookService.Create("Before Crisis");
            BookCategoryService.Create("Before Crisis", "History", "Guthenberg");

            BorrowingService.Create("Hector Servadac", "Marilyn Monroe");
            BorrowingService.Create("Terminator", "Marilyn Monroe");
            BorrowingService.Create("Diplomacy", "Michael Jackson");

            var borrowing = BorrowingService.ReadByTitle("Hector Servadac");

            BorrowingService.Delete(borrowing);

            return(View("Login"));
        }