Tuesday 16 May 2017

Example of Simple Sign In Form In asp.net MVC 4 Using Linq

Dear Student ,

   Please , Follow the step to create your Sign In Form in Aps.net Mvc 4

Step 1 :

     Create a Database with " Customer "  following Types


Step 2: Create a Action Result method in your Controllar with Name "SignIn"  and Follow the following Step ....

Step 3 : Create your SignIn Form in View page with following Code Step by Step ;

@model Database_Connection.Models.Customers

@{
    ViewBag.Title = "SignIn";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>SignIn</h2>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Customers</legend>

        <div class="editor-label">
          Enter your Email Id
        </div>
        <div class="editor-field">
           <input type="email" name="email" required/>
        </div>

        <div class="editor-label">
          Enter your Mobile No 
        </div>
        <div class="editor-field">
          <input type="text" name="mobile" required/>
        </div>

        <p>
            <input type="submit" value="Sign In" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}


Let's See , your Output : 








Sunday 14 May 2017

Example of Retrieve the whole data from database using my sql in php

Dear Student ,

    Please , Follow the Step ....

1. Create a Table in mySql and insert the Data inside it.


2 . create File with dbconnect.php for connect our file to database

<?php$servername = "localhost";
$username = "root";
$password = "";
$DbName="Registration";
// Create connection
$conn = new mysqli($servername, $username, $password,$DbName);// Check connection
if ($conn->connect_error)
{  
  die("Connection failed: " . $conn->connect_error);
?>

 2. Create A file to ViewData.php for show our data from Database


 <?php

 include("dbconnect.php");

?>

</br>

</br>

</br>

<?php



$sql="SELECT Id,Name,userName,Email,Password,Sex,Mobile_No FROM registartionform";


if ($result=mysqli_query($conn,$sql))

  {

   echo "<center>

   <table border='1'>

   <tr>

   <th>ID</th>

   <th>Name</th>

   <th>User Name</th>

   <th>Email Id</th>

   <th>Password</th>

   <th>Sex</th>

   <th>Mobile No</th></tr>";

  // Fetch one and one row

    while ($row=mysqli_fetch_row($result))

    {

     echo "<tr><td>".$row[0]."</td>

<td>".$row[1]."</td>

<td>".$row[2]."</td>

<td>".$row[3]."</td>

<td>".$row[4]."</td>

<td>".$row[5]."</td>

<td>".$row[6]."<td>

<a href='edit.php'>Edit Record</a></td>"."<td>

<a href='delete.php'>Delete Record</a></td>"."</td></tr>";

    }

echo "</table></center>";

  // Free result set

  mysqli_free_result($result);

}


mysqli_close($conn);

?>

</br>

</br>

</br>

<a href="home.php">Back to Home Page</a>



3.Execute your ViewData from any web browser with following link...

localhost:80/Viewdata.php

Output :




Wednesday 10 May 2017

Example of Create , delete , Edit and View the data in Asp.net MVC Step by Step using Code First Approach

Dear Student ,

   If You want to create a Sign Up Form and Delete , Edit and View your all data in as a list format using Code First Approach. So Please Follow the Step by step Process...


Step 1 :

   Create your Model Class as per your requirements attributes but mention one things that Insert One primary key using [Key] keywords


Step 2 :


  Create one more class in Model For DbContext Class



Step 3:


Go to Controller Folder and Create a empty Controller


Step 4 :


 Create a Your own Action result For inserting the data ..

Step 5 :


 Go to Create action Method and right click add a view

@model Database_Connection.Models.Customers

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Customers</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.C_Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.C_Name)
            @Html.ValidationMessageFor(model => model.C_Name)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.C_Address)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.C_Address)
            @Html.ValidationMessageFor(model => model.C_Address)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.C_Mobile_No)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.C_Mobile_No)
            @Html.ValidationMessageFor(model => model.C_Mobile_No)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.C_Email_Id)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.C_Email_Id)
            @Html.ValidationMessageFor(model => model.C_Email_Id)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}


Step 6 :


Create one more action method for View you Data as list view 


Step 7 :


Create a view for Index Action Result for View the data

@model IEnumerable<Database_Connection.Models.Customers>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.C_Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.C_Address)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.C_Mobile_No)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.C_Email_Id)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.C_Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.C_Address)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.C_Mobile_No)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.C_Email_Id)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
            @Html.ActionLink("Details", "Details", new { id=item.Id }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.Id })
        </td>
    </tr>
}

</table>


Step 8 :


Create one more action method for delete the data from database 


Step 9 :


  Create a view for delete the data from data base 

@model Database_Connection.Models.Customers

@{
    ViewBag.Title = "Delete";
}

<h2>Delete</h2>

<h3>Are you sure you want to delete this?</h3>
<fieldset>
    <legend>Customers</legend>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.C_Name)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.C_Name)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.C_Address)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.C_Address)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.C_Mobile_No)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.C_Mobile_No)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.C_Email_Id)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.C_Email_Id)
    </div>
</fieldset>
@using (Html.BeginForm()) {
    <p>
        <input type="submit" value="Delete" /> |
        @Html.ActionLink("Back to List", "Index")
    </p>
}


Step 10:

Create one more Action method for Edit the information from Database 



Step 11 :


 Create a view form Editing the data from Database 


@model Database_Connection.Models.Customers

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Customers</legend>

        @Html.HiddenFor(model => model.Id)

        <div class="editor-label">
            @Html.LabelFor(model => model.C_Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.C_Name)
            @Html.ValidationMessageFor(model => model.C_Name)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.C_Address)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.C_Address)
            @Html.ValidationMessageFor(model => model.C_Address)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.C_Mobile_No)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.C_Mobile_No)
            @Html.ValidationMessageFor(model => model.C_Mobile_No)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.C_Email_Id)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.C_Email_Id)
            @Html.ValidationMessageFor(model => model.C_Email_Id)
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

Tuesday 9 May 2017

Example of Retrieve the Data from XML File in Asp.net MVC 4 using Controller and View

Dear Student ,
   
   Please , Follow the step for retrieve the data from XML File in Asp.net MVC 4 using Controller with view

Step 1 :

   Create the XML File with DataReport.xml

  <?xml version="1.0" encoding="utf-8"?>
<CusterDetails>
  <Customer>
    <name>Deepak Kumar Gupta</name>
    <product>Buiscuits</product>
    <quantity>12</quantity>
    <price>60</price>
  </Customer>
  <Customer>
    <name>Roshan Kumar Gupta</name>
    <product>Namkeen</product>
    <quantity>120</quantity>
    <price>6000</price>
  </Customer>
  </CusterDetails>


Step 2 :

 Create the Controller file With RetrieveDataFromXMLData.cs


 public ActionResult RetriveDataFromXml()
        {
            string result = "";
            XDocument xmlDoc = XDocument.Load("C:/Users/Deepak Kumar/documents/visual studio 2012/Projects/ramkola_bhagwat/ramkola_bhagwat/XMLData/DataReport.xml");
            var q = from c in xmlDoc.Descendants("Customer")
                    select (string)c.Element("name") + "-" + (string)c.Element("product") + "-" +
                        (string)c.Element("quantity") + "-" + (string)c.Element("price");
            foreach(string ar in q)
            {
                result = result + "|" + ar;
            }
            ViewBag.aaa = result;
            return View();
        }

Step 3 :

 Create ViewFile with RetriveDataFromXml.cshtml

@model ramkola_bhagwat.Models.niitEntities

@{
    ViewBag.Title = "RetriveDataFromXml";
}

<h2>RetriveDataFromXml</h2>
<p>@ViewBag.aaa</p>


Output : 


Example of retrieve the data from Arraylist in Controllar to view in asp.net MVC

Follow the Step :


1. Controller Code

        public ActionResult ArrayValue()
        {
            string names = "";
            string[] arr = new string[3] { "Deepak", "Roshan", "mahesh" };
           var quer = from string name in arr select name;
           foreach (var na in quer)
           {
               names = names + " " + na;
           }
           ViewBag.aa = names;
            return View();
        }

2. View Code

  @model ramkola_bhagwat.Models.niitEntities

@{
    ViewBag.Title = "ArrayValue";
}

<h2>ArrayValue</h2>

<p>@ViewBag.aa</p>



Output :



Monday 8 May 2017

Example of Simple login page in Php with MySql

HTML CODE 
...................................................

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Jotorres Login Form</title>
</head>
<body>
    <form method="post" action="validate_login.php" >
        <table border="1" >
            <tr>
                <td><label for="users_email">Email</label></td>
                <td><input type="text" name="users_email" id="users_email"></td>
            </tr>
            <tr>
                <td><label for="users_pass">Password</label></td>
                <td><input name="users_pass" type="password" id="users_pass"></input></td>
            </tr>
            <tr>
                <td><input type="submit" value="Submit"/>
                <td><input type="reset" value="Reset"/>
            </tr>
        </table>
    </form>
</body>
</html>

PHP CODE  

.........................................................................

<?php

// Grab User submitted information
$email = $_POST["users_email"];
$pass = $_POST["users_pass"];

// Connect to the database
$con = mysql_connect("localhost","root","");
// Make sure we connected successfully
if(! $con)
{
    die('Connection Failed'.mysql_error());
}

// Select the database to use
mysql_select_db("registration",$con);

$password = hash('sha256', $pass); // password hashing using SHA256

$res=mysql_query("SELECT userId, userName, userPass FROM users WHERE userEmail='$email'");
$row=mysql_fetch_array($res);
$count = mysql_num_rows($res); // if uname/pass correct it returns must be 1 row

if( $count == 1 && $row['userPass']==$password ) {
echo 'Successful';
} else {
echo "Incorrect Credentials, Try again...";

}?>

OUPUT :

                                       Successful