Sie sind auf Seite 1von 35

Web Application Development

Lecture 01
Agenda
• What is .Net
• Why .Net
• Development Environment
• Example Program
• Course Contents
• Assessment Criteria
What is .Net
• .NET is a platform for developing, deploying, and
maintaining desktop, enterprise, Internet and Smart
devices applications.
Why .Net
• A developer can enjoy or take advantage various .Net
features such as:
– Multiple Languages based Development

– Cool Development environment, Visual Studio .NET

– Support for front-end technologies: HTML, XML, Java script,


Jquery, CSS, AJAX etc.

– A huge and powerful class library with over 2000 classes (data
structure, data connection, threading, code security etc.)
Development Environment
• Visual Studio: For Web Development Environment
– Supports

MVC REST

Single Page
API
Languages Support
• Visual Studio IDE is developed with support for
Example
• Example C# program
Week Content Assessment
 Introduction to MVC Framework
 understanding Model, View and Controller
 Creating new Project and adding controller class
 Writing first hello world function in controller class
1 Quiz 01
 Control Structures
 Conditional Statements
 Functions with parameters
 Exception handling
 C# classes and coding convention
 Collection classes
 Basic LINQ queries
Quiz 02,
2  Regular Expressions
Assignment 01
 Enumeration
 Anonymous types
 for loop and for each loop in View file
 Basic HTML (Tags, hyper reference, anchor, images)
3 Assignment 02
 Page layout using CSS (classes, ID, CSS rules)
 Setting different layouts in CSS
4 Assignment 02
 Shared View/Master Page
 Bootstrap CSS with Shared View/ Master Page
5  View Bag, view data and view data dictionary Assignment 02
 The razor view engine
 creating classes and database using code first approach
6 Assignment 03
 creating classes and database using data first approach
 Generating controller and views
7 Assignment 03
 Model binding (default & Explicit)
 HTML Helper
8  Metadata attributes on class members Quiz 03
 Advance LINQ queries
9  Data Annotation and Validation Assignment 04
10  Membership, authorization and security Assignment 04
Quiz 04,
11  AJAX
Assignment 05
Quiz 05
12  Routing
Project
13&14.  ASP.Net Web API Project
15&16.  Single Page Application with AngularJS Project
Assessment
Exam Type Percentage (%)
Quiz 10
Assignments 20
Project-Presentation 10
Mid Term 20
Final Term 40
Introduction to C#
• C# is an stylish and type-safe object-oriented language
that enables developers to build a variety of secure and
robust applications that run on the .NET Framework.

• C# syntax is highly expressive, yet it is also simple and


easy to learn. It is easy to understand for a developer
who is already familiar with C, C++ or java.
Making First Project in C#
• Choose File from menubar
Making First Project in C#
• Select New-> Project
Making First Project in C#
• Choose Console App (.Net Framework)
• Assign name to your project and press ok
Introduction to C#

Like java Packages Preprocessing directives

All code is encapsulated in class


Variables’ Type in C#
• Variables’ Type
– Value Type
Type Represents
bool Boolean value
byte 8-bit unsigned integer
char 16-bit Unicode character
decimal 128-bit precise decimal values with 28-29 significant digits
double 64-bit double-precision floating point type
float 32-bit single-precision floating point type
int 32-bit signed integer type
long 64-bit signed integer type
sbyte 8-bit signed integer type
short 16-bit signed integer type
uint 32-bit unsigned integer type
ulong 64-bit unsigned integer type
ushort 16-bit unsigned integer type
Variables’ Type in C#
– Reference Type
• Do not actually store the data
• They contain reference to variable
• E.g.
Person p1=new Person(“Lional”,39,”Itly”);
Person p2=p1;
p2.name=“asad”;
console.write(p1.name); //it will print “asad”

p1 Person
refers name:Lional
age:39
country:Itly
refers
p2
Variables’ Type in C#
• Other distinct object types
– Three kind of built-in types
– object, dynamic, String
– object
• base class for all data types in C#
• can be assigned values of any other types
• But we need type casting to get value back
• Example
object obj;
obj = 100;
• Assigning any other type to object is called boxing.
• Assigning value back from object type is called unboxing.
– int value=(int)obj;
Variables’ Type in C#
• Other distinct object types (cont.…)
– Dynamic
• You can store any type of value in the dynamic data type variable.
Type checking for these types of variables takes place at run-time.
dynamic var = "hello";
var = 5;
Console.WriteLine(var); //prints 5
– String
• allows you to assign any string values to a variable
• string type is an alias for the System.String class
• String str=“Welcome to .Net”;
Defining Class in C#
• Naming Convention
– PascalCase for class name and methods
• string FirstName
• double TotalAmount
• double GetTotalCount()
– camelCase for arguments and local variables
• double GetTotalCount(string employeeID);
• void Swap(double firstVariable, double secondVariable)
{ //camel case is used for class
members: ‘first variable’, and
int thirdVariable=firstVariable; ‘secondVariable’
firstVariable=secondVariable;
//camel case is used for local
secondVariable=thirdVariable; variable ‘third variable’
}
Switch statement in C#
namespace CSharpPractice { case 'F':
class Demo { Console.WriteLine("Failed");
static void Main(string[] args) { break;
/* local variable definition */ default:
char grade = 'B'; Console.WriteLine("Invalid grade");
switch (grade) { break;
case 'A': }
Console.WriteLine("Excellent!"); Console.WriteLine("Your grade is “+ grade);
break; } //end switch
case 'B': } //end main
case 'C': } //end class
Console.WriteLine("Well done");
break;
case 'D':
Console.WriteLine("Promoted");
break;
Function Call Statement
• You can call a local function or class member
function from main body of C# program.
• For example
class Demo {
public static void Main(string[] args)
{
Demo d = new Demo();
d.mathematics()
}
public void mathematics(){

}
}//end main
} // end class
Function Call Statement
• Write a C# program that takes two variables (of
type double) and operator (char) from user as
input.
– The program calls mathematics(var1, operator, var2)
and perform arithmetic operation based on provided
operator.
– Program shall use switch statement on operator and
print accurate output on console screen.
Function Call Statement
class Demo {
public static void Main(string[] args)
{
Demo d = new Demo();

double firstVariable;

firstVariable= Console.ReadLine();

char operators = '/';

double secondVariable;

secondVariable = Console.ReadLine();

d.mathematics(firstVariable, operators, secondVariable);

Console.ReadKey();
} //end main
}
Function Call Statement
static void mathematics (double firstVariable, char operators, double secondVariable) {
switch (operators) {
case '*':
Console.WriteLine(firstVariable * secondVariable);
break;
case '+':
Console.WriteLine(firstVariable + secondVariable);
break;
case '-':
Console.WriteLine(firstVariable - secondVariable);
break;
case '/’:
Console.WriteLine(firstVariable / secondVariable);
break;
default:
break;
} //end switch
}// end function
Exception Handling
class ExceptionDemo {
static void Main(string[] args)
{
try {
//your code comes here
}
catch (Exception e) {
Console.WriteLine(e.ToString());
}
finally {
Console.WriteLine(“This statement executes after try or catch block");
}
Console.ReadKey();
} //end main
} // end class
Exception Handling
• Write a C# program that takes two variables (of
type double) from user as input.
– The program divides first variable by second variable
and prints result
– If second variable is zero (0) then it shall throw an
exception printing that “divide by zero exception” +
exception message.
Exception Handling
class ExceptionDemo {
static void Main(string[] args)
{
try {
double firstVariable;
firstVariable= Console.ReadLine();
char operators = '/';
double secondVariable;
secondVariable = Console.ReadLine();
Console.WriteLine(firstVariable / secondVariable);
}
catch (Exception e) {
Console.WriteLine(“divide by zero exception”+e.ToString());
}
finally {
Console.WriteLine("terminating calculator program");
}
Console.ReadKey();
} //end main
} // end class
Exception handling
• Repeat your previous program and use throw
statement when operator is ‘/’ and second
variable is zero (0)
Function Call Statement
class ExceptionDemo {
static void Main(string[] args)
{
try {
double firstVariable;
firstVariable= Console.ReadLine();
char operators = '/';
double secondVariable;
secondVariable = Console.ReadLine();
mathematics(firstVariable, operator, secondVariable);
}
catch (Exception e) {
Console.WriteLine(“divide by zero exception”+e.ToString());
}
finally {
Console.WriteLine("terminating calculator program");
}
Console.ReadKey();
} //end main
} // end class
Function Call Statement
static void mathematics (double firstVariable, char operators, double secondVariable) {
switch (operators) {
case '*':
Console.WriteLine(firstVariable * secondVariable);
break;
case '+':
Console.WriteLine(firstVariable + secondVariable);
break;
case '-':
Console.WriteLine(firstVariable - secondVariable);
break;
case '/':
if (secondVariable == 0)
throw new Exception();
else
Console.WriteLine(firstVariable / secondVariable);
break;
} //end switch
}// end function
Break and Continue…
• Break • Continue
for( int i=0;i<10;i++) { for( int i=0;i<10;i++){
if(i>2&&i<8){ if(i>2&&i<8){
break; continue;
} }
else{ else{
Console.WriteLine(i); Console.WriteLine(i);
} }
} //Breaks for loop when executed } //Passes control back to for loop
Prints
0
Prints 1
0 2
1 8
2 9
foreach Loop
static void Main()
{
string[] vehicle= { “Car", “Jeep", “cycle" };
foreach (string value in vehicle)
{
Console.WriteLine(value);
}
}
Defining Class in C#
namespace CSharpPractice{ namespace CSharpPractice
class Person { {
private string FirstName; //Pascal Case
class Demo
private string LastName;
{
private string profession;
double Age; static void Main(string[] args)
///////////SETTERS////////////// {
public void SetFirstName(string Person person = new Person();
firstName) { //camel case for local variable ‘person’
FirstName = firstName;
person.SetFirstName("aziz");
}
Console.WriteLine(person.GetFirstName
//…………Write other setters…………….
());
///////////GETTERS//////////////
string GetFirstName() //Pascal Case
Console.ReadKey();
{ }
return FirstName; }
} }
}
}
Inheritance in C#
class Employee : Person namespace CSharpPractice
{ {
class Demo {
private string EmployeeID;
static void Main(string[] args)
////////////SETTERS//////////////
{
public void setEmployeeID(string Employee employee = new Employee();
employeeID) { employee.SetFirstName("aziz");
this.EmployeeID = employeeID; employee.setEmployeeID("43543");
} Console.WriteLine
////////////GETTERS////////////// (employee.GetFirstName());
Console.WriteLine
public string GetEmployeeID() {
(employee.GetEmployeeID () );
return this.EmployeeID; Console.ReadKey();
} }
} //end class }
}
Using properties and Camel
case in classes
class Person { public string Profession {
private string _firstName; get { return _profession; }
public string _lastName; set { _profession = value; }
private string _profession; }
double _age; } //end class
public string FirstName { public static void main(String[] args)
get { return _firstName; } {
set { _firstName = value; } Person person=new Person();
} person.FirstName=“usama”;
public string LastName { person.LasrName=“azhar”;
get { return _lastName; } :
set { _lastName = value; } :
} }

Das könnte Ihnen auch gefallen