Ejemplo n.º 1
0
        public IActionResult Post([FromBody] Book book)
        {
            if (book == null)
            {
                return(BadRequest());
            }
            var createdBooks = _bookRepository.AddBooks(book);

            return(CreatedAtRoute("GetBooks", new { id = createdBooks.Id }, createdBooks));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            await _booksRepo.AddBooks(Book);

            Message = "Dodano pomyślnie";
            return(RedirectToPage("Index"));
        }
Ejemplo n.º 3
0
        public void ExecuteCommandOrExit(string command)
        {
            switch (command.ToUpper())
            {
            case "1":
                _bookRepository.AddBooks();
                break;

            case "2":
                _bookRepository.DeleteBooks(_clientRepository);
                break;

            case "3":
                ShowListOfBooks(SearchBy.ByName);
                break;

            case "4":
                ShowListOfBooks(SearchBy.ByTime);
                break;

            case "5":
                _bookRepository.BorrowBook(_clientRepository);
                break;

            case "6":
                ShowClientsList();
                break;

            case "7":
                ShowAllBooks();
                break;

            case "Q":
                exit = true;
                break;

            default:
                Console.WriteLine("Wrong Command!");
                break;
            }
            Console.WriteLine("Powrot");
            Console.ReadLine();
        }
Ejemplo n.º 4
0
        protected LibraryDTO GetBooksFromLibraryExpress(IUrlHttpClient urlHttpClient, IBookRepository bookRepository, BookFilter bookFilter)
        {
            try
            {
                var libraryRequest = GenerateLibraryBookRequest(bookFilter);

                //Go fetch from external service ExpressLibraryApi
                var libraryResponse = urlHttpClient.HttpGet(libraryRequest).Result;

                var libraryDto = ProcessExternalLibraryResponse(libraryResponse);

                if (libraryDto != null && libraryDto.Books != null && libraryDto.Books.Count > 0)
                {
                    try
                    {
                        var newLibraryDto = new LibraryDTO();

                        var ourbooks = bookRepository.AddBooks(libraryDto.Books);

                        newLibraryDto.Books      = ourbooks;
                        newLibraryDto.TotalBooks = ourbooks.Count;

                        return(newLibraryDto);
                    }
                    catch (Exception ex)
                    {
                        //TODO: Log this the exception information along with the method details to the database for Error tracing
                        //Allowing the exception be rethrown so that LOG4NET can log there is a problem on the api end point
                        return(null);
                    }
                }
                return(libraryDto);
            }
            catch (Exception ex)
            {
                //TODO: Log this the exception information along with the method details to the database for Error tracing
                //Allowing the exception be rethrown so that LOG4NET can log there is a problem on the api end point
                return(null);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Adds the books detail.
 /// </summary>
 /// <param name="bookStoreModel">The book store model.</param>
 /// <returns></returns>
 public int AddBooks(BookStoreModel bookStoreModel)
 {
     return(bookRepository.AddBooks(bookStoreModel));
 }