Naylor | ASP.NET MVC with Entity Framework and CSS | E-Book | www2.sack.de
E-Book

E-Book, Englisch, 628 Seiten

Naylor ASP.NET MVC with Entity Framework and CSS


1. ed
ISBN: 978-1-4842-2137-2
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark

E-Book, Englisch, 628 Seiten

ISBN: 978-1-4842-2137-2
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark



This book will teach readers how to build and deploy a fully working example retail website using Microsoft ASP.NET MVC and Entity Framework technologies and recommendations. This book contains several solutions to real world issues that developers will frequently encounter.
Whether you are a novice developer or an experienced .NET developer wishing to learn more about MVC and Entity Framework, author Lee Naylor will teach you how to develop a detailed database driven example website using Microsoft ASP.NET and Entity Framework Code First with fully explained code examples including:
•Filtering and Searching Related Data using Linq•Using code first migrations to automatically update the database plus seeding data from code•How to use Visual Studio Scaffolding views and controllers•Manage CRUD operations including model binding as recommended by Microsoft and dealing with cascading deletions correctly•Input and data validation using Attributes•Sorting and paging through data and routing for friendly URL formats•Authorization and Authentication using Microsoft Identity v2 by making use of Microsoft example code including correct use of redirection after login and registration•Advanced techniques including managing data concurrency conflicts and using two database contexts•Asynchronous database access and paging•Azure deployment using Code First Migrations, remote debugging and viewing/editing your remote data•CSS Styling including animation and media queries
What You Will Learn:
•Get up and running quickly with ASP.NET MVC and Entity Framework building a complex web site to display and manage several related entities•How to integrate Identity code into a project•Advanced topics including: Asynchronous database access and managing data conflicts•Working with Microsoft Azure including remote debugging and database access•CSS skills including animations and media queries for use with tablet or mobile/cell phone devices
Who This Book Is For:
People wanting to learn ASP.NET MVC and Entity Framework ranging from novice developers new to the subject through to more experienced ASP.NET web forms developers looking to migrate from web forms to MVC and Entity Framework. The book assumes some programming knowledge such as object-oriented programming concepts and a basic knowledge of C#.

Lee Naylor has fifteen years experience as a software engineer with experience in Finance (Banking and Accounting), Retail, Automotive and Gaming/Gambling. His current areas of expertise are ASP.NET MVC, Entity Framework, Front End Development with CSS, JavaScript and JQuery. In the past he has worked with several technologies including Classic ASP, VB, Access, Java, Oracle, Unix and search engine software such as Google Search Appliances and Autonomy/Verity. He is also experienced in Project and Team Management, mentoring/teaching others and understand all aspects of Software Projects from proposals and budgeting through analysis, estimations, planning, development, testing, UAT, and release management.

Naylor ASP.NET MVC with Entity Framework and CSS jetzt bestellen!

Autoren/Hrsg.


Weitere Infos & Material


1;Contents at a Glance;6
2;Contents;8
3;About the Author;20
4;About the Technical Reviewer;22
5;Acknowledgments;24
6;Introduction;26
7;Chapter 1: Building a Basic MVC Web Site;27
7.1;MVC and ASP.NET MVC;27
7.2;Entity Framework and Code First;28
7.2.1;Using Code First with an Existing Database;28
7.3;Software Required for Web Site Development;28
7.4;Creating the Project;28
7.4.1;Viewing the Web Site;31
7.4.2;How the Home Page Works;32
7.4.3;The About and Contact Pages and ViewBag;33
7.4.4;Routing: How the Web Site Knows Which Controllers and Methods to Request;34
7.4.4.1;Using the Optional URL ID Parameter;35
7.4.5;The Purpose of the Layout Page;36
7.5;Summary;38
8;Chapter 2: Creating Views, Controllers, and a Database from Model Classes;39
8.1;Adding the Model Classes;39
8.2;Adding a Database Context;41
8.3;Specifying a Connection String;41
8.4;Adding Controllers and Views;42
8.4.1;Adding a Category Controller and Views;42
8.4.2;Examining the CategoriesController Class and Methods;43
8.4.3;Examining the Category Views;47
8.4.3.1;The Categories Index View;47
8.4.3.2;Category Details View;49
8.4.3.3;The Category Create View;50
8.4.3.4;The Category Edit View;53
8.4.3.5;The Category Delete View;54
8.4.4;Adding a Product Controller and Views;55
8.4.4.1;Examining the Product Controller and Views;56
8.5;Using the New Product and Category Views;57
8.5.1;Examining the Newly Created BabyStore Database;58
8.5.2;Adding Some Data Using the Views;60
8.5.3;Changing the Way the Category and Product Name Properties are Displayed Using DataAnnotations;62
8.5.3.1;Splitting DataAnnotations into Another File Using MetaDataType;64
8.6;A Simple Query: Sorting Categories Alphabetically;65
8.7;Filtering Products by Category: Searching Related Entities Using Navigational Properties and Include;66
8.8;Summary;68
9;Chapter 3: Searching, Advanced Filtering, and View Models;69
9.1;Adding Product Search;69
9.1.1;Updating the Controller for Product Searching;69
9.1.2;Testing Product Search;70
9.1.3;Adding a Search Box to the Main Site Navigation Bar;71
9.1.4;How to Style Using Bootstrap;73
9.2;Filtering the Search Results by Category Using ViewBag;74
9.2.1;Updating the ProductsController Index Method to Filter by Category;75
9.2.2;Adding the Filter to the Products Index Page;75
9.3;Using a View Model for More Complex Filtering;78
9.3.1;Creating a View Model;78
9.3.2;Updating the ProductsController Index Method to Use the View Model;80
9.3.3;Modifying the View to Display the New Filter Using the View Model;81
9.4;Summary;84
10;Chapter 4: More Advanced Data Management;85
10.1;Deleting an Entity Used as a Foreign Key;85
10.2;Enabling Code First Migrations and Seeding the Database with Data;87
10.2.1;Enabling Code First Migrations;87
10.2.2;Seeding the Database with Test Data;90
10.2.3;Creating the Database Using the Initial Database Migration;92
10.3;Adding Data Validation and Formatting Constraints to Model Classes;95
10.3.1;Adding Validation and Formatting to the Category Class;96
10.3.2;Adding Formatting and Validation to the Product Class;101
10.3.3;How Validation Works;105
10.4;Summary;108
11;Chapter 5: Sorting, Paging, and Routing;109
11.1;Sorting Products by Price;109
11.1.1;Adding Sorting to the Products Index View;111
11.2;Adding Paging;115
11.2.1;Installing PagedList.Mvc;116
11.2.2;Updating the View Model and Controller for Paging;116
11.2.3;Updating the Products Index View for Paging;118
11.3;Routing;121
11.3.1;Adding Routes;122
11.3.2;Using Routes in Forms;129
11.3.3;Using a Route in a Hyperlink;130
11.4;Setting a Project Start URL;130
11.5;Summary;131
12;Chapter 6: Managing Product Images: Many-to-Many Relationships;132
12.1;Creating Entities to Store Image Filenames;132
12.2;Uploading Images;133
12.2.1;Defining Reusable Constants;133
12.2.2;Adding a ProductImage Controller and Views;135
12.2.3;Updating the ProductImagesController Class for File Uploads;136
12.2.4;Updating the View;139
12.2.5;Testing File Uploads;141
12.2.6;Checking for Unique Records Using Entity Framework;143
12.2.7;Allowing Multiple File Uploads;147
12.2.7.1;Updating the ProductImagesController Class for Multiple File Uploads;147
12.2.7.2;Updating the Upload View for Multiple File Uploads;154
12.2.7.3;Testing Multiple File Uploads;154
12.2.8;Working with the DbContext Object and Entity States;156
12.3;Viewing SQL Generated by Entity Framework;159
12.4;Performance Considerations When Using db.SaveChanges();161
12.5;Dealing with Maximum Request Length Exceeded Errors;162
12.5.1;Upping the Allowed Maximum Request Size;162
12.5.2;Adding a Custom Error Page for Maximum Request Length Exceeded Errors;163
12.6;Associating Images with a Product;165
12.6.1;Adding a Many-to-Many Relationship with Payload;165
12.6.2;Adding Images to a New Product;167
12.6.2.1;Creating a View Model for Product Creation and Editing;168
12.6.2.2;Specifying a Fixed Number of Images per Product;169
12.6.2.3;Updating the ProductsController to Add Images to a New Product;169
12.6.2.4;Updating the Product Create View;170
12.6.2.5;Updating the HttpPost Version of the ProductsController Create Method: Manual Model Binding with a View Model;173
12.6.2.6;Displaying Images in Product Details;175
12.6.2.7;Testing Product Creation with Images;177
12.6.3;Displaying Images in Search Results;179
12.6.4;Editing a Product’s Images;182
12.6.4.1;Updating the GET Version of the ProductController’s Edit Method;182
12.6.4.2;Updating the Product Edit View;184
12.6.4.3;Updating the ProductsController HttpPost Edit Method: Performing Model Binding Using TryUpdateModel;186
12.6.4.4;Testing Product Image Editing;191
12.6.5;Deleting Images and Products;192
12.6.5.1;Testing Image Deletion;194
12.6.6;Seeding the Database with Image Data;196
12.7;Updating Image Editing, Details, and Index Views;203
12.8;Creating a Partial View for Creating and Editing Products;204
12.9;Summary;208
13;Chapter 7: Authentication and Authorization Using ASP.NET Identity;209
13.1;Examining the Automatically Created BabyStore Project Identity Code and Database;210
13.2;Working with Roles;213
13.2.1;Adding a Role Manager;213
13.2.2;Creating an Admin User and Admin Role Whenever the Identity Database Is Created: Using a Database Initializer;214
13.2.3;Logging In as the Admin User;216
13.2.4;Adding a Roles View Model and RolesAdminController;217
13.2.5;Displaying All Roles;220
13.2.6;Adding Authorization at a Controller Class Level;221
13.2.7;Displaying Role Details;222
13.2.8;Creating a Role;224
13.2.9;Fixing the Navigation Bar Style Issues;227
13.2.10;Editing a Role;228
13.2.11;Deleting a Role;231
13.3;Adding a Basic Admin Controller and View;234
13.3.1;Adding Authorization to the Admin Controller and Admin Link;235
13.4;Working with Users;237
13.4.1;Adding Extra Properties for a User;237
13.4.2;Working with Two Database Contexts: Updating the Identity Database for the New User Properties;239
13.4.3;Updating the Admin User Creation Code for the New User Fields;242
13.4.4;Creating a Users Role on Database Creation;244
13.4.5;Adding a UsersAdminController;246
13.4.6;Displaying All Users;247
13.4.7;Displaying User Details;249
13.4.7.1;Using a Display Template;253
13.4.8;Creating a New User as Admin;255
13.4.8.1;Using an Editor Template;260
13.4.9;Editing a User as Admin;266
13.4.10;Dealing with Deleting Users;274
13.4.11;User Self-Registration;275
13.4.12;Allowing a User to View Personal Details;284
13.4.13;Allowing Users to Edit Personal Details;288
13.4.14;Allowing Users to Reset Their Passwords;295
13.4.15;Managing Password Complexity;297
13.5;Adding Authorization for Product and Category Administration;297
13.5.1;Adding Authorization to Categories;297
13.5.2;Adding Authorization to Products;300
13.6;Improving Redirection after Logging In or Registration;302
13.6.1;Redirecting Correctly After an Unsuccessful Then Successful Log In Attempt;302
13.6.2;Always Redirecting to the Previous Page after Log In;303
13.6.3;Always Redirecting to the Previous Page After Registration;304
13.7;Summary;308
14;Chapter 8: Creating a Shopping Basket;309
14.1;Adding a BasketLine Entity;309
14.2;Adding Basket Logic;311
14.3;Adding a Basket View Model;327
14.4;Adding a Basket Controller;328
14.5;Adding a Basket Index View;331
14.6;Allowing a User to Add to Basket;335
14.7;Updating the Basket: Model Binding to a List or an Array;339
14.8;Deleting a Line or Product from the Basket;344
14.9;Displaying a Basket Summary;348
14.10;Migrating a Basket When a User Logs In or Registers;351
14.10.1;Migrating the Basket Upon Login;351
14.10.2;Migrating the Basket Upon Registration;354
14.11;Summary;356
15;Chapter 9: Checkout: Creating and Viewing Orders;357
15.1;Modeling Orders;357
15.2;Creating Sample Order Data and Updating the Database;359
15.3;Displaying Order Data;362
15.3.1;Adding an OrdersController Class;362
15.3.2;Displaying a List of Orders;363
15.3.3;Displaying Order Details;366
15.4;Placing an Order;369
15.4.1;Creating an Order for Review;369
15.4.2;Displaying an Order for Review;370
15.4.3;Saving an Order to the Database;375
15.5;Updating Product Deletion to Avoid Foreign Key Conflicts;378
15.6;Adding Links to the Orders Index View;379
15.7;Searching and Sorting Orders;380
15.7.1;Orders Text Searching;380
15.7.2;Searching Orders by Date;383
15.7.3;Sorting Orders;387
15.8;Summary;394
16;Chapter 10: Advanced Scenarios and Common Workarounds;395
16.1;Asynchronous Database Access;395
16.1.1;A Simple Asynchronous Example: Adding Best Sellers to the Home Page;395
16.1.2;Adding Asynchronous Paging;400
16.1.2.1;Making Asynchronous Paging Reusable with an Extension Method;402
16.1.2.2;Adding Page Links to the View and Building an Html Helper;404
16.2;Dealing with Concurrent Database Updates;415
16.2.1;Warning Users When the Values They are Editing Have Been Changed by Another User;415
16.2.2;Checking for Conflicts on Deletion;422
16.3;Running Raw SQL Queries via Entity Framework;425
16.4;Adding Custom Error Pages to the Site;426
16.5;Common Entity Framework Problems and Workarounds;428
16.5.1;Cannot Attach the File Filepath\DatabaseName.mdf as Database “DatabaseName”;428
16.5.1.1;Cause;428
16.5.1.2;Workaround;428
16.5.2;Code First Migrations Become Out of Order or No Longer Run Correctly;428
16.5.2.1;Cause;428
16.5.2.2;Workaround;428
16.5.3;You Want to Roll Back a Migration;429
16.5.3.1;Cause;429
16.5.3.2;Workaround;429
16.6;Summary;429
17;Chapter 11: Using Entity Framework Code First with an Existing Database;430
17.1;Create a Database to Use with Code First;430
17.2;Setting Up a New Project and Generating a Code First Data Model from the Database;436
17.2.1;Setting Up a Controller and Views to View the Data;443
17.3;Updating the Existing Database Using Code First Migrations;445
17.4;Summary;449
18;Chapter 12: Introduction to ASP.NET Core v1.0 (MVC6 and EF 7);450
18.1;Creating an ASP.NET Core v1.0 MVC Project;450
18.1.1;Adding Product and Category Models;453
18.1.2;Adding a Database Context;454
18.1.3;Seeding the Database with Test Data;454
18.1.4;Configuring the Connection String for the Database;455
18.1.5;Configuring the Project to Use the SeedData Class and StoreContext;456
18.1.6;Using Migrations to Create the Database;457
18.1.7;Adding Controllers and Views;457
18.1.8;Viewing the Data in the Web Site;460
18.1.9;Correcting Bugs with the Scaffolding Generated Code;462
18.2;Summary;463
19;Chapter 13: Deploying to Azure;464
19.1;Preparing to Deploy to Azure;464
19.1.1;Changing from Using a Database Initializer to using a Code First Migrations Seed Method;464
19.1.2;Setting Up Azure;467
19.2;Deploying to Azure from Visual Studio;472
19.2.1;Configuring Database Publishing;475
19.2.2;Redeploying Code Changes to Azure;481
19.3;Remote Debugging an Azure Web Application;483
19.4;Viewing and Editing an Azure Database with Visual Studio;485
19.5;Connection Resiliency When Using Azure;487
19.6;Summary;488
20;Chapter 14: Restyling the Web Site: An Introduction;489
20.1;CSS: The Basics;490
20.1.1;Styles;490
20.1.2;Stylesheets;490
20.1.3;Selectors;490
20.1.3.1;Group Selectors;491
20.1.3.2;Descendant Selectors;491
20.1.3.3;Sibling Selectors;491
20.1.4;Inheritance;491
20.1.5;Cascading;492
20.1.6;The Box Model;493
20.1.6.1;Borders;493
20.1.6.2;Margins;493
20.1.6.3;Padding;494
20.1.6.4;Inline and Block Display;494
20.1.7;Putting It Together: Visualizing the Box Model;494
20.1.7.1;Viewing the Box Model;496
20.2;Updating the BabyStore Site to Use Your Own Stylesheet;498
20.2.1;Using a CSS Reset;501
20.2.2;Adding Basic Formatting;504
20.2.3;Fading In Each Page;505
20.3;Summary;506
21;Chapter 15: Styling the Home Page;507
21.1;Styling the Footer;507
21.1.1;Using Line Height to Vertically Align Text;508
21.1.2;Rounding Corners;509
21.2;Styling the Home Page Headings by Using Font Weights and em Values for Font-Size;510
21.3;Introducing Float for Displaying Images Next to One Another;511
21.3.1;Using Clear After a Floated Element;512
21.4;Styling the Images;513
21.5;Basic Link Styling;515
21.6;Styling a Hyperlink to Look Like a Button;517
21.7;Removing an Element from the Page Flow Using CSS;520
21.8;Summary;521
22;Chapter 16: Styling Forms, Grid Layouts, and Tables;522
22.1;Styling the Categories Index Page;522
22.1.1;Adding Space Between Table Cells;523
22.1.2;Styling the Links;524
22.2;Styling the Category Edit Form;526
22.2.1;Adding Vertical Space Using Margins;527
22.2.2;Adding a Grid Layout;528
22.2.3;Styling Labels and Text Boxes;530
22.2.4;Revisiting the Grid System: Adding Blank Columns Using Margins;531
22.2.5;Styling Buttons;532
22.2.6;Styling the Cursor;533
22.2.7;Styling Error Messages;534
22.2.7.1;Changing the Flow of the Page Using the Display Property;535
22.3;Styling the Other Forms in the Site;535
22.3.1;Forcing Inheritance;536
22.3.2;Aligning Text;539
22.3.3;Box-Sizing;541
22.3.3.1;Using Line-Height with Box-Sizing:Border-Box;544
22.3.4;Vertically Aligning Something with Another Element Containing Text;545
22.4;Styling Definition Lists;547
22.5;Styling Tables;550
22.6;Styling the Paging Links;554
22.7;A Sibling Selector Example: Styling the Create New Links;556
22.8;Summary;557
23;Chapter 17: Advanced CSS;558
23.1;Styling the Navigation Bar;558
23.1.1;Transforming the Navigation Bar Content to Display Horizontally;560
23.1.2;Moving Elements Using Positioning;563
23.1.3;Styling Text;565
23.1.3.1;Adding a Shadow to Text;566
23.1.3.2;Styling Letters and Lines of Text Using CSS;566
23.1.4;Adding Images Using CSS;568
23.1.4.1;Positioning a Background Image;570
23.1.5;Floating Elements to the Right;571
23.1.6;Adding Animation to Links Using Scaling;572
23.2;Introducing jQuery;574
23.2.1;How the Project References jQuery;574
23.2.2;jQuery Syntax;574
23.2.3;Using jQuery to Update the Main Image in the Product Details Page;575
23.3;Summary;580
24;Chapter 18: Responsive Web Sites: Styling for Mobile/Cell and Tablet Sized Devices;581
24.1;Introducing Media Queries;581
24.2;Designing a Responsive Site;582
24.3;Developing for Mobile/Cell Using Google Chrome;582
24.4;Making the Home Page Responsive;583
24.5;Styling the Navigation Bar for Mobile/Cell;589
24.5.1;Showing/Hiding the Navigation Bar;592
24.6;Selectively Adding Columns;598
24.7;Displaying Tables on Smaller Screens;610
24.8;Viewing a Visual Studio Project on Another Device;619
24.9;Summary;622
25;Index;623



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.