1. Trang chủ
  2. » Luận Văn - Báo Cáo

Lecture E-Commerce - Chapter 26: ASP.NET MVC (part II)

50 67 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 50
Dung lượng 812,2 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

In this chapter students will be able to: Introduction, javascript where to, javascript output, javascript syntax, javascript statements, javascript comments, javascript variables, javascript data type.

Trang 1

CSC 330 E-Commerce

Teacher

Ahmed Mumtaz Mustehsan

GM-IT CIIT Islamabad

Virtual Campus, CIIT

COMSATS Institute of Information Technology

T2-Lecture-15

Trang 2

ASP.NET MVC

Part - II

For Lecture Material/Slides Thanks to: www.w3schools.com

Trang 3

Internet Application

Application

We will build an Internet application that supports

adding, editing, deleting, and listing of information

stored in a database

Part I: Creating the Application

Part II: Exploring the Application Folders

Part III: Adding Styles and a Consistent Look (Layout).Part IV: Adding a Controller

Part V: Adding Views for Displaying the Application

Part VI: Adding a Database

Part VII: Adding a Data Model

1-3

T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 4

Part VI:

Adding a Database.

Trang 5

Creating the Database

The database needed for this lesson can be created with these simple steps:

Right-click the App_Data folder in the Solution Explorer

window

Click the Add button

1-5

T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 6

Creating the Database

database in the App_Data folder If SQL Server

Compact Local Database is not an available option, means SQL Server Compact not installed

computer Install it from this link:

SQL Server Compact

1-6

T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 7

Adding a Database Table

Double-clicking the Movies.sdf file in the App_Data

folder will open a Database Explorer window

To create a new table in the database, right-click the

Tables folder, and select Create Table

1-7

T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 8

Adding a Database Table

ID is an integer (whole number) used to identify each record in the table

Title is a 100 character text column to store the name

make the ID column the table's primary key (record

identifier)

To do this, click on the column name (ID) and select Primary Key Also, in the Column Properties window, set the Identity property to True:

1-8

T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 9

T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 10

Adding a Database Table

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 11

Adding Database Records

the movie database

Double-click the Movies.sdf file in the App_Data folder

Right-click the MovieDBs table in the Database

Note: The ID column is updated automatically You should not edit

it

11

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 12

Part VII:

Adding a Data Model MVC Models

Trang 13

The MVC Model contains all application logic:

 business logic,

validation logic,

data access logic,

(except pure view and controller logic.)

MVC, models are used for both:

Hold and manipulate application data.

13

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 14

The Models Folder

represent the application model

Visual Web Developer automatically creates an

for application security

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 15

Adding a Database Model

The database model needed for this Lesson can be created with these simple steps:

In the Solution Explorer,

right-click the Models folder, select Add and

Name the class MovieDB.cs , and click Add

Edit the class:

15

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 16

16

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 17

Adding a Database Model

Note:

"MovieDB"

"MovieDBs" (ending with s) used for the database

table It looks strange, but this is the naming

convention we have to use to make the model connect

to the database table

17

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 18

Adding a Database Controller

The database controller needed for this lesson can be

created with these simple steps:

Re-Build your project:

 Select Debug , and then Build MvcDemo from the menu.

 In the Solution Explorer, right-click the Controllers folder, and select Add and Controller

 Set controller name to MoviesController

 Select template: Controller with read/write actions and

views, using Entity Framework

 Select model class: MovieDB (MvcDemo.Models)

 Select data context class: MovieDBContext

(MvcDemo.Models)

 Select views Razor (CSHTML)

 Click Add

18

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 19

Adding a Database Controller

Visual Web Developer will create the following files:

A MoviesController.cs file in the Controllers folder

A Movies folder in the Views folder

19

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 20

Adding Database Views

The following files are automatically created in the Movies folder:

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 21

Adding a Connection String

Add the following element to the

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 22

MVC Application Security

The Models Folder contains the classes that represent the application model

an AccountModels.cs file that contains the models for application authentication

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 23

Account Model

23

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 24

The Change Password Model

public class ChangePasswordModel

{

[Required]

[DataType(DataType.Password)]

[Display(Name = "Current password")]

public string OldPassword { get; set; }

[Required]

[StringLength(100, ErrorMessage = "The {0} must be at least {2}

characters long.", MinimumLength = 6)]

[DataType(DataType.Password)]

[Display(Name = "New password")]

public string NewPassword { get; set; }

[DataType(DataType.Password)]

[Display(Name = "Confirm new password")]

[Compare("NewPassword", ErrorMessage = "The new password and

confirmation password do not match.")]

public string ConfirmPassword { get; set; }

}

24

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 25

A Logon Model

public class LogOnModel

{

[Required]

[Display(Name = "User name")]

public string UserName { get; set; }

[Required]

[DataType(DataType.Password)]

[Display(Name = "Password")]

public string Password { get; set; }

[Display(Name = "Remember me?")]

public bool RememberMe { get; set; }

}

25

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 26

The Register Model

public class RegisterModel

{

[Required]

[Display(Name = "User name")]

public string UserName { get; set; }

[Required]

[DataType(DataType.EmailAddress)]

[Display(Name = "Email address")]

public string Email { get; set; }

[Display(Name = "Confirm password")]

[Compare("Password", ErrorMessage = "The password and confirmation password

do not match.")]

public string ConfirmPassword { get; set; }

}

26

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 27

Congratulations You have added your first

MVC data model to your application.

Now you can click on the "Movies" tab

27

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 28

Run the Application

 Select Debug, Start Debugging (or F5) from the Visual Web

Developer menu.

 Your application will look like this:

 Click on the "Home" tab and the "About" tab to see how it works.

28

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 29

The End ASP.NET MVC

Part-II

29 T2-Lecture-15 Ahmed Mumtaz

1-Mustehsan www.w3schools.com

Trang 30

to Visual Studio 2010

30 T2-Lecture-15 Ahmed Mumtaz

1-Mustehsan www.w3schools.com

Trang 31

Installation of Visual Studio/Visual Web Express

Get and install a licensed copy of either the Visual

Studio or Visual Web Developer

Visual Studio family So, either of the environments can

be used to build Web sites without any issue

environment

31

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 32

Starting Visual Studio/Web Developer

Run Visual Studio from the installed directory or Desktop or

Start Menu.

32 T2-Lecture-15 Ahmed Mumtaz

1-Mustehsan www.w3schools.com

Trang 33

Adding Projects and Items

 Web Projects

The New Web Site dialog box enables you to create a new

Web site on the local computer or on a remote computer, or

to connect to a Web site location using FTP to read and

write files The following illustration shows the New Web

Site dialog box.

33

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 34

Using the Integrated Development EnvironmentThe Visual Web Developer environment

34

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 35

 Customizing Menus and Toolbars

The menus and toolbars in Visual Web Developer are customizable To

customize menus commands and toolbars, click Customize in

the Tools menu

Customize dialog box

The Customize dialog box lets

you select toolbars to display,

create custom toolbars and

menus, add remove items from

toolbars and menus, and

change the appearance of

toolbar and menu items.

Using the Integrated Development Environment

35

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 36

Using the Integrated Development Environment

Solution Explorer Window

 The Solution Explorer window displays solutions, projects, and the items in those projects

 It provides an organized view of the projects and their files as well

as access to the commands that pertain to them.

36

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 37

Using the Integrated Development Environment

Properties Window

 Used to view and set the properties and events of objects that

you are working with in the editor and page designer

 Can also be used to edit and view file, project, and solution

properties To display the Properties window, click Properties

Window in the View menu.

37

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 38

Editors, Designers, and Tools

and using designer windows

The functionality of the editor and of designers

depends on the type of file or document being created

38

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 39

Editors, Designers, and Tools

Web page designer, design view

Design view displays

the controls and other

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 40

Editors, Designers, and Tools

 Web page designer, Source view

Source view displays the

source code for the file

Source view also supports

editing features like word

wrap, bookmarks, and line

numbers.

40

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 41

Editors, Designers, and Tools

 Web page designer, Split view

Some editors can also

display the design view

and source view at the

same time This view

is called Split view.

41

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 42

Editors, Designers, and Tools

 Editing Web Pages in the Designer

 An ASP.NET Web page consists of visual

elements and programming logic

 Visual elements for the page include

markup, server controls, and static text

 Programming logic for the page includes

event handlers and other code

 The Toolbox displays controls that can be

added to Visual Web Developer projects To

display the Toolbox , click Toolbox in

the View menu.

42

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 43

CSS Properties and Styles

 The CSS Properties window is

used during the editing of an

ASP.NET Web page

 The window shows the styles

that are used by the current

selection in a Web page and the

order of precedence for the

styles

 The window is used to add

properties to an existing style,

modify the already set

properties, and create new inline

styles.

43

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 44

Build and Debug Options

compiled, or built Visual Web Developer provides a robust set of build (compilation) and debugging

options

can be selected, or those unwanted can be excluded, and built details can be specified Build configurations for solutions and projects can be created

Building application helps in the detection of time errors

keywords, and type mismatches

44

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 45

The Output window displays these types of errors.

Output window showing build information

Build and Debug Options

45

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 46

After building the application, the debugger can be

used to detect and correct run-time problems, such as logic errors

break mode, the local variables and other data can be examined by using tools such as the Variable window,

Build and Debug Options

46

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 47

Debugging windows

other messages that are related to debugging

Build and Debug Options

47

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 48

Deployment Options

 Web Site Project Deployment

projects include:

◦Deploying a Web site by using the Copy Web Site tool, which can copy and synchronize files between the source computer, a destination computer or location

XCopy command

48

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 49

Product Documentation

 The Help can be accessed by pressing F1 in the IDE and by

clicking View Help in the Help menu

 Help can be obtained from either locally installed Help or

documentation on the MSDN Web site.

49

1-T2-Lecture-15 Ahmed Mumtaz Mustehsan www.w3schools.com

Trang 50

End ASP.NET MVC

Part - II

For Lecture Material/Slides Thanks to: www.w3schools.com

Ngày đăng: 18/01/2020, 16:03

w