Browse Source

Added books page.

pull/318/head
Halil ibrahim Kalkan 8 years ago
parent
commit
603d17737c
  1. 61
      docs/Tutorials/AspNetCore-Mvc/Part-I.md
  2. BIN
      docs/images/bookstore-add-index-page.png
  3. BIN
      docs/images/bookstore-localization-files.png
  4. BIN
      docs/images/bookstore-menu-items.png
  5. 4
      samples/BookStore/Acme.BookStore.sln
  6. 2
      samples/BookStore/src/Acme.BookStore.Domain/Localization/BookStore/en.json
  7. 2
      samples/BookStore/src/Acme.BookStore.Domain/Localization/BookStore/tr.json
  8. 5
      samples/BookStore/src/Acme.BookStore.Web/Menus/BookStoreMenuContributor.cs
  9. 6
      samples/BookStore/src/Acme.BookStore.Web/Pages/Books/Index.cshtml
  10. 12
      samples/BookStore/src/Acme.BookStore.Web/Pages/Books/Index.cshtml.cs

61
docs/Tutorials/AspNetCore-Mvc/Part-I.md

@ -87,7 +87,7 @@ public class BookStoreDbContext : AbpDbContext<BookStoreDbContext>
Startup template uses [EF Core Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/) to create and maintain the database schema. Open the **Package Manager Console (PMC)**, select the `Acme.BookStore.EntityFrameworkCore` as the **default project** and execute the following command: Startup template uses [EF Core Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/) to create and maintain the database schema. Open the **Package Manager Console (PMC)**, select the `Acme.BookStore.EntityFrameworkCore` as the **default project** and execute the following command:
![bookstore-pmc-add-book-migration](../../images\bookstore-pmc-add-book-migration.png) ![bookstore-pmc-add-book-migration](../../images/bookstore-pmc-add-book-migration.png)
This will create a new migration class inside the `Migrations` folder. Then execute the `Update-Database` command to update the database schema: This will create a new migration class inside the `Migrations` folder. Then execute the `Update-Database` command to update the database schema:
@ -99,7 +99,7 @@ PM> Update-Database
`Update-Database` command created the `Books` table in the database. Enter a few sample rows, so you can show them on the page: `Update-Database` command created the `Books` table in the database. Enter a few sample rows, so you can show them on the page:
![bookstore-books-table](../../images\bookstore-books-table.png) ![bookstore-books-table](../../images/bookstore-books-table.png)
### Create the Application Service ### Create the Application Service
@ -215,7 +215,7 @@ acme.bookStore.book.getList({}).done(function (result) { console.log(result); })
Running this code produces such an output: Running this code produces such an output:
![bookstore-test-js-proxy-getlist](D:\Github\abp\docs\images\bookstore-test-js-proxy-getlist.png) ![bookstore-test-js-proxy-getlist](../../images/bookstore-test-js-proxy-getlist.png)
You can see the **book list** returned from the server. You can see the **book list** returned from the server.
@ -240,15 +240,66 @@ successfully created the book with id: f3f03580-c1aa-d6a9-072d-39e75c69f5c7
Check the `books` table in the database to see the new book row. You can also try `get`, `update` and `delete` functions. Check the `books` table in the database to see the new book row. You can also try `get`, `update` and `delete` functions.
### Create the Book List Page ### Create the Books Page
TODO... It's time to create something visible! Instead of classic MVC, we will use the new [Razor Pages UI](https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/razor-pages-start) approach which is recommended by Microsoft.
Create a new `Books` folder under the `Pages` folder of the `Acme.BookStore.Web` project and add a new Razor Page named `Index.html`:
![bookstore-add-index-page](../../images/bookstore-add-index-page.png)
Open the `Index.cshtml` and change the content as shown below:
````html
@page
@using Acme.BookStore.Pages.Books
@inherits Acme.BookStore.Pages.BookStorePageBase
@model IndexModel
<h2>Books</h2>
````
* This page inherits from the `BookStorePageBase` class which comes with the startup template and provides some shared properties/methods used by all pages.
#### Add Books Page to the Main Menu
Open the `BookStoreMenuContributor` class in the `Menus` folder and add the following code to the end of the `ConfigureMainMenuAsync` method:
````c#
context.Menu.AddItem(
new ApplicationMenuItem("BooksStore", l["Menu:BookStore"])
.AddItem(new ApplicationMenuItem("BooksStore.Books", l["Menu:Books"], url: "/Books"))
);
````
#### Localizing the Menu Items
Localization texts are located under the `Localization/BookStore` folder of the `Acme.BookStore.Domain` project:
![bookstore-localization-files](../../images/bookstore-localization-files.png)
Open the `en.json` file and add localization texts for `Menu:BookStore` and `Menu:Books` keys:
````json
{
"culture": "en",
"texts": {
//...
"Menu:BookStore": "Book Store",
"Menu:Books": "Books"
}
}
````
* ABP's localization system is built on [ASP.NET Core's standard localization](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization) system and extends it in many ways. See the [localization document](../../Localization.md) for details.
* Localization key names are arbitrary, you can set any name. We prefer to add `Menu` namespace for menu items to distinguish from other texts. If a text is not defined in the localization file, it **fallbacks** to the localization key (ASP.NET Core's standard behavior).
Run the application and see the menu items are added to the top bar:
![bookstore-menu-items](../../images/bookstore-menu-items.png)
When you click to the Books menu item, you are redirected to the new Books page.
#### Book List
TODO...

BIN
docs/images/bookstore-add-index-page.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

BIN
docs/images/bookstore-localization-files.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
docs/images/bookstore-menu-items.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

4
samples/BookStore/Acme.BookStore.sln

@ -15,9 +15,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CA9AC87F-097
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{04DBDB01-70F4-4E06-B468-8F87850B22BE}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{04DBDB01-70F4-4E06-B468-8F87850B22BE}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Acme.BookStore.Application.Tests", "test\Acme.BookStore.Application.Tests\Acme.BookStore.Application.Tests.csproj", "{50B2631D-129C-47B3-A587-029CCD6099BC}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Acme.BookStore.Application.Tests", "test\Acme.BookStore.Application.Tests\Acme.BookStore.Application.Tests.csproj", "{50B2631D-129C-47B3-A587-029CCD6099BC}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Acme.BookStore.Web.Tests", "test\Acme.BookStore.Web.Tests\Acme.BookStore.Web.Tests.csproj", "{5F1B28C6-8D0C-4155-92D0-252F7EA5F674}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Acme.BookStore.Web.Tests", "test\Acme.BookStore.Web.Tests\Acme.BookStore.Web.Tests.csproj", "{5F1B28C6-8D0C-4155-92D0-252F7EA5F674}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

2
samples/BookStore/src/Acme.BookStore.Domain/Localization/BookStore/en.json

@ -2,6 +2,8 @@
"culture": "en", "culture": "en",
"texts": { "texts": {
"Menu:Home": "Home", "Menu:Home": "Home",
"Menu:BookStore": "Book Store",
"Menu:Books": "Books",
"Welcome": "Welcome", "Welcome": "Welcome",
"LongWelcomeMessage": "Welcome to the application. This is a startup project based on the ABP framework. For more information, visit abp.io." "LongWelcomeMessage": "Welcome to the application. This is a startup project based on the ABP framework. For more information, visit abp.io."
} }

2
samples/BookStore/src/Acme.BookStore.Domain/Localization/BookStore/tr.json

@ -2,6 +2,8 @@
"culture": "tr", "culture": "tr",
"texts": { "texts": {
"Menu:Home": "Ana sayfa", "Menu:Home": "Ana sayfa",
"Menu:BookStore": "Kitap Deposu",
"Menu:Books": "Kitaplar",
"Welcome": "Hoşgeldiniz", "Welcome": "Hoşgeldiniz",
"LongWelcomeMessage": "Uygulamaya hoşgeldiniz. Bu, ABP framework'ü üzerine bina edilmiş bir başlangıç projesidir. Daha fazla bilgi için abp.io adresini ziyaret edebilirsiniz." "LongWelcomeMessage": "Uygulamaya hoşgeldiniz. Bu, ABP framework'ü üzerine bina edilmiş bir başlangıç projesidir. Daha fazla bilgi için abp.io adresini ziyaret edebilirsiniz."
} }

5
samples/BookStore/src/Acme.BookStore.Web/Menus/BookStoreMenuContributor.cs

@ -21,6 +21,11 @@ namespace Acme.BookStore.Menus
var l = context.ServiceProvider.GetRequiredService<IStringLocalizer<BookStoreResource>>(); var l = context.ServiceProvider.GetRequiredService<IStringLocalizer<BookStoreResource>>();
context.Menu.Items.Insert(0, new ApplicationMenuItem("BookStore.Home", l["Menu:Home"], "/")); context.Menu.Items.Insert(0, new ApplicationMenuItem("BookStore.Home", l["Menu:Home"], "/"));
context.Menu.AddItem(
new ApplicationMenuItem("BooksStore", l["Menu:BookStore"])
.AddItem(new ApplicationMenuItem("BooksStore.Books", l["Menu:Books"], url: "/Books"))
);
} }
} }
} }

6
samples/BookStore/src/Acme.BookStore.Web/Pages/Books/Index.cshtml

@ -0,0 +1,6 @@
@page
@using Acme.BookStore.Pages.Books
@inherits Acme.BookStore.Pages.BookStorePageBase
@model IndexModel
<h2>Books</h2>

12
samples/BookStore/src/Acme.BookStore.Web/Pages/Books/Index.cshtml.cs

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Acme.BookStore.Pages.Books
{
public class IndexModel : PageModel
{
public void OnGet()
{
}
}
}
Loading…
Cancel
Save