AppStart-->RouteConfig.cs
routes.MapRoute(
name: " ",
url: "{controller}/{action}/{id}",
defaults: new { controller = "AdminLogin", action = "AdminLogin_Fun", id = UrlParameter.Optional }
);
Views-->Shared-->_Layout.cshtml
<link rel="stylesheet" href="@Url.Content("~/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css")">
<script src="@Url.Content("~/plugins/jQuery/jQuery-2.1.4.min.js")"></script>
<ul class="sidebar-menu">
<li class="header" style="color: White;">Bill Validator</li>
<li class=" treeview">
<a href="@Url.Action("Dashbord", "Home")">
<i class="fa fa-dashboard"></i><span>DASHBORD</span>
</a>
</li>
<li class=" treeview">
<a href="@Url.Action("Upload_MObile_Bill_Fun","Upload_Mobile_Bill")">
<i class="fa fa-dashboard"></i><span>UPLOAD BILLS</span>
</a>
</li>
Views-->ViewsStart.cshtml
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
Views-->ViewsStart.cshtml-->AdminLogin-->AdminLogin_Fun.cshtml
@model Bill_Validator.Models.UserLoginModel
@{
Layout = null;
}
<link rel="stylesheet" href="@Url.Content("~/assets/bootstrap/css/bootstrap.min.css")">
<script src="@Url.Content("~/assets/js/jquery-1.11.1.min.js")"></script>
<div class="form-bottom">
@using (@Html.BeginForm("login_action", "AdminLogin"))
{
<div class="form-group">
<label class="sr-only" for="form-username">Username</label>
@Html.TextBoxFor(m => m.UserId, new { @class = "form-username form-control" })
</div>
<div class="form-group">
<label class="sr-only" for="form-password">Password</label>
@Html.PasswordFor(m => m.Password, new { @class = "form-username form-control" })
</div>
<button type="submit" class="btn">Sign in!</button>
}
</div>
Models-->UserLoginModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Bill_Validator.Models
{
public class UserLoginModel
{
public string UserId { get; set; }
public string Password { get; set; }
}
}
Controllers-->AdminLoginController.cs
using Bill_Validator.DataAccessLayer;//Data Access Layer NameSpace
using Bill_Validator.Models;// Models class Login.css
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Bill_Validator.Controllers
{
public class AdminLoginController : Controller
{
//
// GET: /AdminLogin/
public ActionResult AdminLogin_Fun()
{
return View();
}
[HttpPost]
public void login_action(UserLoginModel ur)
{
Login l = new Login();
bool value = l.CreateLogin(ur);
if (value.Equals(true))
{
Response.Redirect(Url.Action("Dashbord", "Home"));
}
else
{
Response.Redirect(Url.Action("AdminLogin_Fun", "AdminLogin"));
}
}
}
}
DataAccessLayer-->Login.cs
using Bill_Validator.Models;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Bill_Validator.DataAccessLayer
{
public class Login
{
MySqlConnection con = new MySqlConnection("SERVER=localhost;DATABASE=billvalidator;UID=root;PASSWORD=techsoft;");
public bool CreateLogin(UserLoginModel data)
{
String S = "SELECT * FROM login where username= '" + data.UserId + "' and password='" + data.Password + "'"; ;
MySqlCommand cmd = new MySqlCommand(S, con);
con.Open();
bool status = true;
MySqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
return status;
}
else
{
return status = false;
}
con.Close();
}
}
}