Saturday, 16 December 2017

Data Annotations In Code First Model First and Data Base First

Data Annotation : Entity framework facilitate Data Annotation For validate Data before inserting in database client side and server side both.

for use of Data Annotation Two name space Require 

(1) System.ComponentModel.DataAnnotions 

This class hold these attributes

  1. Key
  2. Required
  3. String Length
  4. MinLength
  5. MaxLength
  6. TimeStamp
  7. ConcurrencyCheck
2) System.ComponentModel.DataAnnotation.Schema

This class hold these attributes

  1. Table
  2. Index
  3. ForeignKey
  4. NotMapped
  5. InversProperty 
  6. Column 





Thursday, 13 October 2016

MVC Complete Project With Code

Creating Cascading DropDownList In MVC 5 Using Entity Framework 6.0 Database First Step By Step 


step 1:

Create database first 
 Create database cascadingcountrystatecity;
USE [cascadingcountrystatecity]
GO
/****** Object:  Table [dbo].[C_State]    Script Date: 10/13/16 3:27:34 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[C_State](
[StId] [int] IDENTITY(1,1) NOT NULL,
[ConId] [int] NULL,
[StName] [nvarchar](100) NULL,
[DateTimeStamp] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED 
(
[StId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
[StName] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[City]    Script Date: 10/13/16 3:27:34 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[City](
[CityId] [int] IDENTITY(1,1) NOT NULL,
[Stid] [int] NULL,
[CityName] [nvarchar](100) NULL,
[DateTimeStamp] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED 
(
[CityId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
[CityName] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[country]    Script Date: 10/13/16 3:27:34 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[country](
[ConId] [int] IDENTITY(1,1) NOT NULL,
[ConName] [nvarchar](100) NULL,
[DateTimeStamp] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED 
(
[ConId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
[ConName] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[employee]    Script Date: 10/13/16 3:27:34 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[employee](
[Empid] [int] IDENTITY(1,1) NOT NULL,
[EmpName] [nvarchar](100) NULL,
[ConId] [int] NULL,
[StId] [int] NULL,
[CityId] [int] NULL,
PRIMARY KEY CLUSTERED 
(
[Empid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[C_State] ADD  DEFAULT (getdate()) FOR [DateTimeStamp]
GO
ALTER TABLE [dbo].[City] ADD  DEFAULT (getdate()) FOR [DateTimeStamp]
GO
ALTER TABLE [dbo].[country] ADD  DEFAULT (getdate()) FOR [DateTimeStamp]
GO
ALTER TABLE [dbo].[C_State]  WITH CHECK ADD FOREIGN KEY([ConId])
REFERENCES [dbo].[country] ([ConId])
GO
ALTER TABLE [dbo].[City]  WITH CHECK ADD FOREIGN KEY([Stid])
REFERENCES [dbo].[C_State] ([StId])
GO
ALTER TABLE [dbo].[employee]  WITH CHECK ADD FOREIGN KEY([CityId])
REFERENCES [dbo].[City] ([CityId])
GO
ALTER TABLE [dbo].[employee]  WITH CHECK ADD FOREIGN KEY([ConId])
REFERENCES [dbo].[country] ([ConId])
GO
ALTER TABLE [dbo].[employee]  WITH CHECK ADD FOREIGN KEY([StId])
REFERENCES [dbo].[C_State] ([StId])
GO
USE [master]
GO
ALTER DATABASE [cascadingcountrystatecity] SET  READ_WRITE 
GO



1: Select and copy Above Script 
2: Open sql server management studio 
3: open query window 
4: paste and execute above query :


Step 2:

1: Open visual studio 2013 and above 
2: Create web application with mvc 
3: Right click on models folder 

coming soon    

  










Friday, 15 April 2016

Validation and Data Annotations In MVC 5


Validation and  Data Annotations  In MVC 5

Validation is way to check data or information is authentic or not. Here we are discuses How to validate data or information from client Side Step By step
step 1:
use namespace 
System.ComponentModel.DataAnnotations;
step2:
Create Model class
Let Us consider Create Model Class employee
and some property define as 

public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string EmailConfirm { get; set; }
public int Age { get; set; }
public decimal Price { get; set; }


step3

We are Disused Required

 [Required]
public string FirstName { get; set; }

[Required]

public string LastName { get; set; }

[Required]

[StringLength(160)]
public string FirstName { get; set; }


[Required]

[StringLength(160)]
public string LastName { get; set; }

[Required]
[StringLength(160, MinimumLength=3)]
public string FirstName { get; set; }


Step 4:

RegularExpression

Some properties of Order require more than a simple presence or length check. For example, 
you want to ensure the Email property of an  Order contains a valid, working e-mail address. 
Unfortunately, ensuring an e-mail address is working without sending a mail message and waiting 
for a response is practically impossible. What you can do instead is ensure the value  looks  like  a 
working e-mail address using a regular expression:


[RegularExpression(@"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}")]
public string Email { get; set; }


Range
The  Range attribute specify  minimum and maximum constraints for a numerical value. If the 
 field  only wanted to serve middle-aged customers, you could add an Age  property to the 
Order class and use the  Range attribute as in the following code:


[Range(35,44)]
public int Age { get; set; }

The values are inclusive. The Range attribute can work with integers and doubles, and 
another overloaded version of the constructor takes a  Type parameter and two strings (which can 
allow you to add a range to date and decimal properties, for example).

[Range(typeof(decimal), "0.00", "49.99")]
public decimal Price { get; set; }


Compare:

Compare ensures two properties on a model object have the same value. For example, you might 
want to force customers to enter their e-mail address twice to ensure they didn’t make a typographi-
cal error:

[RegularExpression(@"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}")]
public string Email { get; set; }

[Compare("Email")]
public string EmailConfirm { get; set; }

[Required]
[DataType(DataType.Password)]
[Display(Name="Password")]
public string Password { get; set; }


Remote

The ASP.NET MVC framework adds an additional Remote validation attribute. This attribute is in the  System.Web.Mvc namespace.
The  Remote attribute enables you to perform client-side validation with a server callback. Take, for example, the  UserName  property of the RegisterModel  class in the MVC Music Store. No two user should have the same  UserName  value, but validating the value on the client to ensure the value is unique is difi cult (to do so you would have to send every single username from the database to the client). With the Remote attribute you can send the  UserName  value to the server, and compare the value against the values in the

database.[Remote("CheckUserName","Account")]
public string UserName { get; set; }


Monday, 11 April 2016

ASP.NET MVC Attribute Routing

ASP.NET MVC Attribute Routing:

Attribute Routing is a new option for specifying routes by placing annotations on your controller classes or action methods.

ASP.NET Identity

ASP.NET Identity:

The membership and authentication systems in MVC 5 have been completely rewritten as part of the new ASP.NET Identity system. This new system moves beyond some outdated constraints of the previous ASP.NET Membership system, while adding some sophistication and configuration to the Simple Membership system that shipped with MVC 4.

Here are some of the top new features in ASP.NET Identity: 

➤ One ASP.NET Identity system: In support of the One ASP.NET focus we discussed earlier, the new ASP.NET Identity was designed to work across the ASP.NET family (MVC, Web Forms, Web Pages, Web API, Signal R, and hybrid applications using any combination).
➤ Control over user profile data:

Although it’s a frequently used application for storing additional, custom information about your users, the ASP.NET Membership system made doing it very difficult. ASP.NET Identity makes storing additional user information (for example, account numbers, social media information, and contact address) as easily as adding properties to the model class that represents the user.
➤ Control over persistence:

By default, all user information is stored using Entity Framework Code First. This gives you both the simplicity and control you’re used to with Entity Framework Code First. However, you can plug in any other persistence mechanism you want, including other ORMs, databases, your own custom web services, and so on.
➤ Testability:

The ASP.NET Identity API was designed using interfaces. These allow you to write unit tests for your user-related application code.
➤ Claims Based:

Although ASP.NET Identity continues to offer support for user roles, it also supports claims-based authentication. Claims are a lot more expressive than roles, so this gives you a lot more power and flexibility. Whereas role membership is a simple Boolean value (a user either is or isn’t in the Administrator role), a user claim can carry rich information, such as a user’s membership level or identity specifics.
➤ Login providers:

 Rather than just focusing on username / password authentication, ASP.NET Identity understands that users often are authenticated through social providers (for example, Microsoft Account, Facebook, or Twitter) and Windows Azure Active Directory.

➤ NuGet distribution:

ASP.NET Identity is installed in your applications as a NuGet package. This means you can install it separately, as well as upgrade to newer releases with the simplicity of updating a single NuGet package.