SlideShare a Scribd company logo
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 1 
Contents 
I/ Set up project ............................................................................................................................................ 3 
1.1/ Create project .................................................................................................................................... 3 
1.2/ Database ............................................................................................................................................ 4 
1.2.1/ Script ........................................................................................................................................... 4 
1.2.2/ Diagram ...................................................................................................................................... 4 
1.3/ Create structure project .................................................................................................................... 4 
1.4/ Install package Dapper ...................................................................................................................... 5 
1.4.1/ Open Package Manager Console ................................................................................................ 5 
1.4.1/ Get syntax to install Dapper ....................................................................................................... 6 
II/ Get List Student ........................................................................................................................................ 8 
2.1/ Store procedure ................................................................................................................................. 8 
2.2/ Create class ........................................................................................................................................ 9 
2.3/ StudentInfoDTO ................................................................................................................................. 9 
2.4/ Get connection string ...................................................................................................................... 10 
2.5/ Read connection string .................................................................................................................... 11 
2.6/ StudentInfoRepository – Function Get List Student ........................................................................ 12 
2.7/ StudentInfoService – Function Get List Student ............................................................................. 13 
2.8/ Create Controller ............................................................................................................................. 14 
2.9/ Add action to handle ajax call ......................................................................................................... 15 
III/ Javascript ............................................................................................................................................... 15 
3.1/ StudentInfoDTO ............................................................................................................................... 15 
3.2/ Handle AJAX function ...................................................................................................................... 16 
3.2.1/ Create XMLHttpRequest ........................................................................................................... 16 
3.2.2/ Handle AJAX call ....................................................................................................................... 17 
3.3/ StudentInfoRepository .................................................................................................................... 17 
3.4/ StudentInfoService .......................................................................................................................... 18 
3.5/ StudentController ............................................................................................................................ 19 
3.6/ View & Place JS in right order .......................................................................................................... 19 
3.7/ Test part 1 ........................................................................................................................................ 20
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 2 
3.8/ Create template for displaying data ................................................................................................ 20 
3.9/ Put template into our View ............................................................................................................. 20 
4.0/ Run and Feel the magic ................................................................................................................... 21
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 3 
Setup Project 
Today, I am going to guild you building application using native Javascript with 3 layers model at a front- end and also using 3 layers at a back-end. 
In this tutorial, I using as follow: 
+ MSSQL 
+ Visual Studio 2013 Web Express 
+ MVC4 
+ .NET 4.0 
+ Dapper (https://github.com/StackExchange/dapper-dot-net) 
I/ Set up project 
1.1/ Create project 
New => Project => C# => Web => MVC4 
Choose Basic
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 4 
1.2/ Database 
1.2.1/ Script 
1.2.2/ Diagram 
1.3/ Create structure project 
I store all javascript handle action or business in folder called JavaScript. And store all class handle business at a back-end in Models.
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 5 
+ DTO: Data transfer object 
+ Repositories: Interact directly with database 
+ Services: handle business 
1.4/ Install package Dapper 
1.4.1/ Open Package Manager Console 
Go to tools => Library Package Manager => Package Manager Console
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 6 
1.4.1/ Get syntax to install Dapper 
Go to : https://www.nuget.org/packages/Dapper 
Copy box with red border line. Then go back to Visual Studio
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 7 
When you successfully install, you will get this:
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 8 
Get list student 
II/ Get List Student 
2.1/ Store procedure
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 9 
2.2/ Create class 
2.3/ StudentInfoDTO 
I create 2 constructors 
+ First: no parameter
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 10 
+ Second: with 3 parameters 
2.4/ Get connection string 
+ Go to SQL Server. Right click to highlight => Properties 
Copy Name 
Go back to Visual Studio. Do as below
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 11 
2.5/ Read connection string 
Once you have connection string from database. You need to read connection string from Visual Studio to handle data with database 
Go to Web.config
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 12 
Parse connection string you just copy from you SQL Server and name it 
To read this connection string. You have to add library System.Configuration and go to StudentInfoRepository. Do as below 
2.6/ StudentInfoRepository – Function Get List Student 
Here is syntax of Dapper. You have to remember to place namespace before you used Dapper syntax.
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 13 
2.7/ StudentInfoService – Function Get List Student
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 14 
2.8/ Create Controller
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 15 
Notice this scripts => We are going to use it to put all our js in this section. Because this place at the bottom of web page, so that all of our js will be placed at the bottom of our web app. 
2.9/ Add action to handle ajax call 
III/ Javascript 
3.1/ StudentInfoDTO 
Here is our constructor of javascript StudentInfoDTO.
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 16 
I’m not going to explain it. Everything you need to know about js. Just go to google and type Javascript OOP and find out what is it. 
3.2/ Handle AJAX function 
3.2.1/ Create XMLHttpRequest 
From folder JavaScript => Add HandleAjax.js => Edit it
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 17 
This function above => create XMLHttpRequest to handle AJAX call and communicate with our server side. 
3.2.2/ Handle AJAX call 
I pass to this function 2 parameter 
+ url: path to our action from controller. E.g: /Home/GetSomeThing (it must be return JSON) 
+ callback: when we retrieve data, so that callback function will be called to handle our business. 
3.3/ StudentInfoRepository 
Once we have tool to communicate with our Server side. So next thing we do that write function to retrieve data from our server.
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 18 
3.4/ StudentInfoService
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 19 
3.5/ StudentController 
3.6/ View & Place JS in right order
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 20 
3.7/ Test part 1 
3.8/ Create template for displaying data 
3.9/ Put template into our View 
Go back to controller and replace the line “console.log(…)” with calling function create template at previous index 3.8.
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 21 
4.0/ Run and Feel the magic
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 22 
IV/ Update code javascript => template 
4.1/ Update your view 
As you can see at index 3.8. No one want to create view like this. So I will take you far away from that. I will change this into my way. 
Go back to you index view. Put some code like this 
[[fullname]] => This is variable to contain data which I define myself. You can use your own. 
4.2/ Create template variable 
Create folder Template and StudentTemplate.js
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 23 
4.3/ Update function templateData (StudentController.js) 
4.4/ function replaceAll 
Create folder Utility and Handle.js => put some code on this. 
4.5/ Update script order 
Go back to your view index and update something
September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS 
https://nndung179.wordpress.com/ Page 24 
4.6/ Test and feel cool

More Related Content

Viewers also liked

2 mc donald older women project-ifa_2012
2 mc donald older women project-ifa_20122 mc donald older women project-ifa_2012
2 mc donald older women project-ifa_2012ifa2012_2
 
Lightning Talks: An Innovation Showcase
Lightning Talks: An Innovation ShowcaseLightning Talks: An Innovation Showcase
Lightning Talks: An Innovation Showcase
Somo
 
KEVIN HARBEY VARGAS
KEVIN HARBEY VARGASKEVIN HARBEY VARGAS
KEVIN HARBEY VARGAS
klaumilenitha
 
Natalia hernandez 1
Natalia hernandez 1Natalia hernandez 1
Natalia hernandez 1
klaumilenitha
 
Yileny Lopez 2
Yileny Lopez 2Yileny Lopez 2
Yileny Lopez 2
klaumilenitha
 
Вебинар проекта "Как лечили"
Вебинар проекта "Как лечили"Вебинар проекта "Как лечили"
Вебинар проекта "Как лечили"
Alexander Erlikh
 
CERTIFICATES FOR INTERNATIONAL CONFERENCES
CERTIFICATES FOR INTERNATIONAL CONFERENCESCERTIFICATES FOR INTERNATIONAL CONFERENCES
CERTIFICATES FOR INTERNATIONAL CONFERENCESKatrina Santos
 
Grow Your Race or Event
Grow Your Race or EventGrow Your Race or Event
Grow Your Race or Event
RaceReach.com
 
Viviana veloza santamaria (1)
Viviana veloza santamaria (1)Viviana veloza santamaria (1)
Viviana veloza santamaria (1)
klaumilenitha
 
ваш сантехник в Питере - Tutorial: Google for Webmasters
ваш сантехник в Питере - Tutorial: Google for Webmastersваш сантехник в Питере - Tutorial: Google for Webmasters
ваш сантехник в Питере - Tutorial: Google for Webmastersкрылов сергей
 
Supplier Assessment Report Yuyao Kangrui Metal Products Co., Ltd.
Supplier Assessment Report Yuyao Kangrui Metal Products Co., Ltd.Supplier Assessment Report Yuyao Kangrui Metal Products Co., Ltd.
Supplier Assessment Report Yuyao Kangrui Metal Products Co., Ltd.
shiyaping1988
 
Global Choice...Right Source | SSOW 2012 - "More Than Simply Savings: Balanci...
Global Choice...Right Source | SSOW 2012 - "More Than Simply Savings: Balanci...Global Choice...Right Source | SSOW 2012 - "More Than Simply Savings: Balanci...
Global Choice...Right Source | SSOW 2012 - "More Than Simply Savings: Balanci...
Lowell Fields Millburn
 
Digital Front - Buzz Manager
Digital Front - Buzz ManagerDigital Front - Buzz Manager
Digital Front - Buzz Manager
Digital Front
 
Romantic age
Romantic ageRomantic age
Romantic ageAvani
 
เก็งกำไร
เก็งกำไรเก็งกำไร
เก็งกำไร
Bhundit Vongumpaiprasert
 
Geneva Emergence in Gauge/Gravity Dualities
Geneva Emergence in Gauge/Gravity DualitiesGeneva Emergence in Gauge/Gravity Dualities
Geneva Emergence in Gauge/Gravity Dualities
Sebastian De Haro
 
YILENI RINTA 1
YILENI RINTA 1YILENI RINTA 1
YILENI RINTA 1
klaumilenitha
 
Holographic Cotton Tensor
Holographic Cotton TensorHolographic Cotton Tensor
Holographic Cotton Tensor
Sebastian De Haro
 
INTEGRATE 2016 - Julie Link & Greg Stroud
INTEGRATE 2016 - Julie Link & Greg Stroud INTEGRATE 2016 - Julie Link & Greg Stroud
INTEGRATE 2016 - Julie Link & Greg Stroud
IMCWVU
 

Viewers also liked (20)

2 mc donald older women project-ifa_2012
2 mc donald older women project-ifa_20122 mc donald older women project-ifa_2012
2 mc donald older women project-ifa_2012
 
Lightning Talks: An Innovation Showcase
Lightning Talks: An Innovation ShowcaseLightning Talks: An Innovation Showcase
Lightning Talks: An Innovation Showcase
 
KEVIN HARBEY VARGAS
KEVIN HARBEY VARGASKEVIN HARBEY VARGAS
KEVIN HARBEY VARGAS
 
Natalia hernandez 1
Natalia hernandez 1Natalia hernandez 1
Natalia hernandez 1
 
Yileny Lopez 2
Yileny Lopez 2Yileny Lopez 2
Yileny Lopez 2
 
Вебинар проекта "Как лечили"
Вебинар проекта "Как лечили"Вебинар проекта "Как лечили"
Вебинар проекта "Как лечили"
 
CERTIFICATES FOR INTERNATIONAL CONFERENCES
CERTIFICATES FOR INTERNATIONAL CONFERENCESCERTIFICATES FOR INTERNATIONAL CONFERENCES
CERTIFICATES FOR INTERNATIONAL CONFERENCES
 
Grow Your Race or Event
Grow Your Race or EventGrow Your Race or Event
Grow Your Race or Event
 
Viviana veloza santamaria (1)
Viviana veloza santamaria (1)Viviana veloza santamaria (1)
Viviana veloza santamaria (1)
 
ваш сантехник в Питере - Tutorial: Google for Webmasters
ваш сантехник в Питере - Tutorial: Google for Webmastersваш сантехник в Питере - Tutorial: Google for Webmasters
ваш сантехник в Питере - Tutorial: Google for Webmasters
 
Supplier Assessment Report Yuyao Kangrui Metal Products Co., Ltd.
Supplier Assessment Report Yuyao Kangrui Metal Products Co., Ltd.Supplier Assessment Report Yuyao Kangrui Metal Products Co., Ltd.
Supplier Assessment Report Yuyao Kangrui Metal Products Co., Ltd.
 
1 ~1
 1 ~1 1 ~1
1 ~1
 
Global Choice...Right Source | SSOW 2012 - "More Than Simply Savings: Balanci...
Global Choice...Right Source | SSOW 2012 - "More Than Simply Savings: Balanci...Global Choice...Right Source | SSOW 2012 - "More Than Simply Savings: Balanci...
Global Choice...Right Source | SSOW 2012 - "More Than Simply Savings: Balanci...
 
Digital Front - Buzz Manager
Digital Front - Buzz ManagerDigital Front - Buzz Manager
Digital Front - Buzz Manager
 
Romantic age
Romantic ageRomantic age
Romantic age
 
เก็งกำไร
เก็งกำไรเก็งกำไร
เก็งกำไร
 
Geneva Emergence in Gauge/Gravity Dualities
Geneva Emergence in Gauge/Gravity DualitiesGeneva Emergence in Gauge/Gravity Dualities
Geneva Emergence in Gauge/Gravity Dualities
 
YILENI RINTA 1
YILENI RINTA 1YILENI RINTA 1
YILENI RINTA 1
 
Holographic Cotton Tensor
Holographic Cotton TensorHolographic Cotton Tensor
Holographic Cotton Tensor
 
INTEGRATE 2016 - Julie Link & Greg Stroud
INTEGRATE 2016 - Julie Link & Greg Stroud INTEGRATE 2016 - Julie Link & Greg Stroud
INTEGRATE 2016 - Julie Link & Greg Stroud
 

Similar to Javascript native OOP - 3 layers

MVC4 – knockout.js – bootstrap – step by step – part 1
MVC4 – knockout.js – bootstrap – step by step – part 1MVC4 – knockout.js – bootstrap – step by step – part 1
MVC4 – knockout.js – bootstrap – step by step – part 1
David Nguyen
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScript
Katy Slemon
 
Nuxtjs cheat-sheet
Nuxtjs cheat-sheetNuxtjs cheat-sheet
Nuxtjs cheat-sheet
ValeriaCastillo71
 
2023-09-27-AWSOnTour-pipeline-first-hugo-on-aws.pdf
2023-09-27-AWSOnTour-pipeline-first-hugo-on-aws.pdf2023-09-27-AWSOnTour-pipeline-first-hugo-on-aws.pdf
2023-09-27-AWSOnTour-pipeline-first-hugo-on-aws.pdf
Manuel Vogel
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
Edureka!
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
David Gibbons
 
Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web App
Edureka!
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
FITC
 
React_Complete.pptx
React_Complete.pptxReact_Complete.pptx
React_Complete.pptx
kamalakantas
 
jQuery Super Basic
jQuery Super BasicjQuery Super Basic
jQuery Super Basic
David Nguyen
 
Create ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm packageCreate ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm package
Andrii Lundiak
 
Introduction To Programming IP5
Introduction To Programming IP5Introduction To Programming IP5
Introduction To Programming IP5
Mark Simon
 
Angular 7 Firebase5 CRUD Operations with Reactive Forms
Angular 7 Firebase5 CRUD Operations with Reactive FormsAngular 7 Firebase5 CRUD Operations with Reactive Forms
Angular 7 Firebase5 CRUD Operations with Reactive Forms
Digamber Singh
 
React django
React djangoReact django
React django
Heber Silva
 
ConSol_IBM_webcast_quarkus_the_blue_hedgehog_of_java_web_frameworks
ConSol_IBM_webcast_quarkus_the_blue_hedgehog_of_java_web_frameworksConSol_IBM_webcast_quarkus_the_blue_hedgehog_of_java_web_frameworks
ConSol_IBM_webcast_quarkus_the_blue_hedgehog_of_java_web_frameworks
ConSol Consulting & Solutions Software GmbH
 
Getting started with the Lupus Nuxt.js Drupal Stack
Getting started with the Lupus Nuxt.js Drupal StackGetting started with the Lupus Nuxt.js Drupal Stack
Getting started with the Lupus Nuxt.js Drupal Stack
nuppla
 
Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5
Devang Garach
 
Kickstarting Node.js Projects with Yeoman
Kickstarting Node.js Projects with YeomanKickstarting Node.js Projects with Yeoman
Kickstarting Node.js Projects with Yeoman
Patrick Buergin
 
JavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureJavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and Future
Igalia
 
Kraken.js Lab Primer
Kraken.js Lab PrimerKraken.js Lab Primer
Kraken.js Lab Primer
Aeshan Wijetunge
 

Similar to Javascript native OOP - 3 layers (20)

MVC4 – knockout.js – bootstrap – step by step – part 1
MVC4 – knockout.js – bootstrap – step by step – part 1MVC4 – knockout.js – bootstrap – step by step – part 1
MVC4 – knockout.js – bootstrap – step by step – part 1
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScript
 
Nuxtjs cheat-sheet
Nuxtjs cheat-sheetNuxtjs cheat-sheet
Nuxtjs cheat-sheet
 
2023-09-27-AWSOnTour-pipeline-first-hugo-on-aws.pdf
2023-09-27-AWSOnTour-pipeline-first-hugo-on-aws.pdf2023-09-27-AWSOnTour-pipeline-first-hugo-on-aws.pdf
2023-09-27-AWSOnTour-pipeline-first-hugo-on-aws.pdf
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web App
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
 
React_Complete.pptx
React_Complete.pptxReact_Complete.pptx
React_Complete.pptx
 
jQuery Super Basic
jQuery Super BasicjQuery Super Basic
jQuery Super Basic
 
Create ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm packageCreate ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm package
 
Introduction To Programming IP5
Introduction To Programming IP5Introduction To Programming IP5
Introduction To Programming IP5
 
Angular 7 Firebase5 CRUD Operations with Reactive Forms
Angular 7 Firebase5 CRUD Operations with Reactive FormsAngular 7 Firebase5 CRUD Operations with Reactive Forms
Angular 7 Firebase5 CRUD Operations with Reactive Forms
 
React django
React djangoReact django
React django
 
ConSol_IBM_webcast_quarkus_the_blue_hedgehog_of_java_web_frameworks
ConSol_IBM_webcast_quarkus_the_blue_hedgehog_of_java_web_frameworksConSol_IBM_webcast_quarkus_the_blue_hedgehog_of_java_web_frameworks
ConSol_IBM_webcast_quarkus_the_blue_hedgehog_of_java_web_frameworks
 
Getting started with the Lupus Nuxt.js Drupal Stack
Getting started with the Lupus Nuxt.js Drupal StackGetting started with the Lupus Nuxt.js Drupal Stack
Getting started with the Lupus Nuxt.js Drupal Stack
 
Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5
 
Kickstarting Node.js Projects with Yeoman
Kickstarting Node.js Projects with YeomanKickstarting Node.js Projects with Yeoman
Kickstarting Node.js Projects with Yeoman
 
JavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureJavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and Future
 
Kraken.js Lab Primer
Kraken.js Lab PrimerKraken.js Lab Primer
Kraken.js Lab Primer
 

More from David Nguyen

ACOMP_2014_submission_70
ACOMP_2014_submission_70ACOMP_2014_submission_70
ACOMP_2014_submission_70David Nguyen
 
Compressed js with NodeJS & GruntJS
Compressed js with NodeJS & GruntJSCompressed js with NodeJS & GruntJS
Compressed js with NodeJS & GruntJS
David Nguyen
 
Chứng minh số node của Heap chiều cao h
Chứng minh số node của Heap chiều cao hChứng minh số node của Heap chiều cao h
Chứng minh số node của Heap chiều cao h
David Nguyen
 
Hướng dẫn sử dụng Mind Manager 8
Hướng dẫn sử dụng Mind Manager 8 Hướng dẫn sử dụng Mind Manager 8
Hướng dẫn sử dụng Mind Manager 8 David Nguyen
 
KTMT Lý Thuyết Tổng Quát
KTMT Lý Thuyết Tổng QuátKTMT Lý Thuyết Tổng Quát
KTMT Lý Thuyết Tổng QuátDavid Nguyen
 
KTMT Số Nguyên - Số Chấm Động
KTMT Số Nguyên - Số Chấm ĐộngKTMT Số Nguyên - Số Chấm Động
KTMT Số Nguyên - Số Chấm ĐộngDavid Nguyen
 
Mô Hình MVC 3.0
Mô Hình MVC 3.0Mô Hình MVC 3.0
Mô Hình MVC 3.0
David Nguyen
 

More from David Nguyen (11)

ACOMP_2014_submission_70
ACOMP_2014_submission_70ACOMP_2014_submission_70
ACOMP_2014_submission_70
 
Compressed js with NodeJS & GruntJS
Compressed js with NodeJS & GruntJSCompressed js with NodeJS & GruntJS
Compressed js with NodeJS & GruntJS
 
Facebook API
Facebook APIFacebook API
Facebook API
 
Quick sort
Quick sortQuick sort
Quick sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
Heap Sort
Heap SortHeap Sort
Heap Sort
 
Chứng minh số node của Heap chiều cao h
Chứng minh số node của Heap chiều cao hChứng minh số node của Heap chiều cao h
Chứng minh số node của Heap chiều cao h
 
Hướng dẫn sử dụng Mind Manager 8
Hướng dẫn sử dụng Mind Manager 8 Hướng dẫn sử dụng Mind Manager 8
Hướng dẫn sử dụng Mind Manager 8
 
KTMT Lý Thuyết Tổng Quát
KTMT Lý Thuyết Tổng QuátKTMT Lý Thuyết Tổng Quát
KTMT Lý Thuyết Tổng Quát
 
KTMT Số Nguyên - Số Chấm Động
KTMT Số Nguyên - Số Chấm ĐộngKTMT Số Nguyên - Số Chấm Động
KTMT Số Nguyên - Số Chấm Động
 
Mô Hình MVC 3.0
Mô Hình MVC 3.0Mô Hình MVC 3.0
Mô Hình MVC 3.0
 

Recently uploaded

Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 

Recently uploaded (20)

Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 

Javascript native OOP - 3 layers

  • 1. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 1 Contents I/ Set up project ............................................................................................................................................ 3 1.1/ Create project .................................................................................................................................... 3 1.2/ Database ............................................................................................................................................ 4 1.2.1/ Script ........................................................................................................................................... 4 1.2.2/ Diagram ...................................................................................................................................... 4 1.3/ Create structure project .................................................................................................................... 4 1.4/ Install package Dapper ...................................................................................................................... 5 1.4.1/ Open Package Manager Console ................................................................................................ 5 1.4.1/ Get syntax to install Dapper ....................................................................................................... 6 II/ Get List Student ........................................................................................................................................ 8 2.1/ Store procedure ................................................................................................................................. 8 2.2/ Create class ........................................................................................................................................ 9 2.3/ StudentInfoDTO ................................................................................................................................. 9 2.4/ Get connection string ...................................................................................................................... 10 2.5/ Read connection string .................................................................................................................... 11 2.6/ StudentInfoRepository – Function Get List Student ........................................................................ 12 2.7/ StudentInfoService – Function Get List Student ............................................................................. 13 2.8/ Create Controller ............................................................................................................................. 14 2.9/ Add action to handle ajax call ......................................................................................................... 15 III/ Javascript ............................................................................................................................................... 15 3.1/ StudentInfoDTO ............................................................................................................................... 15 3.2/ Handle AJAX function ...................................................................................................................... 16 3.2.1/ Create XMLHttpRequest ........................................................................................................... 16 3.2.2/ Handle AJAX call ....................................................................................................................... 17 3.3/ StudentInfoRepository .................................................................................................................... 17 3.4/ StudentInfoService .......................................................................................................................... 18 3.5/ StudentController ............................................................................................................................ 19 3.6/ View & Place JS in right order .......................................................................................................... 19 3.7/ Test part 1 ........................................................................................................................................ 20
  • 2. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 2 3.8/ Create template for displaying data ................................................................................................ 20 3.9/ Put template into our View ............................................................................................................. 20 4.0/ Run and Feel the magic ................................................................................................................... 21
  • 3. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 3 Setup Project Today, I am going to guild you building application using native Javascript with 3 layers model at a front- end and also using 3 layers at a back-end. In this tutorial, I using as follow: + MSSQL + Visual Studio 2013 Web Express + MVC4 + .NET 4.0 + Dapper (https://github.com/StackExchange/dapper-dot-net) I/ Set up project 1.1/ Create project New => Project => C# => Web => MVC4 Choose Basic
  • 4. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 4 1.2/ Database 1.2.1/ Script 1.2.2/ Diagram 1.3/ Create structure project I store all javascript handle action or business in folder called JavaScript. And store all class handle business at a back-end in Models.
  • 5. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 5 + DTO: Data transfer object + Repositories: Interact directly with database + Services: handle business 1.4/ Install package Dapper 1.4.1/ Open Package Manager Console Go to tools => Library Package Manager => Package Manager Console
  • 6. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 6 1.4.1/ Get syntax to install Dapper Go to : https://www.nuget.org/packages/Dapper Copy box with red border line. Then go back to Visual Studio
  • 7. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 7 When you successfully install, you will get this:
  • 8. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 8 Get list student II/ Get List Student 2.1/ Store procedure
  • 9. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 9 2.2/ Create class 2.3/ StudentInfoDTO I create 2 constructors + First: no parameter
  • 10. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 10 + Second: with 3 parameters 2.4/ Get connection string + Go to SQL Server. Right click to highlight => Properties Copy Name Go back to Visual Studio. Do as below
  • 11. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 11 2.5/ Read connection string Once you have connection string from database. You need to read connection string from Visual Studio to handle data with database Go to Web.config
  • 12. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 12 Parse connection string you just copy from you SQL Server and name it To read this connection string. You have to add library System.Configuration and go to StudentInfoRepository. Do as below 2.6/ StudentInfoRepository – Function Get List Student Here is syntax of Dapper. You have to remember to place namespace before you used Dapper syntax.
  • 13. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 13 2.7/ StudentInfoService – Function Get List Student
  • 14. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 14 2.8/ Create Controller
  • 15. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 15 Notice this scripts => We are going to use it to put all our js in this section. Because this place at the bottom of web page, so that all of our js will be placed at the bottom of our web app. 2.9/ Add action to handle ajax call III/ Javascript 3.1/ StudentInfoDTO Here is our constructor of javascript StudentInfoDTO.
  • 16. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 16 I’m not going to explain it. Everything you need to know about js. Just go to google and type Javascript OOP and find out what is it. 3.2/ Handle AJAX function 3.2.1/ Create XMLHttpRequest From folder JavaScript => Add HandleAjax.js => Edit it
  • 17. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 17 This function above => create XMLHttpRequest to handle AJAX call and communicate with our server side. 3.2.2/ Handle AJAX call I pass to this function 2 parameter + url: path to our action from controller. E.g: /Home/GetSomeThing (it must be return JSON) + callback: when we retrieve data, so that callback function will be called to handle our business. 3.3/ StudentInfoRepository Once we have tool to communicate with our Server side. So next thing we do that write function to retrieve data from our server.
  • 18. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 18 3.4/ StudentInfoService
  • 19. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 19 3.5/ StudentController 3.6/ View & Place JS in right order
  • 20. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 20 3.7/ Test part 1 3.8/ Create template for displaying data 3.9/ Put template into our View Go back to controller and replace the line “console.log(…)” with calling function create template at previous index 3.8.
  • 21. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 21 4.0/ Run and Feel the magic
  • 22. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 22 IV/ Update code javascript => template 4.1/ Update your view As you can see at index 3.8. No one want to create view like this. So I will take you far away from that. I will change this into my way. Go back to you index view. Put some code like this [[fullname]] => This is variable to contain data which I define myself. You can use your own. 4.2/ Create template variable Create folder Template and StudentTemplate.js
  • 23. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 23 4.3/ Update function templateData (StudentController.js) 4.4/ function replaceAll Create folder Utility and Handle.js => put some code on this. 4.5/ Update script order Go back to your view index and update something
  • 24. September 29, 2014 NGUYỄN NGỌC DŨNG – JAVASCRIPT OOP – 3 LAYERS https://nndung179.wordpress.com/ Page 24 4.6/ Test and feel cool