SlideShare a Scribd company logo
1 of 24
Download to read offline
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 ShowcaseSomo
 
Вебинар проекта "Как лечили"
Вебинар проекта "Как лечили"Вебинар проекта "Как лечили"
Вебинар проекта "Как лечили"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 EventRaceReach.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 ManagerDigital Front
 
Romantic age
Romantic ageRomantic age
Romantic ageAvani
 
Geneva Emergence in Gauge/Gravity Dualities
Geneva Emergence in Gauge/Gravity DualitiesGeneva Emergence in Gauge/Gravity Dualities
Geneva Emergence in Gauge/Gravity DualitiesSebastian 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 1David 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 + TypeScriptKaty Slemon
 
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.pdfManuel 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 AppEdureka!
 
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 AppEdureka!
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJSFITC
 
React_Complete.pptx
React_Complete.pptxReact_Complete.pptx
React_Complete.pptxkamalakantas
 
jQuery Super Basic
jQuery Super BasicjQuery Super Basic
jQuery Super BasicDavid 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 packageAndrii Lundiak
 
Introduction To Programming IP5
Introduction To Programming IP5Introduction To Programming IP5
Introduction To Programming IP5Mark 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 FormsDigamber Singh
 
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 Stacknuppla
 
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 5Devang Garach
 
Kickstarting Node.js Projects with Yeoman
Kickstarting Node.js Projects with YeomanKickstarting Node.js Projects with Yeoman
Kickstarting Node.js Projects with YeomanPatrick Buergin
 
JavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureJavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureIgalia
 

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 & GruntJSDavid 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 hDavid 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
 

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

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Recently uploaded (20)

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

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