Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4ebea16

Browse files
Nitish KaushikNitish Kaushik
Nitish Kaushik
authored and
Nitish Kaushik
committed
get all books
1 parent 7b31dbb commit 4ebea16

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

‎Webgentle.BookStore/Webgentle.BookStore/Controllers/BookController.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public BookController(BookRepository bookRepository)
1717
_bookRepository = bookRepository;
1818
}
1919

20-
public ViewResult GetAllBooks()
20+
public asyncTask<ViewResult> GetAllBooks()
2121
{
22-
var data = _bookRepository.GetAllBooks();
22+
var data = await_bookRepository.GetAllBooks();
2323

2424
return View(data);
2525
}

‎Webgentle.BookStore/Webgentle.BookStore/Repository/BookRepository.cs‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Microsoft.EntityFrameworkCore;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Threading.Tasks;
@@ -35,9 +36,27 @@ public async Task<int> AddNewBook(BookModel model)
3536

3637
}
3738

38-
public List<BookModel> GetAllBooks()
39+
public asyncTask<List<BookModel>> GetAllBooks()
3940
{
40-
return DataSource();
41+
var books = new List<BookModel>();
42+
var allbooks = await _context.Books.ToListAsync();
43+
if (allbooks?.Any() == true)
44+
{
45+
foreach (var book in allbooks)
46+
{
47+
books.Add(new BookModel()
48+
{
49+
Author = book.Author,
50+
Category = book.Category,
51+
Description = book.Description,
52+
Id = book.Id,
53+
Language = book.Language,
54+
Title = book.Title,
55+
TotalPages = book.TotalPages
56+
});
57+
}
58+
}
59+
return books;
4160
}
4261

4362
public BookModel GetBookById(int id)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /