Book Image

ASP.NET Core and Angular 2

By : Valerio De Sanctis
Book Image

ASP.NET Core and Angular 2

By: Valerio De Sanctis

Overview of this book

<p>Writing code is about striking a balance between maintainability and productivity—how quickly you can write it against how much more you have to write in the future. This is a guide to doing just that by combining the impressive capabilities of ASP.NET Core and Angular 2. It shows you how to successfully manage an API and use it to support and power a dynamic single-page application.</p> <p>We'll show you how to construct your data model and manage routing and redirects before wrapping it up and styling it, all with the help of ASP.NET and Angular 2. You'll also learn how to optimize your application for SEO, check and secure any vulnerabilities, implement a viable authentication mechanism and, last but not least, use the proper tools and strategies for successful deployment. From readable URIs to OData retrieval and authentication patterns, we'll make sure you have all the technical knowledge you need and, more importantly, bring it all together so you can focus on what's important: a high-quality application that performs for users.</p>
Table of Contents (16 chapters)
ASP.NET Core and Angular 2
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Seeding the database


We're now ready to seed our database. Since we hooked the DbSeeder.SeedAsync to the Startup class, it'll be as easy as hitting F5 and letting the application work its magic. If we have done everything correctly, our database should be populated in no time. In order to check that, we can:

  1. Open the Server Object Explorer panel.

  2. Expand the nodes up to our OpenGameList database.

  3. Right-click on the dbo.Items table and select View Data.

Upon doing that, we should see something like the following:

Updating the ItemsController

Last but not least, we need to modify our ItemsController to use the ApplicationDbContext to retrieve data, getting rid of our dummy data provider once and for all.

In order to do that, the first thing we need to do is find an efficient way to map each Item entity to a corresponding ItemViewModel object, as our new data provider won't generate them anymore. We can achieve such a result in a number of ways, including the following:

  • Adding a Helper method, such...