diff --git a/docs/Tutorials/AspNetCore-Mvc/Part-I.md b/docs/Tutorials/AspNetCore-Mvc/Part-I.md index be915e1d8d..236f87bdaa 100644 --- a/docs/Tutorials/AspNetCore-Mvc/Part-I.md +++ b/docs/Tutorials/AspNetCore-Mvc/Part-I.md @@ -87,7 +87,7 @@ public class BookStoreDbContext : AbpDbContext 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: @@ -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: -![bookstore-books-table](../../images\bookstore-books-table.png) +![bookstore-books-table](../../images/bookstore-books-table.png) ### 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: -![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. @@ -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. -### 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 +

Books

+```` + +* 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... \ No newline at end of file diff --git a/docs/images/bookstore-add-index-page.png b/docs/images/bookstore-add-index-page.png new file mode 100644 index 0000000000..2452ca546e Binary files /dev/null and b/docs/images/bookstore-add-index-page.png differ diff --git a/docs/images/bookstore-localization-files.png b/docs/images/bookstore-localization-files.png new file mode 100644 index 0000000000..ca1da1c7ec Binary files /dev/null and b/docs/images/bookstore-localization-files.png differ diff --git a/docs/images/bookstore-menu-items.png b/docs/images/bookstore-menu-items.png new file mode 100644 index 0000000000..255defb707 Binary files /dev/null and b/docs/images/bookstore-menu-items.png differ diff --git a/samples/BookStore/Acme.BookStore.sln b/samples/BookStore/Acme.BookStore.sln index c12f7f345f..49f9115781 100644 --- a/samples/BookStore/Acme.BookStore.sln +++ b/samples/BookStore/Acme.BookStore.sln @@ -15,9 +15,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CA9AC87F-097 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{04DBDB01-70F4-4E06-B468-8F87850B22BE}" 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 -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 Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/samples/BookStore/src/Acme.BookStore.Domain/Localization/BookStore/en.json b/samples/BookStore/src/Acme.BookStore.Domain/Localization/BookStore/en.json index baa9fe753e..d2d707699b 100644 --- a/samples/BookStore/src/Acme.BookStore.Domain/Localization/BookStore/en.json +++ b/samples/BookStore/src/Acme.BookStore.Domain/Localization/BookStore/en.json @@ -2,6 +2,8 @@ "culture": "en", "texts": { "Menu:Home": "Home", + "Menu:BookStore": "Book Store", + "Menu:Books": "Books", "Welcome": "Welcome", "LongWelcomeMessage": "Welcome to the application. This is a startup project based on the ABP framework. For more information, visit abp.io." } diff --git a/samples/BookStore/src/Acme.BookStore.Domain/Localization/BookStore/tr.json b/samples/BookStore/src/Acme.BookStore.Domain/Localization/BookStore/tr.json index 5bf83ee7a8..48e849953b 100644 --- a/samples/BookStore/src/Acme.BookStore.Domain/Localization/BookStore/tr.json +++ b/samples/BookStore/src/Acme.BookStore.Domain/Localization/BookStore/tr.json @@ -2,6 +2,8 @@ "culture": "tr", "texts": { "Menu:Home": "Ana sayfa", + "Menu:BookStore": "Kitap Deposu", + "Menu:Books": "Kitaplar", "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." } diff --git a/samples/BookStore/src/Acme.BookStore.Web/Menus/BookStoreMenuContributor.cs b/samples/BookStore/src/Acme.BookStore.Web/Menus/BookStoreMenuContributor.cs index 84b965ef23..9600f04b3b 100644 --- a/samples/BookStore/src/Acme.BookStore.Web/Menus/BookStoreMenuContributor.cs +++ b/samples/BookStore/src/Acme.BookStore.Web/Menus/BookStoreMenuContributor.cs @@ -21,6 +21,11 @@ namespace Acme.BookStore.Menus var l = context.ServiceProvider.GetRequiredService>(); 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")) + ); } } } diff --git a/samples/BookStore/src/Acme.BookStore.Web/Pages/Books/Index.cshtml b/samples/BookStore/src/Acme.BookStore.Web/Pages/Books/Index.cshtml new file mode 100644 index 0000000000..97f9e9b240 --- /dev/null +++ b/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 + +

Books

\ No newline at end of file diff --git a/samples/BookStore/src/Acme.BookStore.Web/Pages/Books/Index.cshtml.cs b/samples/BookStore/src/Acme.BookStore.Web/Pages/Books/Index.cshtml.cs new file mode 100644 index 0000000000..6bd7bc6dce --- /dev/null +++ b/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() + { + + } + } +} \ No newline at end of file