Вы находитесь на странице: 1из 420

A Quick Reference Guide

www.ManzoorTheTrainer.com
The Complete
ASP.Net Core MVC Web Developer Course
For Absolute Beginners From Scratch

Take The Course Here or Visit : https://bit.ly/2R47dOa


To Achieve Your Dream
What Can I do After Completion Of This Course?
● Job & You will be in a position to develop any web application similar to this
http://linkhub.manzoorthetrainer.com
This Course Is For
● Those who want to become Microsoft ASP.Net MVC Web Developer with zero
prior programming knowledge.
● Those who are working on ASP.Net Web Forms and want to upgrade their profile
with ASP.Net MVC
What Are We Going To Cover?
● Learn MS SQL Server 2017 With Db Design Techniques
● Learn C#.Net Core From Scratch With Real World Examples
● Learn HTML And CSS From Scratch
● Learn JavaScript From Scratch
● Learn Entity Framework Core 2.0 From Scratch (Code First Approach)
● Learn ASP.Net Core 2.0 MVC From Scratch
● Live Project On ASP.Net Core 2.0 MVC And ASP.Net MVC 5
Where do they fit in?

ASP.Net
Core
MVC
HTML C#.Net EF Core
CSS MS SQL Server
JavaScript
DAL 2017
JQuery BLL
BootStrap Database
UI

C#.Net - BOL
Prerequisite
● You should know how to use computer.
● You should have internet connection.
● It is good if you have some basic understanding of c programming.
● Install MS SQL Server 2017 Express Edition
https://www.microsoft.com/en-us/download/details.aspx?id=55994
● Install Visual Studio 2017 Community Edition
https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=Commu
nity&rel=15
Thank You
Take The Course Here or Visit : https://bit.ly/2R47dOa
To Achieve Your Dream
Learn MS SQL Server 2017
www.ManzoorTheTrainer.com

With Db Design Techniques


Mohd Manzoor Ahmed [MCT]
manzoor_trainer manzoorthetrainer.com
www.ManzoorTheTrainer.com

What Are We Going To Cover?


● Introduction To RDBMS ● Stored Procedures
● Primary Key ● Functions
● Unique Key ● Views
● Data Types ● Transactions
● Foreign Key ● Some Admin Tasks
● Database Design Techniques ● Assignment
● T-SQL Select Query ● Q&A
● Joins
● Sub Queries
● Correlated Subqueries
www.ManzoorTheTrainer.com

Prerequisite
● You should know how to use computer.
● Install MS SQL Server 2017 Express Edition
https://www.microsoft.com/en-us/download/details.aspx?id=55994
● Operating System : Windows 10 , Windows 8, Windows 8.1, Windows Server 2012,
Windows Server 2012 R2, Windows Server 2016
● Processor : Intel - compatible processor with a minimum speed of 1 GHz
● RAM : Minimum 512MB
● Hard Disk Space :4.2 GB of Disk Space

Note : Disable prevent saving changes that require table re-creation.


(Tools → Options → Designers : Uncheck )
www.ManzoorTheTrainer.com

Why is RDBMS?
● In the traditional approach, we used to store information in flat files which are
maintained by the file system under the operating system’s control.
● Application programs go through the file system to access these flat files.
● Unable to achieve Data Safety, Concurrent Access, Fault Tolerance, Data
Integrity, Reporting.
What is RDBMS?
www.ManzoorTheTrainer.com

● First published by E.F. Codd in 1970


● A relational database consists of a
collection of tables
● A table consists of rows and columns
● Each row represents a record
● Each column represents an attribute
of the records contained in the table
● MS SQL Server, Oracle, DB2,
MySQL, etc.,
● We interact through SQL.
www.ManzoorTheTrainer.com

Primary Key
www.ManzoorTheTrainer.com

Primary Key Vs Unique Key


● Primary Key
○ It cannot be Null.
○ It cannot have duplicate values.
○ A table can have one and only one primary key
● Unique Key
○ It can have one and only one Null.
○ It cannot have duplicate values.
○ A table can have more than one unique key
www.ManzoorTheTrainer.com

Composite Primary Key


www.ManzoorTheTrainer.com

Get Started With MS SQL Server


● Create Database
● Create Table
● Create Primary Key
● Identity Column
● Set Default Values
● Create Unique Key
● Create Check Constraints
● Take a look into log file entries (fn_dblog(null,null))
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on getting started with MS SQL Server
www.ManzoorTheTrainer.com

Data Types In MS SQL Server


● String
○ char(n) (Fixed Non - Unicode)
○ varchar(n) (Variable Non - Unicode)
○ nchar(n) (Fixed Unicode)
○ nvarchar(n) (Variable Unicode)
● Number
○ int, bigint, smallint, and tinyint
○ decimal and numeric
○ float and real
○ money and smallmoney
www.ManzoorTheTrainer.com

Data Types In MS SQL Server


● DateTime
○ date
○ time
○ datetime
○ datetime2
○ smalldatetime
● uniqueidentifier
● For Ranges : https://www.w3schools.com/sql/sql_datatypes.asp
www.ManzoorTheTrainer.com

Foreign key
www.ManzoorTheTrainer.com

Foreign key
● Foreign Key: A foreign key is a “copy” of a primary key that has been exported
from one relation into another to represent the existence of a relationship
between them.
● A foreign key is a copy of the whole of its parent primary key i.e if the primary key
is composite, then so is the foreign key.
● Foreign key values do not (usually) have to be unique.
● Foreign keys can also be null.
● A composite foreign key cannot have some attribute(s) null and others non-null.
www.ManzoorTheTrainer.com

Update And Delete Constraints


● What happens if I delete or update a parent record
○ No Action
○ Set Null
○ Set Default
○ Cascade
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Foreign Key
www.ManzoorTheTrainer.com

Database Design Task - 1 [Stock Management System]


● A book shop contains multiple books.
● A customer can buy multiple books.
● An old customer can visit again and again.
● Books are sold depending on its availability.

● Objects ● Relationship
○ Book ○ Customer - Book
○ Customer ○ 1→n
○ n→1
○ n → n (M:M)
www.ManzoorTheTrainer.com

Database Design - 3 Key Rules For Relationships


After identifying the objects and relationship among them apply these three rules to
create database structure.

1. One table for each object


2. For 1:M relationship. 1 will become master and M will become child i.e., primary
key of 1 will act as a foreign key for M.
Eg : Department : Employees is 1 : M
www.ManzoorTheTrainer.com

Database Design - 3 Key Rules


3. M:M relationship. Both the objects will become master and there will be one more
new table called as transaction table or child table with primary keys of masters as
foreign Keys in it.
Eg : Student : Subject is M : M
www.ManzoorTheTrainer.com

Database Design
● Objects
○ Book
○ Customer

● Relationship
○ Customer - Book
○ 1→n
○ n→1
○ n → n (M:M)
www.ManzoorTheTrainer.com

Database Design Task - 2 [Stock Management System]


● A Toy manufacturing company manufactures different types of toys.
● The company has several manufacturing plants.
● Each plant manufactures different types of toys.
● A customer can place order for these toys.
● Each customer has multiple ship-to addresses.
www.ManzoorTheTrainer.com

Objects And Relationship


● Objects ● Relationship
○ Plant ○ Plant : Category (1→ n)(1:M)
○ Category ○ Category : Toy (1 → n)(1:M)
○ Toy ○ Customer : ShipToAddress (1 → n)(1:M)
○ Customer ○ Customer : Toy (n → n) {Order}(M:M)
○ ShipToAddress
○ Order
www.ManzoorTheTrainer.com

Database Design
www.ManzoorTheTrainer.com

IT Workshop Management System - Scenario


Admin announces a workshop on a topic and assign it to the trainer.New Students
Register For the workshop and send a request to attend.Old Students can login and
view the upcoming workshops and send a request for it without registration.Admin
will approve the request sent by both kind of students and send a confirmation mail
along with login credentials (For new students of the portal). Both kind of students
need to carry the copy of this mail on the day of workshop as a pass.After the
completion of the workshop they will have secured access to the material of the
workshop on portal.
www.ManzoorTheTrainer.com

IT Workshop Management System - Scenario


Admin can View, Edit and Delete any workshop after announcing. Admin can
view, Edit and delete the information about the registered candidates. Can change his
own password and can reset the password of any student.Admin can View, Edit and
Delete any Trainer.Admin will upload the material in .zip format against a workshop.
Admin can View, Edit and Delete any material uploaded against a workshop.

Students can view,Edit and delete their own details and can change
their password.Can download the Material.Can view the status of the request for
workshop.
www.ManzoorTheTrainer.com

Identifying Objects
● Admin
● Trainer
● Student
● Workshop
● Material
www.ManzoorTheTrainer.com

Objects & Relationships


● Objects ● Relationships
○ Admin ○ Admin : Workshop (1:M)
○ Trainer ○ Trainer : Workshop (M:M)
○ Student ○ Student : Workshop (M:M)
○ Workshop ○ Material : Workshop (M:1)
○ Material
www.ManzoorTheTrainer.com

Database Design
Admin Trainer Student Workshop Material

Aid Tid Sid Wid Mid

Aid Wid

Trainer_Workshop Student_Workshop

TWid SWid

Tid Sid

Wid Wid
www.ManzoorTheTrainer.com

Database Design
User Role Workshop Material

uid Rid Wid Mid

Rid uid Wid

Trainer_Workshop Student_Workshop

TWid SWid

uid uid

Wid Wid
www.ManzoorTheTrainer.com

T-SQL (Transact - SQL)


● The database query and programming language used to access data, query data,
update data, manage database.
● Two main programming categories:
○ DDL : Create, Alter and Drop Objects.
○ DML : Select, Insert, Update and Delete operations.
www.ManzoorTheTrainer.com

DML - Data Manipulation Language


● Insert
● Update
● Delete
● Select
www.ManzoorTheTrainer.com

Insert Query On Department


www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Insert
www.ManzoorTheTrainer.com

Delete And Update Query On Department


www.ManzoorTheTrainer.com

Demo
Let’s see a demo on delete and update
www.ManzoorTheTrainer.com

Generating And Inserting Dummy Records


● We use this online tool to generate ample number of dummy data to work with
different queries.
● https://www.generatedata.com/
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on generating dummy data
www.ManzoorTheTrainer.com

Select Query On Employee Table


● Select * From <Table Name>, Table & Column Aliasing, Distinct
● Expressions on columns : Mathematical & Cases
● Order By
○ Single & Multiple Column
○ Top, Top With Ties
● Where
○ =,<>,<,>,<=,>= (conditions)
○ In, Not In, Between, Not Between, Is null, Is not null
○ Like → %,[]
○ soundex()
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on select query
www.ManzoorTheTrainer.com

Scalar Functions
● A scalar valued function is a function that takes one or more values but returns a
single value.
● String Functions : Len(), Lower(), Ltrim(), Substring(), String_Split()
● Other Functions : Cast(), Convert(), Isnull()
● DateTime Functions : getdate(), year(), month(), day(), DateAdd(), Datediff(),
Datepart(), DateName()
● Mathematical Functions : Ceiling(), Floor(), Round(), Rand()
● Aggregate Functions : Count(), Sum(), Avg(), Max(), Min()
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Scalar Functions
www.ManzoorTheTrainer.com

Grouping Result Set


www.ManzoorTheTrainer.com

Grouping Result Set


● Group By
● Having
● FWGHO
○ The FROM clause assembles the data from the data sources.
○ The WHERE clause restricts the rows based on the conditions.
○ The GROUP BY clause assembles subsets of data.
○ Aggregate functions are calculated.
○ The HAVING clause filters the subsets of data.
○ Any remaining expressions are calculated.
○ The ORDER BY sorts the results.
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Group By
www.ManzoorTheTrainer.com

Joins (Multiplication)
● Joins : Used to extract data from multiple tables.
○ Inner Join
○ Left Outer Join
○ Right Outer Join
○ Full Outer Join
www.ManzoorTheTrainer.com

Inner Join
Get only the matched rows from left(child) and the right(master) table.
www.ManzoorTheTrainer.com

Left Outer Join


Get all the rows from left(child) and matched rows from the right(master) table.
www.ManzoorTheTrainer.com

Right Outer Join


Get only the matched rows from left(child) and all rows from the right(master) table.
www.ManzoorTheTrainer.com

Full Outer Join


Get all the rows from left(child) and the right(master) table.
www.ManzoorTheTrainer.com

Writing Join Query

inner join or left outer join or right outer join


www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Joins
www.ManzoorTheTrainer.com

Joining Three Tables


www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Joining three tables
www.ManzoorTheTrainer.com

Self Join
● Joining a table with itself
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Self Join
www.ManzoorTheTrainer.com

Union (Addition)
● Union : Used to append records of more than one table
○ Union All (A U B with duplicate records)
○ Union (A U B without duplicate records)
○ Intersect (A ⋂ B)
○ Except (A - B)
www.ManzoorTheTrainer.com

Union ALL
www.ManzoorTheTrainer.com

Union
www.ManzoorTheTrainer.com

Intersect
www.ManzoorTheTrainer.com

Except
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Union
www.ManzoorTheTrainer.com

Sub Queries
● Subquery or Inner query or Nested query is a query inside a query.
● Simple Subqueries : Outer query is executed based upon the results of inner query.
○ Scalar Subqueries
○ Multivalued Subqueries
● Correlated Subquery :
○ It is a sub-query that uses values from the outer query.
○ In this case the inner query has to be executed for every row of outer query.
● Common Table Expression (CTE) (Alternate To Views) :
○ It defines the subquery at the beginning of the query using the WITH
command called as CTE
○ CTE can then be accessed multiple times below CTE in main query.
www.ManzoorTheTrainer.com

Scenario - Simple Subquery

● Get the subject name which has got the highest marks. (Simple Scalar Subquery)
● Get the students who are taking Maths exam (Nested Scalar Subquery)
● Get the students who has not taken at least one exam (Multivalued Subquery)

Note: A LEFT [OUTER] JOIN can be faster than an equivalent subquery.


www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Simple SubQueries
www.ManzoorTheTrainer.com

Scenario - Correlated Subquery

● Get the employee details with lowest salary from every department.
● Get the topper student details from every subject.
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Correlated SubQueries
www.ManzoorTheTrainer.com

Views
● A view is a list of columns or a series of records retrieved from one or more
existing tables, or as a combination of one or more views and one or more tables.
● Use views to denormalize or simplify complex joins and hide any keys used to
link data within the database schema.
● In other words it is use full for generating various reports easily.
www.ManzoorTheTrainer.com

Senario - Views

● Get the subject name and number of students taking exam on that subject.
● Get the student name, subject name and marks they get in that subject.
● Get the student name and total mark they got.
www.ManzoorTheTrainer.com

Demo
Let’s see a demo for views
www.ManzoorTheTrainer.com

DML On Views
● You can perform all operation on a view that is based on one table, that would be
entered on the base table.
● You can perform only select & update operations on a view which is based on
multiple table, that would affect the base tables.
www.ManzoorTheTrainer.com

Demo
Let’s see a demo for DML on views
www.ManzoorTheTrainer.com

Scenario - Common Table Expression Subquery


Common Table Expression (CTE) (Alternate To Views) : It defines the subquery at
the beginning of the query using the WITH command called as CTE. It can then be
accessed multiple times below CTE in main query

● Get department name and number of employees in each dept along with
department name and total salary being paid to every department
www.ManzoorTheTrainer.com

A Simple CTE
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on CTE SubQueries
www.ManzoorTheTrainer.com

Stored Procedures
● Stored Procedure is precompiled set of one or more SQL statements which
performs some specific task.
● Store Procedure should be executed stand alone using EXEC.
● Store Procedure can return multiple parameters.
● Store Procedure can be used to implement transaction.
● Create, Alter and Drop Stored Procedures
○ With No Parameters and No Return values
○ With Parameters and No Return values
○ With Parameters and Return values
www.ManzoorTheTrainer.com

Scenario - Stored Procedure

● Get all the employees with department details.


● Get all the employees with department details of a particular department.
● Get the salary of a particular employee.
www.ManzoorTheTrainer.com

Demo
Let’s see a demo for Stored Procedures
www.ManzoorTheTrainer.com

Scenario - Stored Procedure With If Else

● Get all the employees with department details when department Id is not passed
or NULL else all the employees with department details of a particular
department.
www.ManzoorTheTrainer.com

Demo
Let’s see a demo for Stored Procedures
www.ManzoorTheTrainer.com

Functions
● A Functions is a section of code that performs an independent task.
● Function cannot be executed stand alone, it is always used in a query like with
select clause.
● Functions can return one and only one parameter.
● We cannot implement transaction using functions.
www.ManzoorTheTrainer.com

Senario - Function

● Get the student name, total mark they got along with grade. Where grade is the
value returned from GetGrade() function.
www.ManzoorTheTrainer.com

Demo
Let’s see a demo for functions
www.ManzoorTheTrainer.com

Transactions
● Transaction is a set of operation (SQL Queries) which must be executed as a
group.
● If at all a single operation fails then all the previous operation of that group must
be rolled back i.e., undone.
www.ManzoorTheTrainer.com

Scenario - Transaction

● Write a transaction to transfer 2000 from Jack’s Account to Lilly’s Account


www.ManzoorTheTrainer.com

Slowly Changing Dimensions


● Dimensions that change slowly over time, rather than changing on regular
schedule, time-base.
● In Data Warehouse there is a need to track changes in dimension attributes in
order to report historical data.
● Eg: Salary of employee, City of a customer, Class of a student, etc.,
www.ManzoorTheTrainer.com

SCD - Senario Salary History


www.ManzoorTheTrainer.com

Scope_Identity()
● How to get the EmpId value to insert in SalaryHistory table?
● As EmpId is identity column.
● Scope_Identity function returns the recent generated identity value (that is auto
incremented values) for that particular scope i.e., user.
www.ManzoorTheTrainer.com

Demo
Let’s see a demo for ScopeIdentity()
www.ManzoorTheTrainer.com

Scenario - Transaction

● What if insertion in SalaryHistory Fails?


● Write a transaction to maintain employee salary history.
○ Insert.
○ update.
www.ManzoorTheTrainer.com

Demo
Let’s see a demo for Transactions
www.ManzoorTheTrainer.com

Triggers
● A trigger is an action that is performed behind-the-scenes when an insert, update
or delete operation has been performed on a table.
● The trigger must be created in connection to a table of a non-system database
● Triggers are of 2 types in SQL Server:
● DML Triggers
○ AFTER Triggers
○ INSTEAD OF Triggers
● DDL Triggers
www.ManzoorTheTrainer.com

Creating Triggers
www.ManzoorTheTrainer.com

Demo
Let’s see a demo for Triggers
www.ManzoorTheTrainer.com

Insert Operation
Department Inserted Table

DID Name Description DID Name Description

103 Development Dev Dept


100 Testing Testing Dept

101 Admin Admin Dept


Deleted Table
102 HR HR Dept
DID Name Description

103 Development Dev Dept

Insert a record
www.ManzoorTheTrainer.com

Demo
Let’s see a demo for Inserted Table
www.ManzoorTheTrainer.com

Update Operation
Department Inserted Table

DID Name Description DID Name Description

103 Dev Dev Dept


100 Testing Testing Dept

101 Admin Admin Dept


Deleted Table
102 HR HR Dept
DID Name Description

103 Development
Dev Dev Dept
103 Development Dev Dept

Update a record
www.ManzoorTheTrainer.com

Demo
Let’s see a demo for Updated Table
www.ManzoorTheTrainer.com

Delete Operation
Department Inserted Table

DID Name Description DID Name Description

100 Testing Testing Dept

101 Admin Admin Dept


Deleted Table
102 HR HR Dept
DID Name Description

103 Dev Dev Dept


103 Dev Dev Dept

Delete a record
www.ManzoorTheTrainer.com

Demo
Let’s see a demo for Deleted Table
www.ManzoorTheTrainer.com

Some Admin Tasks


● Database Backup
● Database Restore
● Generate DB Script
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Admin Tasks
www.ManzoorTheTrainer.com

Assignment
● Write a query which takes the OrderId
as input and displays all the customer
details and product details along with
the last date of order delivery.

● Write a query to display the details of


a customer with highest number of
orders.

● Write a query to display the business


generated from each country.

Note : Product should be delivered with in 10


days of order placed.
www.ManzoorTheTrainer.com

Thanks
Ask any questions if you have...
www.ManzoorTheTrainer.com

Learn C#.Net Core From Scratch


With Real World Examples
Mohd Manzoor Ahmed [MCT]
manzoor_trainer manzoorthetrainer.com
www.ManzoorTheTrainer.com

Prerequisite
● You should know how to use computer.
● Install Visual Studio 2017 Community Edition
https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=Commu
nity&rel=15
● Operating System : Windows 10 version 1507 or higher, Windows 8.1 (with
Update 2919355), Windows Server 2012 R2, Windows 7 SP1
● Processor : Intel - 1.8 GHz or faster processor. Dual-core or better recommended
● RAM : 2 GB of RAM; 4 GB of RAM recommended
● Hard Disk Space :up to 130 GB of available space, depending on features installed;
typical installations require 20-50 GB of free space.
www.ManzoorTheTrainer.com

.Net Flavours
● .Net Framework
● .Net Core (Our Course Focus)
www.ManzoorTheTrainer.com

What is .Net ?
● What can we do with .Net?
○ We can develop applications like Console App, Windows App, Web App,
Mobile App, Web services, Windows services, etc.,
● Why .Net?
○ Because it is a language and OS neutral platform.
● What is .Net?
○ It is a language and OS neutral platform on which we can develop any kind
of applications.
.NET Framework Vs .NET Core
.NET Framework 4.6
● It is our old framework enhanced that we have been using for more than a decade.
● It is not open source
● It can target only windows OS
● It has all the components like Windows Form Application, ASP.Net Web Forms,
ASP.Net MVC, ASP.Net Web API, ASP.Net SignalR, ASP.Net Web Pages, WPF,
WCF, etc.,
.NET Core X.X (1, 2, 3, …)
● It is a new framework similar to .net framework maintained by Microsoft and the
.NET community on GitHub.
● It is open source.
● It can target Windows, Linux & Mac OS.
● It does not have all the components, It just has ASP.Net Core and Universal
Windows App.
“.Net was language neutral,
.Net Core is OS neutral.”
- www.ManzoorTheTrainer.com
www.ManzoorTheTrainer.com

Language Neutral
● Same class library with different syntax
○ Console::WriteLine(L"C++ Hello, World!");
○ Console.WriteLine("C# Hello, World!");
○ Console.WriteLine ("VB Hello, World!")
www.ManzoorTheTrainer.com

Get Started With Our First C# Program


● Write a program in any text editor say notepad.
● Compile the program from developer command prompt.
● Run the program.

Assembly
IL
First.cs Compile (CSC) Execute Output
MSIL
(.dll or .exe)
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on C# First Program
www.ManzoorTheTrainer.com

Assemblies
● Assemblies are the building blocks of .NET Framework applications; they form
the fundamental unit of deployment.
● An Assembly is a logical unit of code.
● Assembly physically exist as DLLs or EXEs.
● Every assembly file contains:
○ Information about itself called as Assembly Manifest.
○ Information about classes called as Metadata.
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Assemblies
www.ManzoorTheTrainer.com

Getting Started With Visual Studio 2017


● Getting familiar with projects targeting and visual studio 2017.
● Write a hello world program.
● Understand Console.WriteLine() string formatting.
● Understand Console.ReadLine() string parsing.
● Writing a simple program for arithmetic operations.
● Understand Type Casting.
● Understanding how to debug a program.
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Getting Started
www.ManzoorTheTrainer.com

Data Types - Value Type


● Signed integral: sbyte, short, int, long
● Unsigned integral: byte, ushort, uint, ulong
● characters: char
● floating point: float, double
● Boolean: bool
● Enum types
● Struct types
● Nullable value types

Note : Ranges : https://msdn.microsoft.com/en-us/library/s3f49ktz.aspx


www.ManzoorTheTrainer.com

Data Types - Ref Type


● string
● Array
● Class : object
● Interface
www.ManzoorTheTrainer.com

Control Structures
● Conditional Statements ● Iterative Statements
○ If ○ For
○ If else ○ While
○ Else if ladder ○ Do while
○ Switch case default ○ foreach
● UnConditional Statements
○ Goto
○ Continue
○ break
○ return
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Control Structures
www.ManzoorTheTrainer.com

Assignment
Write a C# program which takes current meter reading (CMR), previous meter
reading (PMR) and type of connection as input and displays the bill amount.

● Domestic consumers: ● Non-domestic/Commercial:


○ 0-200 units: Rs 5 per unit ○ 0-100 units: Rs 7.50 per unit
○ 201-300: Rs 7.20 per unit ○ 101-300: Rs 8.90 per unit
○ 301-400: Rs 8.50 per unit ○ 301-500: Rs 9.40 per unit
○ 401-800: Rs 9 per unit ○ Above 500: Rs 10 per unit
○ Above 800 units: Rs 9.50 per unit
www.ManzoorTheTrainer.com

Arrays
● It is a user defined collection of homogeneous data type elements.
● We use index to access an element of an array.
● When declaring an Array, specify the type, name, dimensions, and size.
● int[ ] myArray = { 5, 10, 15 };
● int[] myArray = new int[3];
○ myArray[0]=5;
○ myArray[1]=10;
○ myArray[2]=15;
● Int[,] my2dArray = new int[2,3];
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Arrays & foreach Loop
www.ManzoorTheTrainer.com

Structures
● It is a user defined collection of
heterogeneous data type elements.
● We use period operator to access
an element of the structure.
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on Structures
www.ManzoorTheTrainer.com

Struct vs Classes
● Structs Only:
○ Cannot support inheritance
○ Are value types
○ Are passed by value (like integers)
○ Cannot have a null reference (unless Nullable is used)
○ Do not have a memory overhead per new instance - unless 'boxed'
● Classes Only:
○ Can support inheritance
○ Are reference (pointer) types
○ The reference can be null
○ Have memory overhead per new instance
● Both Classes and Structs:
○ Are compound data types typically used to contain a few variables that have some logical
relationship
○ Can contain methods and events
○ Can support interfaces
www.ManzoorTheTrainer.com

var Vs dynamic
● var is static typed. It identifies the variable type at compile time itself.
○ var type is fixed with initialization
○ var x=”ManzoorTheTrainer”;
● dynamic is a runtime dispatch type. It identifies the variable type at runtime.
○ dynamic x=”ManzoorTheTrainer”;
○ dynamic type can changes where it is required
www.ManzoorTheTrainer.com

Demo
Let’s see a demo on var Vs dynamic
www.ManzoorTheTrainer.com

Object Oriented Programming Through C#


Student

● Objects ● rollNo
○ Jack Properties ● name
● marks
○ Peter
Class
○ John
● getDetails()
Methods
● getResult()
www.ManzoorTheTrainer.com

Object & Class


● Object
○ Any real time entity is called as an object.
○ Every object consist of state(look and feel) and behaviour(what is does).
○ States are called as properties and behaviors are called as methods.
● Classes
○ Class is a blueprint of an object.
○ It consist of fields which are not allowed to access from outside the class.
○ It also consist of methods which are allowed to access from outside the class.
www.ManzoorTheTrainer.com

Fields

Defining A Class
● Defining A Class
● Defining Fields
● Defining Methods
Methods
● Public and Private specifiers
www.ManzoorTheTrainer.com

Demo
For Defining A Class
www.ManzoorTheTrainer.com

Object Creation
● Creating Object
● Accessing Method
www.ManzoorTheTrainer.com

Demo
For Object Creation
www.ManzoorTheTrainer.com

Constructor
● Why do i need constructor?
● Creating a constructor
www.ManzoorTheTrainer.com

Constructor
● It’s a special method with same name as class name
● Usually constructor is public.
● It won’t have any return type.
● It may or may not have parameters.
● Constructor with no parameters is called as default constructor.
● Constructor is invoked automatically when we create an object.
● You cannot invoke constructor explicitly.
● It is used to initialize an object.
www.ManzoorTheTrainer.com

Demo
For Constructor
www.ManzoorTheTrainer.com

Constructor Overloading
● If we have more than one constructor
with different parameters then we call
it as constructor overloading
www.ManzoorTheTrainer.com

Demo
For Constructor Overloading
www.ManzoorTheTrainer.com

this Keyword
● this keyword is a default object of
current class.
● In what ever class we use “this” keyword
it acts like its object
● ‘this’ keyword has two uses.
● ‘this’ keyword is used to refer the
members of same class.
● It is also used to invoke a constructor
from another constructor of the same
class.
www.ManzoorTheTrainer.com

Demo
For this Keyword
Method Overloading
www.ManzoorTheTrainer.com

Compile Time or Static


Polymorphism
● If a class contains more than one
method with same name and different
parameters then we call this as method
overloading
www.ManzoorTheTrainer.com

Demo
For Method Overloading
www.ManzoorTheTrainer.com

Properties
● Properties are special kind of methods to access
any field in a secured way.
● It contains two kind of methods i.e., getter and
setter.
● Getter method is to read the value of the
private field.
● Setter method is to write the value of the
private field.
● It looks like we are accessing the fields directly.
But, internally it works as methods where we
can perform some kind of validations.
www.ManzoorTheTrainer.com

Demo
For Properties
www.ManzoorTheTrainer.com

Latest Style Of Class


● With auto properties
● Latest style of object creation
www.ManzoorTheTrainer.com

Demo
For Latest Class Style
www.ManzoorTheTrainer.com

Static Variables
● Any member of a class declared with
the keyword static is called as static
member.
● Memory for static variable is allocated
only once and is shared by all the
objects of that class.
● We can access static variables with
directly with the class name if they are
public.
www.ManzoorTheTrainer.com

Demo
For Static Variables
www.ManzoorTheTrainer.com

Static Constructor
● Static constructor is a constructor
which is declared with the keyword as
static.
● Static constructor is use to initialize
static variables (private).
● Static constructor does not have any
access modifiers (i.e,Public,Private).
● Static constructor is parameter less.
● There can be one and only one static
constructor in a class.
● Static Constructor is invoked before
creation of any object.
www.ManzoorTheTrainer.com

Demo
For Static Constructor
www.ManzoorTheTrainer.com

Static Methods
● Static method is a method which is
declared with the keyword static.
● There can be n number of static
methods in a class.
● Static methods can access only static
variables.
● Static method can be directly accessed
by Class name.
www.ManzoorTheTrainer.com

Demo
For Static Methods
www.ManzoorTheTrainer.com

Static Class
● Static class is a class which is declared
with static keyword.
● Static class should contain only static
methods.
● Static class does not allow creation of
class reference or object.
● Like Console is a predefined static
class which contains all static methods
like WriteLine()
www.ManzoorTheTrainer.com

Demo
For Static Classes
www.ManzoorTheTrainer.com

Namespaces
● Namespaces are logical group of
classes and namespaces.
● It is used for avoiding name clashes
between two sets of code.
www.ManzoorTheTrainer.com

Demo
For Namespaces
www.ManzoorTheTrainer.com

Reusable Component Or .dll


UI / PLL BLL
Windows
App

Organization.dll
Web App Employee.cs
GetSalary()
Console
App

Note : Every UI/PLL will have a local copy of dll, any changes made dll will not be reflected
automatically
www.ManzoorTheTrainer.com

Organization.dll
● Create a new project Organization.
● Create a class Employee
● Create a method GetSalary()
● Create a Console UI
● Add dll reference
● Add namespace
● Create Object of Employee
● Call GetSalary
● Public and non public class
www.ManzoorTheTrainer.com

Demo
For dll Consumption in ConsoleUI
www.ManzoorTheTrainer.com

.Net Standard Library


● Let’s use Organization.dll in Windows
Classic App.
● Let’s Create .Net standard library.
● .Net standard library can consumed by
both Classic .Net and .Net Core Apps.
www.ManzoorTheTrainer.com

Demo
For .Net Standard Library
www.ManzoorTheTrainer.com

Inheritance
● Deriving a new class from an existing
class is called Inheritance.
● Existing class is called as base class.
● New class is called as derived class.
● Everything from the base class gets
inherited except private members.
IS - A
www.ManzoorTheTrainer.com

Demo
For Inheritance
www.ManzoorTheTrainer.com

Types Of Inheritances
● Single Inheritance : If a derived class has a
single base class then it is called as single Single
inheritance i.e., A(Base) → B (Derived)
● Multilevel Inheritance : If a class is derived
from a class which is already a derived class
then it is called as multi level inheritance.
i.e., A(Base) → B (Derived) → C(Derived)
● Multiple Inheritance : If a class is derived
from more than one class then it is called as
which is already a derived class then it is
called as multiple inheritance.i.e., A,B(Base) Multilevel
→ C(Derived)
● C# does not support multiple inheritance
using classes.
www.ManzoorTheTrainer.com

Demo
For Types Of Inheritance
www.ManzoorTheTrainer.com

Protected Members
● Protected members of a classes can be
inherited in the child class.
● Protected members of a class cannot
be accessed from outside of a class.
www.ManzoorTheTrainer.com

Demo
For Protected Members
Constructor Chaining (Or)
www.ManzoorTheTrainer.com

base keyword
● Any constructor of child class always
invokes default constructor of base
class.
● Calling the base class constructor
from the child class’ constructor using
base keyword is called as constructor
chaining.
● base keyword is a default object of its
base class.
● It is also used to refer the members of
base class from derived class.
www.ManzoorTheTrainer.com
www.ManzoorTheTrainer.com

Method Overriding
● If a method in the derived class has the
same signature as that of in the base
class with different implementation
then we say that method in the derived
class overrides the method of base
class.
● This process is called as Method
Overriding.
● The method of the base class should be
declared as virtual and method in
derived class should be declared as
override.
www.ManzoorTheTrainer.com

Other Use Of base


● base keyword is also used to refer the
members of base class from derived
class.
www.ManzoorTheTrainer.com

Demo
For Method Overriding
www.ManzoorTheTrainer.com

Sealed Method & Class


● A sealed method is a method which is
declared with the keyword sealed and it
cannot be overridden by the derived
class.
● But we can invoke this method.
● Sealed keyword is always used in
combination with override keyword.
● A sealed class is the class which is
declared with the keyword sealed and it
cannot be derived by other classes.
● But we can create the objects of sealed
class
www.ManzoorTheTrainer.com

Demo
For Sealed Methods And Classes
www.ManzoorTheTrainer.com

Abstract Method
● An abstract method is a method which
is declared with the keyword abstract.
● It does not have body.
● It should be implemented by the
derived class.
● If a method is abstract then the class
should be abstract.
www.ManzoorTheTrainer.com

Demo
For Abstract Method
www.ManzoorTheTrainer.com

Abstract Class
● It is the blueprint of the problem.
● It says what to do but not how to do.
● An abstract class is the class which is
declared with the keyword abstract.
● Basically it contains at least one
abstract method.
● It’s object cannot be created.
● But it’s reference can be created.
● It is used to implement runtime
polymorphism.
www.ManzoorTheTrainer.com

Demo
For Abstract Class
www.ManzoorTheTrainer.com

Runtime or Dynamic Polymorphism


● Deriving the abstract class by one or more classes and overriding all the abstract
methods.
● Creating the reference of abstract class and making it an object of derived class
based on user’s input.
● And calling the method of abstract class.
● The method gets referred from derived class at runtime based on user input.
● This complete process is called as runtime polymorphisms.
Runtime or Dynamic Polymorphism
www.ManzoorTheTrainer.com
Runtime or Dynamic Polymorphism
www.ManzoorTheTrainer.com
www.ManzoorTheTrainer.com

Demo
For Runtime Polymorphism
www.ManzoorTheTrainer.com

Interface
● An interface is a pure abstract class.
● It is a reference type and it contains only
abstract members.
● Any implementation must be placed in
class that implements them.
● All the member declarations inside
interface are implicitly public and
abstract.
● We can implement multiple inheritance
using interfaces.
www.ManzoorTheTrainer.com

Demo
For Interfaces
www.ManzoorTheTrainer.com

Partial Class
● Partial class is a class which is declared
with partial keyword.
● Its implementation can be spread over
multiple files.
● Multiple classes prefixed with partial
keyword with same class name and
different methods in different files, acts
as a single class with all the methods.
www.ManzoorTheTrainer.com

Demo
For Partial Classes
www.ManzoorTheTrainer.com

Collection Classes
● Collection is an alternate way of storing
multiple variable number of elements or
objects.
● Like Stack, Queue, ArrayList , etc., are
collection classes present in
System.Collection namespace
● There is no type safety in collection
classes i.e., in a collection object of a
Queue we can store few integers and few
strings.
● We need to type cast the elements while
accessing it.
www.ManzoorTheTrainer.com

Demo
For Collection Classes
www.ManzoorTheTrainer.com

Generic Collection Classes


● Generic collection is an alternate way of
storing multiple variable number of
elements or objects.
● Like Stack, Queue, List , etc., are generic
collection classes present in
System.Collection.Generic namespace
● There is type safety in generic collection
classes i.e., in a generic collection object
of a Queue we cannot store few integers
and few strings.
● Hence it is strongly typed.
● We need not to type cast the elements
while accessing it.
www.ManzoorTheTrainer.com

Demo
For Generic Collection Classes
www.ManzoorTheTrainer.com

Exception Handling
● Runtime error is called as an exception.
● Exception handling is an in-built
mechanism in .NET core to detect and
handle runtime errors.
● C# provides three keywords try, catch
and finally to do exception handling.
● The try encloses the statements that
might throw an exception.
● The catch handles an exception if one
exists.
● The finally can be used for doing any
clean up process.
www.ManzoorTheTrainer.com

Demo
For Exception Handling
www.ManzoorTheTrainer.com

Thanks
www.ManzoorTheTrainer.com

Learn Entity Framework


Core From Scratch
Mohd Manzoor Ahmed [MCT]
manzoor_trainer manzoorthetrainer.com
www.ManzoorTheTrainer.com

Prerequisite
● Learn MS SQL Server From Scratch
● Learn C#.Net Core From Scratch
www.ManzoorTheTrainer.com

What is EF ?
● Entity framework is the latest technology provided by ADO.net for accessing
database.
● It is an O/RM tool (Objects Relation Mapping).
● It provides easy and automated way of mapping between Objects(Classes) and
Relations(Tables).
● It auto generates most of the data-access code.
www.ManzoorTheTrainer.com

Why Use O/RM?


● It provides full intelliSense support
for columns names and table
names.(Strongly Typed)
www.ManzoorTheTrainer.com

What is EF Core ?
● EF Core is an O\RM tool.
● Entity Framework Core is the latest data access technology for .Net developers.
● EF Core has almost same interface as EF6.X.
● EF Core can be used to access NoSQL DB. Where as EF6.X cannot.
● EF Core can run on Windows, Linux, and Apple. Where as EF6.X is only for Win.
● There are two approaches of working with EF Core
○ Code-First
○ Database-First (Reverse Engineering)
www.ManzoorTheTrainer.com

Code-First Approach
In the Code-First approach, you focus on your application and start creating classes for
it and we call them as business entities or business objects.
Getting Started
www.ManzoorTheTrainer.com

With EF Core
● Start a new .Net Core Console App
● Install - Nuget Packages
● Microsoft.EntityFrameworkCore.SqlServer
● Create an Entity Department
EF Core DbContext
www.ManzoorTheTrainer.com

● Create a DbContext Class


● DbContext is the top-level object
that manages database connection
and provides the functionalities on
database like Create, Read, Update,
and Delete operations.
● Our main data access class using
which we perform all the
operations should be inherited
from DbContext class.
DbSet<TEntity>
www.ManzoorTheTrainer.com

● Our OrganizationContext Class


Should have DbSet<Department>
properties for each entity or object.
● DbSet<TEntity> is used to perform
CRUD operations on TEntity.
● Using Departments property, we
can perform CRUD operations on
Department table with the help of
OrganizationContext object.
www.ManzoorTheTrainer.com

Creating A
Database - 5 Steps
1. Install - Nuget Packages
Microsoft.EntityFrameworkCore.Tools
2. Override OnConfiguring() method in
OrganizationContext with connection
string.
3. Open Package Manager Console and
run the below commands
4. add-migration OrganizationDb
5. update-database
www.ManzoorTheTrainer.com

Updating Database Structure


● Creating a new migrations. (add-migration <Name>)
● Updating database (update-database)
● Reverting a migration (update-database <Old-Migration-File-Name>)
● Removing a migration (remove-migration) (it will remove the recent migration)
● Generating DbScript (script-migration)
www.ManzoorTheTrainer.com

Solution To A Given Problem


● Identify Objects
● Identify Relationship among the objects
www.ManzoorTheTrainer.com

Entities Design Task - 1 [Organization Management System]


● An organization has multiple number of departments
● An organization has multiple number of employees
● A department can have multiple number of employees
● An employee cannot belongs to multiple departments

● Objects ● Relationship
○ Department ○ Department - Employee
○ Employee ○ 1→n
○ n→1
○ 1 → n (1:M)
www.ManzoorTheTrainer.com

3 Rules For Creating Entities Or Business Objects - #1


● One class for each object → Department.
www.ManzoorTheTrainer.com

Relationship(1:M) - #2
● Department will have list of employees and Employee will refer to a single department.
www.ManzoorTheTrainer.com

Entities Design Task - 2 [School Management System]


● A school has multiple number of courses
● A school has multiple number of students
● A student can opt in for multiple number of courses
● A course can be opted by multiple number of students

● Objects ● Relationship
○ Course ○ Course - Student
○ Student ○ 1→n
○ n→1
○ n → n (M:M)
www.ManzoorTheTrainer.com

Relationship(M:M) - Entities - #3
● Student will have list of Student_Course
● Course will also have list of Student_Course
● It will have a new entity Student_Course referring to Student & Course
www.ManzoorTheTrainer.com

Relationship(M:M) - Tables
www.ManzoorTheTrainer.com

Entity Design Task - 3 [Stock Management System]


● A Toy manufacturing company manufactures different types of toys.
● The company has several manufacturing plants.
● Each plant manufactures different types of toys.
● A customer can place order for these toys.
● Each customer has multiple ship-to addresses.
www.ManzoorTheTrainer.com

Objects And Relationship


● Objects ● Relationship
○ Plant ○ Plant : Category (1→ n)(1:M)
○ Category ○ Category : Toy (1 → n)(1:M)
○ Toy ○ Customer : ShipToAddress (1 → n)(1:M)
○ Customer ○ Customer : Toy (n → n) {Order}(M:M)
○ ShipToAddress
○ Order
www.ManzoorTheTrainer.com

Entity Design Task - 4 [IT Operation Management System]


Need a web app for IT Operation Management System

● The Employee can raise a request with status open for a new hardware or
software component to be installed on their system.
● Employee can also raise a request with status open for update or repair of an
existing hardware or software component.
● IT Manager has rights to approve or reject the request. on approval, the request is
assigned to IT Assistant.
● IT Assistant can then works on it and completes the task and change the request
status to completed.
● Finally IT Manager has rights to close the completed request.
www.ManzoorTheTrainer.com

Defining the Roles & Responsibilities


● Employee
○ Can raise a request.
● IT Manager
○ Can approve, reject or closes a request.
○ Can assign it to an IT Assistant on approval.
● IT Assistant
○ Can work on a request assigned to him\her .
○ Can change the status of request to completed.
www.ManzoorTheTrainer.com

Identifying the Objects


Need a web app for IT Operation Management System

● The Employee can raise a request with status open for a new hardware or
software component to be installed on their system.
● Employee can also raise a request with status open for update or repair of an
existing hardware or software component.
● IT Manager has rights to approve or reject the request. on approval, the request is
assigned to IT Assistant.
● IT Assistant can then works on it and completes the task and change the request
status to completed.
● Finally IT Manager has rights to close the completed request.
www.ManzoorTheTrainer.com

Identifying the Objects


Objects

● Employee
● IT Manager
● IT Assistant
● Component
● Request
● Status
www.ManzoorTheTrainer.com

Identifying the Objects and Relationships


Object Relationships

● Role (M | A | U) ● Role : Employee (1 : M)


● Employee ● Employee : Request (1 :M)
● Request
● Component
● Status (OP | AP | RJ | CM | CS)
Data Annotations Attributes
www.ManzoorTheTrainer.com

● Table()
● Column()
● Key
● Required
● MaxLength()
● DatabaseGenerated()
● ConcurrencyCheck
● NotMapped
● ForeignKey()
www.ManzoorTheTrainer.com

CRUD - Insert
● Insert
www.ManzoorTheTrainer.com
CRUD - Update
● Update
CRUD - Delete
www.ManzoorTheTrainer.com

● Delete
CRUD - Select
www.ManzoorTheTrainer.com

Note : Property in an entity which represents (Primary -Foreign key) relationship with another entity is
called as navigation property. As here Department is navigation property in Employees
www.ManzoorTheTrainer.com

Immediate Vs Deferred Mode Of Execution


● Immediate Mode:
○ In Immediate mode of query execution query gets executed wherever the query is
defined. and it is achieved with the help of linq methods like ToList(), Count() etc.
○ Here query object holds the data which reduces number of hits to SQL server on every
request.
○ Return type can be List Or IEnumerable
● Differed Mode:
○ In Differed mode of query execution, Query is executed whenever we use it like,
when we access a field or iterating through a List.
○ Here query object hits the server on every request which reduces the size of query
objects.
○ Return type can be IQueryable or IEnumerable

Note : IEnumerable is read-only and List is not.


Immediate Vs Deferred Mode Of Execution
www.ManzoorTheTrainer.com

Immediate Mode Of Execution Deferred Mode Of Execution


www.ManzoorTheTrainer.com

Eager Loading Vs Explicit Loading Vs Lazy Loading


● Eager Loading: If we write a select query on parent table, it not only loads Parent
table records but also automatically loads its related table records. It is achieve with
the help of Include() method.
● Explicit Loading: If we write a select query on parent table, it loads only parent table
records and the child table records are loaded explicitly with the help of Collection()
or Reference() methods whenever we access the related table with navigation
property.
● Lazy Loading: (Microsoft.EntityFrameworkCore.Proxies)If we write a select query on
parent table, it loads only parent table records and the child table records are loaded
automatically whenever we access the related table with navigation property. (Not
Eager Loading Vs Explicit Loading Vs Lazy Loading
www.ManzoorTheTrainer.com
Working With Raw SQL in
www.ManzoorTheTrainer.com

EF Core
● EF Core allows you to work with Raw
SQL.
● It is useful if the query you want to
perform can't be expressed using LINQ.
● If using a LINQ query is resulting in
inefficient SQL being sent to the
database.
● Use : FromSql(), ExecuteSqlCommand()
● Limitations :
https://docs.microsoft.com/en-us/ef/core/
querying/raw-sql
Working With Stored
www.ManzoorTheTrainer.com

Procedures EF Core
● Create An empty migration file.
● PM> Add-migration All_SPs.
● Create SPs in Up() and drop SPs in
Down() of generated migration file.
● Use : FromSql(), ExecuteSqlCommand()
to execute an existing stored procedure.
● With return type as an existing entity.
● With Custom return type.
Default Transaction
www.ManzoorTheTrainer.com

In EF Core
● Say we are inserting 1 record and
updating 2 records and finally calling
SaveChanges().
● By default, SaveChanges() are applied in
a transaction.
● Which means If any of the operations
fail, then the transaction is rolled back.
● You can also manually control
transactions if you have multiple
SaveChanges() method Call.
Manually Controlling
www.ManzoorTheTrainer.com

Transaction In EF Core
● You can also manually control
transactions if you have multiple
SaveChanges() method Call.
● We use the DbContext.Database to begin,
commit, and rollback transactions.
● Transactions are always applied on try
catch blocks
www.ManzoorTheTrainer.com

2 - Layered Approach - .Net Core Library


.Net FWK
ASP.Net
Web Forms

UI
EF Core
MS SQL
DAL Server
.Net Core
Console App

UI

BOL - Entities
www.ManzoorTheTrainer.com

3 - Layered Approach - .Net Core Library


.Net FWK
ASP.Net
Web Forms

UI
C#.Net EF Core
MS SQL
BLL DAL Server
.Net Core
Console App

UI

BOL - Entities
www.ManzoorTheTrainer.com

3 - Layered Approach
1. Add BOL
2. For Attributes Install Package :
a. System.ComponentModel.Annotations
3. Add DAL as EF Core Install Packages :
a. Microsoft.EntityFrameworkCore.SqlServer
b. Microsoft.EntityFrameworkCore.Tools
4. add-migration & update-database
5. Write data access classes with repository pattern.
6. Add BLL & Write business classes
7. Add .Net Framework Web Forms UI
8. Install Package In UI :
a. Microsoft.EntityFrameworkCore.SqlServer
www.ManzoorTheTrainer.com

Thank You
Learn HTML & CSS
From Scratch
Mohd Manzoor Ahmed [MCT]
manzoor_trainer manzoorthetrainer.com
What Are We Going To Learn?
● Introduction To HTML ● Images
● Page Structure ● Static Vs Dynamic Pages
● Tags ● Forms
● Comments And Page Information ● Introduction To CSS
● Document Structure ● Approaches Of Applying Style
● Links ● CSS Selectors
● Text Markup ● Develop A Static Web Site
● Lists
● Tables
Why HTML?
Share information with the world in the form of different pages linked together.
What is HTML?
● HTML stands for HyperText Markup Language.
● It is used to design and develop Web Pages.
○ Simple
○ Browser/Platform Independent
○ Not Case Sensitive
○ A medium for User Interface
Observation..
Let’s observer a real world any page. Say Google.com
<!DOCTYPE>

Page Structure
HTML Or Web Page
A Demo..
● Let us create our first page say MyFirstPage.html.
● You can use any text editor to create a web page, say notepad.
● Its extension should be either htm or html(popularly used).
● We need any browser to run the page, say chrome.
Introduction To Visual Studio
● https://www.visualstudio.com/en-us/news/vs2013-community-vs.aspx

Any Version
<div id=”myDiv”> Hello </div>
Key Value

Open Tag Attribute Content Close Tag

HTML Element
Everything Is A Tag
● The HTML instructions are called Tags. Basically tags are classified into two
categories.
● Container Tags :Tags that have starting as well as ending part.
○ e.g.: <TITLE>Title of the Web Page </TITLE>
● Empty Tags : Tags that do not have the closing part.
○ e.g.: <br>
● HTML instructions + text to which the instructions apply is an HTML element.
Attributes
● A key value pairs inside the tag which defines the some features of text are called
as Attributes.
● Some important attributes of the BODY tag
○ BGCOLOR = “color” / “#rrggbb”
○ BGPROPERTIES=”FIXED”
○ BACKGROUND = “url of the image”
○ TEXT = “color” / “#rrggbb”
● Core attributes of other tags inside body.
○ id, name, value and class
Demo..
For Attributes
Comments And Page Information
● <!-- Comment Text -->
● Page information goes into the <head> tag
● Mostly used page information tags are
○ <meta/>
○ <title>
○ <link/>
○ <style>
○ <script>
Demo..
For Page Information
Document Structure
● Below are the mostly used tags to structure the content on the body of the page.
○ <h[1-6]>
○ <div>
○ <span>
○ <p>
○ <pre>
○ <br/>
○ <hr/>
Demo..
For Document Structure Tags
Text Markup
● Tags mostly used to give some different style or look to the text on the body of
page.
○ <strong>
○ <em>
○ <code>
○ <del>
○ <sub>
○ <sup>
Demo..
For Text Markup
Lists
● The tags used to list items either in bullet style or numbered style
○ <ol>
○ <ul>
○ <li>
Demo..
For List
Tables
Most of the page layouts are based upon tables or to show some tabular data on web
pages we some time use tables

● <table> ● <col>
● <caption> ● <tr>
● <thead> ● <th>
● <tbody> ● <td>
● <tfoot>
Demo..
For Tables
Images
● To display images on web page we use image tag i.e.,
○ <img>
Demo..
For Images
Links
● The link tags are also called as anchor tag <a href=’xxx’></a>
● The link tags are used to
○ Link one page to another page .
○ To make a section of page as anchor.
○ One section of page to another section(anchor) of page.
○ Link to send email board
Demo..
For Anchor Tag
Static Vs Dynamic Pages
● Static Web Page ● Dynamic Web Page
● Same content to any user, anywhere ● Content may differ as per the user
● Requires web development expertise request and location
to update site ● Much more functional website
● Site not as useful for the user ● Much easier to update
● Content can get stagnant ● New content brings people back to
the site and helps in the search
engines
Forms
● Whenever we want to interact with end user basically we need a form.
● Forms can be created with the following form tags
○ <form> ○ <select>
○ <fieldset>(I love it) ○ <option>
○ <legend> ○ <textarea>
○ <input>
Demo..
For Form Design
Why CSS?
● As HTML is mark-up language, I say CSS is a make-up language.
● Don’t you want your content look good to the end user
What is CSS?
● CSS stands for Cascading Style Sheets.
● CSS describes how your web page should look.
● For example its layout, color, font, size, etc.,
Observation..
Let’s observer a real world any page. Say Google.com
Three Different Approaches
● There are three different approaches of inserting a style sheet:
○ Inline style
○ Internal style sheet
○ External style sheet
InLine
● It is used to apply style to a single element.
● Eg:
● <div id="myDiv" style="color:white; background-color:linen;">

This is my Div.

</div>

● Not recommended to use extensively.


Demo..
For Inline Style..
Internal
It is used to apply style to a single page.
Demo..
For internal style sheet
External
● It is used to apply style to all page of a web site.
● External style sheet is a file created using any text editor.
● It should have .css as extension
● Every page should refer that file using <link> tag
● Say my style sheet file name is myStyle.css
● The link that I should include in head is
● <head>
<link rel="stylesheet" type="text/css" href="myStyle.css" />
</head>
Demo..
For external stylesheet
Style For Div
Class

Selector
div.x {
Decoration color: red;
text-align: center;
Style For Div
Decoration

}
Property Value
CSS Selectors
● To find an element on the page and map it to the style we use different selectors.
● Few of them are as follows
○ Element
○ id
○ class
○ grouping
element Selector
Select all <div> elements and apply the style.

div {

color: red;

text-align: center;

<div> The content goes here </div>


Demo..
For element selector
id Selector
Select the element with myDiv as id and apply the style.

#myDiv {

color: red;

text-align: center;

<div id=”myDiv”> The content goes here </div>


Demo..
For element selector
class Selector
Select the elements with myClass as class and apply the style.

.myClass {

color: red;

text-align: center;

<div class=”myclass”> The content goes here </div>

<p class=”myclass”> The content goes here </p>


element.class Selector
Select the all Div elements with myClass as class and apply the style.

Div.myClass {
color: red;
text-align: center;
}
<div id= “div1” class=”myclass”> The content goes here </div>

<div id =”div2” class=”myclass”> The content goes here </div>

<p class=”myclass”> The content goes here </p>


Demo..
for class selector
grouping Selector
div {
text-align: center;
color: red;
} div, h2, p {
h2 {
text-align: center; text-align: center;
color: red;
color: red;
}
p{ }
text-align: center;
color: red;
}
Demo..
For grouping selector
css Selector Traversing
ul#menu {
padding: 0;
}
<ul id="menu">
ul#menu li {
display: inline;
<li><a href="/html.htm">HTML</a></li>
}

ul#menu li a { <li><a href="/css.htm">CSS</a></li>


background-color: black;
color: white; <li><a href="/js.htm">JavaScript</a></li>
padding: 10px 20px;
text-decoration: none;
border-radius: 4px 4px 0 0; <li><a href="/php.htm">PHP</a></li>
}
</ul>
ul#menu li a:hover {
background-color: orange;
}
Demo..
For grouping selector
Develop A Static Web Site
● Step 1: Create all pages (Home, About us, Our Services and Contact Us)
● Step 2: Add a list of links to all pages
● Step 3: Create a style sheet
● Step 4: Apply style to all pages

Note: Using free static website templates. www.templatemonster.com


Define Layout
Header

Left Content

footer
Demo..
For developing static website.
Learn JavaScript From Scratch
Mohd Manzoor Ahmed
(Microsoft Certified Trainer | 15+yrs Exp)
What Are We Going To Learn?
● Introduction To JavaScript ● Types Of Variables
● Introduction To Visual Studio ● Events
● Modes Of Execution ● OOPs Through JavaScript
● Data Types In JavaScript ● Object
● Conditional Statements ● Class
● UnConditional Statements ● Properties
● Iterative or Loop ● Methods
● Array Variable Declaration ● List Of Objects
● Functions ● Stand Alone Object/s
Why JavaScript?
● We need responsive HTML pages.
○ React to events.
○ Read and write HTML elements.
○ Validate data.
○ Detect the visitor's browser.
○ Lot more these days....
What is JavaScript?
● JavaScript is a scripting and lightweight programming language.
● It is an interpreted language and requires a browser to run it.
● Everyone can use JavaScript without purchasing any license.
● It is usually embedded directly into HTML pages in script tag inside head tag.
● You can use any text editor to write javascript including HTML
○ <head>
○ <script type=”text/javascript”>
○ ……………….
○ </script>
○ </head>
Display Hello World
● Mostly used methods to display any content at runtime on web page are
○ document.write()
○ console.log()
○ window.alert()
Demo
For “Hello World”
What is JavaScript?
● But these days it is being written in separate file and it’s extension is .js say
myScript.js
● It is being referred in the web pages using script tag at the bottom of the page, i.e.,
after body tag.
○ <html>
○ <head>
○ </head>
○ <body>
○ </body>
○ <script type=”text/javascript” src=”myScript.js”/>
○ </html>
Demo
For .js file
IDE - Introduction To Visual Studio
● https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx

Any Version
Demo
Getting Friendly with Visual Studio 2015
Modes Of Execution
● Immediate mode of script execution is writing script inside body tag and gets
executed as soon as page loads.
● Deferred mode of script execution is writing script in head tag and gets executed
on any event.
Demo
For both immediate and deferred modes
Data Types In JavaScript
● numbers
● strings
● arrays
● objects
● array of objects
Single Variable Declaration
● var x; ● var x=10;
● x=10; ● x=’Peter’;
● or ● x=”John”;
● var x=10; ● x=12.6;
● or
● x=10;
Performing Operations - Require Operators
● Arithmetic : +,-,*,/,%
● Assignment : =, += (x+=y => x=x+y),-=,*=,%=
● Comparison : ==,===,!==,!===,<,<=,>,>=,
Demo
For All Operations
Control Structure
● Controlling the flow of our structure is achieved through the following statements
● Conditional
○ if, if else, else..if ladder and switch..case
● UnConditional
○ break, continue, goto and return. (Covered in functions)
● Iterative or Loop
○ for, while, do while, for/in
Conditional Statements - if else
<script type="text/javascript">
var t=6;
if (t<10) {
document.write("<b>Good morning</b>");
}
else {
document.write("Good day!");
}
</script >
Conditional Statements - else if Ladder
<script type="text/javascript">
var t=16;
if (t<10) {
document.write("<b>Good morning</b>");
}
else if (t>10 && t<16) {
document.write("<b>Good day</b>");
}
else {
document.write("<b>Hello World!</b>");
}
</script>
Demo
For if, if else and else if ladder
Conditional Statements - switch case default
<script type="text/javascript">
theDay=5;
switch (theDay){
case 5: document.write("Finally Friday");
break;
case 6: document.write("Super Saturday");
break;
case 0: document.write("Sleepy Sunday");
break;
default: document.write("I'm looking forward to this weekend!");
}
</script>
Demo
For switch case default
Iterative Statements - for
Syntax

for (statement 1; statement 2; statement 3) {


___________________
}

Ex:

for(i=0;i<10;i++){
document.write(“MTT”+<br/>);
}
Demo
For for loop
Iterative Statements - while
Syntax:
while (condition) {
___________
}

Eg:
i=0;
while(i<10){
document.write(“MTT”+<br/>);
i++;
}
Demo
For while loop
Iterative Statements - do while
Syntax:
do {
_____________
}
while (condition);

Eg:
i=0;
do{
document.write(“MTT”+<br/>);
i++;}
while(i<10);
Demo
For do while
Array Variable Declaration
● An Array is collection of similar type of elements.
● It can be defined in three ways
● Literal Array: var x=[‘Peter’,’John’,’Bob’]; or var x=[]; //best approach
● Condensed Array: var x=new Array(‘Peter’,’John’,’Bob’);
● Regular Array: var x=new Array();
○ x[0]=’Peter’;
○ x[1]=’John’;
○ x[2]=’Bob’;
● length,push(),sort(), reverse().
Demo
For arrays
Iterative Statements - for/in
Syntax:

for(item in list)
{
____________
}

Eg: var people=[‘Peter’,’John’,’Bob’];


for (i in people) {
document.write(people[i] +”<br/>”);
}
Demo
For for/in
Functions
● It is a set of instructions to perform a specific task.
● It can be classified into four categories.
○ No Parameter - No Return Value
○ With Parameter - No Return Value
○ No Parameter - With Return Value
○ With Parameter - With Return Value
● Syntax: function name(parameter1, parameter2, parameter3) {
_____________________
return result; }
Demo
Implementing functions
Types Of Variables or Scope Of Variables
● Local : Declared inside the function.
● Global : Declared outside the function.
Demo
For Variables
Events
● Windows
● Form
● Keyboard
● Mouse
Windows Events
Major windows events

● onload

Eg:

<element onload="script">

Note:

● It is mostly used on <body> tag.


● Introduction to navigator object.
Demo
For Windows Events
Forms Events
Major events used with form elements

● onfocus : textbox
● onblur : textbox
● onchange : textbox and dropdown list
● onsubmit : form

Note:

● Introduction to getElementById object.


● Introduction to test() method of Regular Expression
Demo
For Form Events
Keyboard Events
Major Keyboard events are

● onkeydown //textbox
● onkeyup //textbox
● onkeypress //textbox

Note:

● Count number of characters in the textarea, like in twitter.


Demo
For Keyboard Events
Mouse Events
Major mouse events

● onclick : button
● onmouseover : link
● onmouseout : link

Note:

● Introducing <marquee> tag


Demo
For Mouse Events
Creating Calculator
● Basic Operations
● Introducing eval function
Demo
For Calculator
Stand Alone Object/s
● Single Object
○ var obj={“RollNo”:1, “Name”:"Peter", “Marks”:75};
○ obj.RollNo
● List Of Object
○ var lstObj=[{“RollNo”:1, “Name”:"Peter", “Marks”:75},

{“RollNo”:2, “Name”:"John", “Marks”:25},

{“RollNo”:3, “Name”:"Bob", “Marks”:35}]

○ lstObj[0].RollNo
Demo
For Stand Alone Object\s
Why OOPs?
● No strong binding between data and functions.
Demo
For Why OOPs
OOPs Through JavaScript
● Object
● Class
● Properties
● Methods
Analogy
Student

● Objects ● rollNo
○ Jack Properties ● name
● marks
○ Peter
Class
○ John
● getDetails()
Methods
● getResult()
Object & Class
● Object
○ Any real time entity is called as an object.
○ Every object consist of state(look and feel) and behaviour(what is does).
○ States are called as properties and behaviors are called as methods.
● Classes
○ Class is a blueprint of an object.
○ It consist of fields which are not allowed to access from outside the class.
○ It also consist of methods which are allowed to access from outside the class.
Constructor
● Constructor is invoked automatically when we create an object.
● You cannot invoke constructor explicitly.
● It is used to initialize an object.
● Here in javascript, it is slightly different.
function Student(){

this.rollNo=123;

Defining A Class
this.name="ManzoorThetrainer";

this.marks=75;

● Javascript is prototype-oriented, this.getResult=function(){


classless, or instance-based if(this.marks>=35)
programming. return “Pass”;
● But we can simulate the class
else
concept using JavaScript functions.
return “fail”;

}
Demo
For Defining A Class
var obj=new Student();

alert(obj.rollNo + “ ” obj.name);

Object Creation alert(obj.getResult());

● Creating Object obj.rollNo=111;


● Accessing Properties obj.name=”Peter”;
● Accessing Method
obj.marks=23;

alert(obj.rollNo + “ ” obj.name);

alert(obj.getResult());
Demo
For Object Creation
function Student(r,n,m){

this.rollNo=r;

Constructor this.name=n;

this.marks=m;
● Creating Class …
● Creating Object …
● Accessing Properties
}
● Accessing Method
var obj=new Student(1,”Jack”,78);

alert(obj.rollNo + “ ” obj.name);

alert(obj.getResult());
Demo
For Constructor
function Student(r,n,m){

this.rollNo=r;

List Of Objects this.name=n;

this.marks=m;
● Creating List Of Object …
● Accessing Object’s Properties …
● Accessing Object’s Method
}

var lstObj=new Array(); / [];

lstObj.push(new Student(1,”Jack”,78));

lstObj.push(new Student(2,”Peter”,81));
Demo
For List Of Objects
Thanks
Learn ASP.Net Core
MVC From Scratch
Mohd Manzoor Ahmed [MCT]
manzoor_trainer manzoorthetrainer.com
Prerequisite
● C#.Net Core
● EF Core
● HTML & CSS
● MS SQL Server (Recommended)
● JavaScript (Recommended)
● HTML5 & Bootstrap (Recommended)
● JQuery (Recommended)
.NET Framework Vs .NET Core
.NET Framework 4.6
● It is our old framework enhanced that we have been using for more than a decade.
● It is not open source
● It can target only windows OS
● It has all the components like Windows Form Application, ASP.Net Web Forms,
ASP.Net MVC, ASP.Net Web API, ASP.Net SignalR, ASP.Net Web Pages, WPF,
WCF, etc.,
.NET Core X.X (1, 2, 3, …)
● It is a new framework similar to .net framework maintained by Microsoft and the
.NET community on GitHub.
● It is open source.
● It can target Windows, Linux & Mac OS.
● It does not have all the components, It just has ASP.Net Core and Universal
Windows App.
www.ManzoorTheTrainer.com

ASP.Net Core 2.1


● ASP.Net is a part of Microsoft.Net for developing web apps.
● ASP.Net Core 2.1 is the redesign of ASP.Net.
● It is open source.
● It can target Windows, Linux & Mac OS.
● No ASP.Net Web Forms :(
● It has 3 major modules
○ MVC
○ Razor Pages
○ Web APIs
What is ASP.Net Core MVC ?
● It is open source, OS independent and free framework for building modern,
cloud-based, Internet-connected applications.
● More secure as URLs are not directly mapped to physical files.
● Inbuilt support for HTML5,CSS3 and bootstrap responsive design.
● Lightweight UI as there is no overhead of ViewState which makes pages load fast.
● Simple integration of modern, client-side frameworks like Angular And React.
● A unified framework for building both web UI and web APIs.
www.ManzoorTheTrainer.com

ASP.Net Vs ASP.Net Core


www.ManzoorTheTrainer.com

First ASP.Net Core Empty App


www.ManzoorTheTrainer.com

Understanding The Main() Of Program.cs Method


● Understand directory structure
● CreateDefaultBuilder() : Use Kestrel(cross-platform web server), set the
ContentRootPath, etc.,
● UseStartup<Startup>() : ConfigureServices(), Configure()
● Build() : Makes the server ready.
● Run() : Starts Listing.

Know more about Kestrel server here :


https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnet
core-2.0&tabs=aspnetcore2x
www.ManzoorTheTrainer.com

Understanding The Startup Class


ConfigureServices() Vs Configure()
● CogifureServices() : Adding services to IServiceCollection container will make
them available for dependency injection.
● Cofigure() : It is a middleware i.e., pipeline to handle requests and responses.
Ordering is important in Configure method.
www.ManzoorTheTrainer.com

First ASP.Net Core Static


Website
● Design a static website
● Set a default startup page
● https://github.com/damianh/StaticFile
sMiddleware/blob/master/src/Microso
ft.Owin.StaticFiles/DefaultFilesOption
s.cs (for ref)
MVC
www.ManzoorTheTrainer.com

Controller & Action


● The Model-View-Controller (MVC) is
an architectural pattern which
separates an application's UI into
three main blocks i.e., Models, Views,
and Controllers.
● Any Controller is a class which is
inherited from a base Controller class.
● User request is handled by a
controller’s method called as Action
www.ManzoorTheTrainer.com

Configuring an ASP.Net MVC


Core App
1. Adding MVC Service
2. Configuring route
www.ManzoorTheTrainer.com

MVC - View
● Whatever we see on the web page is a
View.
● It is a presenting content file with
.cshtml extension.
● It is send to the user in response to a
request from controller.
Updating To
www.ManzoorTheTrainer.com

ASP.Net Core 2.1 MVC


https://www.microsoft.com/net/do
wnload/thank-you/dotnet-sdk-2.1.3
00-windows-x64-installer
www.ManzoorTheTrainer.com

AppSetting & Package Files


1. appsetting.json : configuration
information at application level like
connectionstrings, etc.,
2. package.json : Used to install all client
side libraries like jquery, etc.,
I. Add package.json file to your UI
project.
II. Add libraries as json code
III. Select the project and click on show
all files. You will find node_modules
folder and files in that folder.
IV. Drag the files from node_modules to
your required location.
Get Vs Post
www.ManzoorTheTrainer.com

● To access a web page we use HTTP or


to communicate between client
(browser) and server(web app on IIS).
● Famous HTTP methods are
○ GET, POST, PUT & DELETE
Binding A Form To An Action
● Get Method is used to request a
resource (web page) from server.
● In Get Method data is embedded in
request URL (If any).

● Post Method is used to send data of


form to the server.
● In Post Method data is embedded in
body of form.
www.ManzoorTheTrainer.com
Passing Data From
View To Controller (Action)
● Parameterized Method
○ Same for Get
○ Same for Post
● Context Object Method
○ For Get Method - Request.Query
○ For Post Method - Request.Form
Introduction To
www.ManzoorTheTrainer.com

Razor View Engine


● Razor is a new markup for mixing
HTML and C#.
● @ symbol is used to translate from
HTML to C#.
● Eg : <p>Date is @DateTime.Now.ToString()</p>
● Razor files generally have a .cshtml
file extension.
www.ManzoorTheTrainer.com
Redesigning A Form Using
Razor View Engine
www.ManzoorTheTrainer.com

State Management Or Passing Data - Weakly Typed


● View To Controller
○ Parameterized Method
○ Context Object Method
● Controller To View
○ ViewData (non-persistent)
○ ViewBag (non-persistent)
● Controller To Controller (Via View)
○ TempData (non-persistent)
● Every where
○ Session (Persistent)
○ Action to View - ViewBag
○ Action to View Of Another Action - TempData
ViewData Vs ViewBag www.ManzoorTheTrainer.com

● ViewData is a dictionary of objects which


stores the data as key-value pair.
● It is used to pass data from Controller to
view.
● Null values must be handled explicitly.
● We need to type cast ViewData to get it as
the required type explicitly.

● ViewBag is also stores the data as key-value


pair by using dynamic feature of c#.
● It is also used to pass data from Controller
to view.
● Null values get handled implicitly.
● Type casting in ViewBag happens
automatically.
www.ManzoorTheTrainer.com
Integrating EF Core in MVC Core
● Install - Nuget Packages
● Microsoft.EntityFrameworkCore.SqlServer
● Microsoft.EntityFrameworkCore.Tools
● Add Student entity in Models Folder
● Add SchoolDbContext in Data Folder
● Add-Migration
● Update-DataBase
● Ready to go with data access in MVC
State Management Or Passing
www.ManzoorTheTrainer.com

Data - Strongly Typed


● Every where
○ Model (Domain)
○ ViewModel
www.ManzoorTheTrainer.com
Adding A New Student
● Add an Create() action to get the form
● Add another Create() action to post
the form
● Use @HTMLControlFor() to work
with model bindings.
● Using ActionLink() for links to call
action
● Use RedirectToAction() to move from
one action to another action.
● Finally we will see using TempData to
pass a message from from one action
to another action
Redesigning Form www.ManzoorTheTrainer.com

With Tag Helper


● Tag Helpers participate in creating
and rendering HTML elements in
Razor files which provides an
HTML-friendly development
experience.
● Add the below reference at the top of
cshtml file @addTagHelper *,
Microsoft.AspNetCore.Mvc.TagHelpe
rs
www.ManzoorTheTrainer.com

Tag Helper Server Side Form Validations


Ajax Actionlink
www.ManzoorTheTrainer.com

● AJAX stands for Asynchronous


JavaScript and XML.
● AJAX is used for creating faster
and more interactive web
applications by making partial page
postbacks.
www.ManzoorTheTrainer.com

Tag Helper Client Side Form Validations


Custom Validators - 3 Steps
www.ManzoorTheTrainer.com

1. Create a class for custom validator say


UniqueEmailAttribute which inherits
ValidationAttribute.
2. Override the method IsValid() with
validation logic which takes input as
value and returns ValidationResult
3. Then apply [UniqueEmail] attribute
on email field where ever is required.
CRUD - Select www.ManzoorTheTrainer.com
CRUD - Delete www.ManzoorTheTrainer.com
CRUD - Create www.ManzoorTheTrainer.com
CRUD - Update www.ManzoorTheTrainer.com
Bootstrap 4
www.ManzoorTheTrainer.com

● In simple words Bootstrap is


combination of predefined design
classes in CSS and JavaScript file for
developing responsive, mobile-first
websites.
● Bootstrap 4 is completely free.
● https://bootswatch.com/simplex/
● Download bootstrap.min.css
● Replace old css in lib with latest css
Layouts In MVC (Master Pages)
www.ManzoorTheTrainer.com

● A Layout view contains common UI


parts, so that we need not to write the
same code in every page.
(_Layout.cshtml)
● ViewStart is a special view which
contains the Layout page that has to
be included in every View.
(__ViewStart.cshtml)
● ViewImports contains namespaces
which can be used by all other views.
(_ViewImports.cshtml)
● Error is a common error page for any
unhandled exceptions (Error.cshtml)
Dependency Injection
www.ManzoorTheTrainer.com

● .NET garbage collector performs


memory cleanup for C# objects.
● But, it does not release memory for
unmanaged resources.
● Unmanaged resources like Files,
DbConnections, DataReaders,
Printers, etc.,
● We need to implement or call a
Dispose method to release
unmanaged resources.
● Solution to this overhead of calling
Dispose method is DI.
ASP.Net Identity - Authentication
www.ManzoorTheTrainer.com

● Checking the genuinity of a user or client is called as authentication.


● It is normally achieved with the help of username and password called as forms
authentication for web apps.
● In our early days .Net Framework we used Membership classes or providers to
achieve authentication.
● The ASP.NET Identity system is a replacement of Membership systems which is
specially designed to support social logins for building modern applications for
the web, phone, or tablet.
● In Microsoft.AspNetCore.Identity we have mainly two classes using which we
implement authentication and authorization i.e., UserManager and
SignInManager
Initial Setup - 4 Steps
www.ManzoorTheTrainer.com

1. Add the nuget package


Microsoft.AspNetCore.Identity.EntityFrame
workCore
2. Inherit application’s DbContext say
SchoolDbContext from IdentityDbContext.
3. Inject application’s DbContext object and
Identity object using service collection
object in ConfigureServices Method of
StartUp Class.
4. Add authentication configuration in HTTP
pipeline using app object in Configure
method of StartUp classes
User Registration - 4 Steps
www.ManzoorTheTrainer.com

1. Create RegistrationViewModel
2. Create UserManager And
SignInManager objects.
3. Create an action to render user
registration form.
4. Create another action to handle
registration request.
Login And Logout - 7 Steps
www.ManzoorTheTrainer.com

1. Create LoginViewModel
2. Create UserManager And
SignInManager objects.
3. Create an action to render login form.
4. Create another action to handle login
request.
5. Apply [Authorize] attribute on
Controllers to secure it.
6. Finally we will also show and hide links
based on login and logout.
7. Applying [Authorize] at application
level and use [AllowAnonymous]
Email Confirmation - 6 Steps
www.ManzoorTheTrainer.com

1. Create Email Service


2. Create confirmation token
3. Create confirmation link with userId and token
4. Send email with confirmation link
5. Find user by userId in Confirm email
6. Finally confirm email using token received
Forgot Password - 7 Steps
www.ManzoorTheTrainer.com

1. Create ForgotPasswordViewModel.
2. Create action to render forgot
password form.
3. Create an action to handle forgot
password.
4. Find user by Email.
5. Create password reset token.
6. Create password reset link with userId
and token
7. Send email with password reset link
Password Reset - 5 Steps
www.ManzoorTheTrainer.com

1. Create ResetPasswordViewModel.
2. Create action to render reset
password form using UserId and
token.
3. Create an action to handle reset
password.
4. Find user by UserId.
5. Finally reset the password using user,
token and new password
Authorization - 5 Steps
www.ManzoorTheTrainer.com

1. Create Roles in Db Say ‘Admin’ and


‘User’.
2. Assign Role to a user from Db.
3. Add role to authorize attribute
[Authorize(Roles = "Admin")]
4. Finally we will also show and hide
links based on authorization.
5. At last we will see how to assign
default role as ‘User’ at the time of
registration.
Assigning Roles Dynamically
www.ManzoorTheTrainer.com
www.ManzoorTheTrainer.com
Partial Views
www.ManzoorTheTrainer.com

● A partial view is a .cshtml file that


renders HTML output within
another View.
● It is used to create a common
markup content across multiple
markup files.
AjaxForms
www.ManzoorTheTrainer.com

● A partial view is a .cshtml file that


renders HTML output within
another View.
● It is used to create a common
markup content across multiple
markup files.
jQuery Based Ajax Call
www.ManzoorTheTrainer.com

Read Operation
jQuery Based Ajax Call
www.ManzoorTheTrainer.com

Delete Operation
jQuery Based Ajax Call
www.ManzoorTheTrainer.com

Update Operation
jQuery Based Ajax Call
www.ManzoorTheTrainer.com

Create Operation
www.ManzoorTheTrainer.com

Thanks

Вам также может понравиться