As most of you already know that ASP.NET 5 is now official named as .NET Core 1.0 and ASP.NET Core 1.0 for details you can read the Scott Hanselman blog. So I decided to take you on tour of ASP.NET core 1.0 and to discuss each feature of it, in more developer manner, which will be more on MVC 6 project structure.
vNext (ASP.NET 5) is Microsoft's new platform that is opensource and cross platform. which means you can change code according to your needs, distribute it and run on any platform as you like (Windows, MacOs or Linux). Microsoft has been working on this stuff for quite a long time and now it is very near of first release in this quarter of the year (Q1 2016). Currently vNext/ASP.NET 5 is in Release Candidate Update 1.
Its being long time after my last post, I hope you people missed me. I am writing this tutorial especially for my newbies programming students, who wants to know the basics of Web service as well as some tutorials to kick start with their Projects.
Before starting tutorial I would first like to take you on background tour of web service and the importance of the web service in today's world. As we all know, we are in an era in which everything is a part of cloud service and every thing is connected to each other, where laptops, tablets, PC, mobiles and all the portable devices are the main consumer of Cloud. When we talk about Cloud we mean some unknown place where your data stores and you consume it, and its available everywhere.
For making things more digestible I would like to give you an example of Facebook, we can access it from anywhere, and from any device. The first thing that pops in your mind will be "hey wait, isn't fb is a website?, not a cloud?" , and my answer will be "No its a Cloud". Why cloud? because it provides you service and not 100% users use it as a website, they have applications in their tablets, phones, some people use its chatting app from desktop. Facebook have built in Cloud service that provides service to website, mobiles, tablets, desktop app and so on.
Bored?, Lets Get Started with web service, there are certain things that you must know, web service can be created through any language, platform and there are certain types of services that we use know days 1) RESTful and 2) SOAP, there are more but I don't want to go to much deep.
In the last we have web service languages in which JSON (JavaScript Object Notation) and XML (eXtensible Markup Language) Commonly used for data transferring.
Just remember to go through my Jump Start tutorial for MVC this will help you understanding MVC Architecture and Web API works on MVC.
Now, start your Visual Studio and create yourself a New Project and named it something nice, I named it MvcApiWebApplication.
Before starting tutorial I would first like to take you on background tour of web service and the importance of the web service in today's world. As we all know, we are in an era in which everything is a part of cloud service and every thing is connected to each other, where laptops, tablets, PC, mobiles and all the portable devices are the main consumer of Cloud. When we talk about Cloud we mean some unknown place where your data stores and you consume it, and its available everywhere.
For making things more digestible I would like to give you an example of Facebook, we can access it from anywhere, and from any device. The first thing that pops in your mind will be "hey wait, isn't fb is a website?, not a cloud?" , and my answer will be "No its a Cloud". Why cloud? because it provides you service and not 100% users use it as a website, they have applications in their tablets, phones, some people use its chatting app from desktop. Facebook have built in Cloud service that provides service to website, mobiles, tablets, desktop app and so on.
Bored?, Lets Get Started with web service, there are certain things that you must know, web service can be created through any language, platform and there are certain types of services that we use know days 1) RESTful and 2) SOAP, there are more but I don't want to go to much deep.
In the last we have web service languages in which JSON (JavaScript Object Notation) and XML (eXtensible Markup Language) Commonly used for data transferring.
Just remember to go through my Jump Start tutorial for MVC this will help you understanding MVC Architecture and Web API works on MVC.
Now, start your Visual Studio and create yourself a New Project and named it something nice, I named it MvcApiWebApplication.
For beginners, CRUD Applications are the applications that uses 4 operations for manipulating data. Those 4 operations are Inserting data, Retrieving data, Editing data and Deleting data. You can also find these commands in Databases such as Select, Insert, Delete and Update.
To follow the drill, First Create a New MVC 4 internet Project, "CrudMvcApp". Now goto Models Folder in Solution Explorer, Right Click , goto add Class and name it "Restaurant.cs" and add the following Code.
Create another class file in Model with the name RestaurantContext.cs, yes this is the same file that we have created in our previous exercises, place the following code in it. You need to add namespace for DbContext "using System.Data.Entity;" above your class file. This is the same code that I have used in my previous blog related Code First and Data Annotation.
In order to avoid complexity i am using only one model for time being and without relation simple implimentation of Code First
Goto Controllers Folder in Solution Explorer, Right Click on the folder goto Add > Controller and name the Controller "RestaurantController.cs". From Scoffolding Option Select Template as "MVC Controller with empty read/write actions".
To follow the drill, First Create a New MVC 4 internet Project, "CrudMvcApp". Now goto Models Folder in Solution Explorer, Right Click , goto add Class and name it "Restaurant.cs" and add the following Code.
Create another class file in Model with the name RestaurantContext.cs, yes this is the same file that we have created in our previous exercises, place the following code in it. You need to add namespace for DbContext "using System.Data.Entity;" above your class file. This is the same code that I have used in my previous blog related Code First and Data Annotation.
In order to avoid complexity i am using only one model for time being and without relation simple implimentation of Code First
Goto Controllers Folder in Solution Explorer, Right Click on the folder goto Add > Controller and name the Controller "RestaurantController.cs". From Scoffolding Option Select Template as "MVC Controller with empty read/write actions".
This is 3rd post of my MVC series that discuss fundamental concepts of MVC with Jumpstart drill.
Model-View-Controller (MVC) is basically a software architecture pattern which comprises of 3 Tiers, each tier have different functionality. Controller is a main tier of MVC architecture that responsible for collecting request and responding to request. Model is a tier that responsible for validating data structure at database end as well as on the User Interface. While View is front end of MVC application in which data is presented to user.
Speaking of generally MVC does not have any version and can be implemented in any language. Since we are focussing on Microsoft technology therefore we will see different versions of MVC, which are versioned after updation of libraries.
Currently, in ASP.net MVC we have versions upto 4. We will be focussing on the latest that is i-e, MVC 4.
Some of the main Features that MVC 4 provides are:
1. Asp.net Web API.
2. New and Modernized default project template.
3. Supports for mobile application.
4. Mobile default project template.
5. Enhanced support for asynchronous projects and many more.
You can find detail list by following this link
Now we can go to real staff, creating our own First MVC 4 application.
Open you Visual Studio 2012 and Go to File > New Project
In New Project window select Web from left hand side menu under Template and Select MVC 4 Web Application from the list and name the project "MyFirstMVC4WebApp".
After pressing OK a new window will appear select a template as a Internet Application and make sure view engine is selected as a Razor.
Model-View-Controller (MVC) is basically a software architecture pattern which comprises of 3 Tiers, each tier have different functionality. Controller is a main tier of MVC architecture that responsible for collecting request and responding to request. Model is a tier that responsible for validating data structure at database end as well as on the User Interface. While View is front end of MVC application in which data is presented to user.
Speaking of generally MVC does not have any version and can be implemented in any language. Since we are focussing on Microsoft technology therefore we will see different versions of MVC, which are versioned after updation of libraries.
Currently, in ASP.net MVC we have versions upto 4. We will be focussing on the latest that is i-e, MVC 4.
Some of the main Features that MVC 4 provides are:
1. Asp.net Web API.
2. New and Modernized default project template.
3. Supports for mobile application.
4. Mobile default project template.
5. Enhanced support for asynchronous projects and many more.
You can find detail list by following this link
Now we can go to real staff, creating our own First MVC 4 application.
Open you Visual Studio 2012 and Go to File > New Project
In New Project window select Web from left hand side menu under Template and Select MVC 4 Web Application from the list and name the project "MyFirstMVC4WebApp".
After pressing OK a new window will appear select a template as a Internet Application and make sure view engine is selected as a Razor.
This post is a second part of the MVC 4 series that discusses implementation of Data Annotation. Before proceeding to the drill, I would first like explain, what Data Annotation is and used for. Data annotation is a set of classes that used with data models to define data in form of attributes.
Data annotation attributes can be categories into 3 types.
1) Validation Attributes
2) Display Attributes
3) Modelling Attributes
some of the validation attributes are:-
Data annotation attributes can be categories into 3 types.
1) Validation Attributes
2) Display Attributes
3) Modelling Attributes
Validation Attributes
Validation attributes are the attributes that are use for validating data, these controls are similar to validation controls in asp.net webforms but over here it is taken as attributes rather control.some of the validation attributes are:-
- CustomValidationAttribute - it uses a custom method for validation
- DataTypeAttribute - Use for data type validation, such as Email or Phone Number.
- EnumDataTypeAttribute - Validate data whether it exist in given Enum or not.
- RangeAttribute - Use for validating the range, minimum and maximum value that can be use.
- RegularExpressionAttribute - Use for validating data with the help of given Regular Expression.
- RequiredAttribute - Use where the value must be provided.
- StringLengthAttribute - Use for providing limit to string characters.
- ValidationAttribute - Use has a base class for validation attributes.
Display Attributes
Display Attributes defines how data is being displayed from Data Model.
Some of the Display attributes are:-
- DataTypeAttribute - Specifies a perticular type of data such as email or phone number.
- DisplayAttribute - Specifies a string for data type and members used that are used in user interface.
- DisplayFormatAttribute - Specifies how data field is displayed or formatted.
Data Modelling Attributes
Data Modelling Attribute is used for specifying data members and the relation in between them.
Few of the main attribute of this category are:-
- KeyAttribute - use for defining unique key one or more time.
- TimestampAttribute - Use for defining a timestamp for data versioning.
These are the main attributes that we can find in System.ComponentModel.DataAnnotations Namespace, however there is also another namespace within System.ComponentModel.DataAnnotations for Schema definition i-e, System.ComponentModel.DataAnnotations.Schema .
I will only highlight few of the schema's attributes that are related to my example which you will see in drill.
Those are
- TableAttribute - Use for mapping class with Database table
- ColumnAttribute - Use for representation of the Column in Database Table.
For the implementation I have used my previous project of Restaurant Management System
Open each of the model file from your previous project add following attributes as shown below
Always remeber that these Attributes while implimenting doesnot need full name for example RequiredAttribute will be written like [Required] without keyword Attribute.
Rest of the Code remains same.
After Running a project you will get following changes in your database that can be viewed from SQL Object Explorer
Rest of the Code remains same.
After Running a project you will get following changes in your database that can be viewed from SQL Object Explorer
Please free to comment any queries or complexities in blog.
This is my first article of MVC 4 Development series, which is based on basic guidance of implementation of the code first approach, initially this project is build on Console Application to avoid complexities for the starters.
Before starting the drill, I would first like to tell you that all of my example will base on Restaurant Management System and i will try to keep this example consistent through out this series.
Following is an ERD of the system, I hope the naming conventions are self explanatory to all the viewers.
Create a new console application project in your visual studio, by going to File > New Project in menu bar or Ctrl + Shift + N
Before starting the drill, I would first like to tell you that all of my example will base on Restaurant Management System and i will try to keep this example consistent through out this series.
Following is an ERD of the system, I hope the naming conventions are self explanatory to all the viewers.
Create a new console application project in your visual studio, by going to File > New Project in menu bar or Ctrl + Shift + N