Controller
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
namespace NoOneWaiter.Controllers.Account
{
public class AdminController : Controller
{
dbConnection db = new dbConnection();
// GET: Admin
public ActionResult AdminList()
{
return View();
}
#region Login Using TB_AdminMaster
public ActionResult Login()
{
Session.Clear();
return View();
}
[HttpPost]
public ActionResult Login(TB_AdminMaster tb_AdminMaster)
{
if (tb_AdminMaster != null)
{
TB_AdminMaster user = db.TB_AdminMaster.Where(x => x.MOBILE_NO == tb_AdminMaster.MOBILE_NO && x.PASSWORD == tb_AdminMaster.PASSWORD && x.STATUS == "Active").FirstOrDefault();
if (user != null)
{
Session["ADMIN_ID"] = user.ADMIN_ID;
Session["ADMIN_NAME"] = user.ADMIN_NAME;
return RedirectToAction("Dashboard", "Dashboard");
}
else
{
ViewBag.Message = "Please enter valid user name and password.";
}
}
return View();
}
public JsonResult AccessList()
{
Int64 id = Convert.ToInt64(Session["ADMIN_ID"]);
var list = db.TB_Roles.Where(x => x.ADMIN_ID == id).Select(y => new { y.TB_Module.MODULE_NAME }).ToList();
Session["Permission"] = list;
return Json(list, JsonRequestBehavior.AllowGet);
}
public ActionResult ForgotPassword()
{
return View();
}
[HttpPost]
public ActionResult ForgotPassword(string MobileNumber)
{
if (MobileNumber != null)
{
TB_AdminMaster user = db.TB_AdminMaster.Where(x => x.MOBILE_NO == MobileNumber && x.STATUS == "Active").FirstOrDefault();
if (user != null)
{
FormsAuthentication.SetAuthCookie(user.ADMIN_NAME, true);
send("Use '" + user.PASSWORD + "' as a NumberOneWaiter security code. Please dont share any one else.", user.MOBILE_NO);
return RedirectToAction("Login", "Admin");
}
else
{
ViewBag.Message = "Please enter correct mobile number";
}
}
return View();
}
#endregion
#region Login using TB_Admin_Registration
//public ActionResult Login()
//{
// return View();
//}
//[HttpPost]
//public ActionResult Login(TB_AdminRegistration tb_AdminRegistration)
//{
// if (tb_AdminRegistration != null)
// {
// TB_AdminRegistration admin = db.TB_AdminRegistration.Where(x => x.USER_NAME == tb_AdminRegistration.USER_NAME && x.PASSWORD == tb_AdminRegistration.PASSWORD && x.STATUS == "Active").FirstOrDefault();
// if (admin != null)
// {
// Session["ADMIN_ID"] = admin.ADMIN_ID;
// Session["USER_NAME"] = admin.USER_NAME;
// return RedirectToAction("AdminList", "Admin");
// }
// else
// {
// ViewBag.Message = "Please enter valid user name and password.";
// }
// }
// return View();
//}
//public ActionResult ForgotPassword()
//{
// return View();
//}
//[HttpPost]
//public ActionResult ForgotPassword(TB_AdminRegistration tb_AdminRegistration)
//{
// if (tb_AdminRegistration != null)
// {
// TB_AdminRegistration admin = db.TB_AdminRegistration.Where(x => x.MOBILE_NUMBER == tb_AdminRegistration.MOBILE_NUMBER && x.STATUS == "Active").FirstOrDefault();
// if (admin != null)
// {
// FormsAuthentication.SetAuthCookie(tb_AdminRegistration.USER_NAME, true);
// send("Use '" + admin.PASSWORD + "' as a G-infotech security code. Please dont share any one else.", admin.MOBILE_NUMBER);
// return RedirectToAction("Login", "Admin");
// }
// else
// {
// ViewBag.Message = "Please enter correct mobile number";
// }
// }
// return View();
//}
#endregion
#region Send Message
public static void send(string varMSG, string varPhNo)
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://nimbusit.co.in/api/swsend.asp?username=t1wowinfotech&password=33022096&sender=Wowinf&sendto=" + varPhNo + "&message=" + varMSG + "");
//HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://nimbusit.co.in/api/swsend.asp?username=" + varUserName + "&password=" + varPWD + "&sender=" + varSenderID + "&sendto=" + varPhNo + "&message=" + varMSG + "");
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
string responseString = respStreamReader.ReadToEnd();
respStreamReader.Close();
myResp.Close();
}
#endregion
#region Change Password And Forget Password
[VerifyUserAttribute]
public ActionResult ChangePassword()
{
return View();
}
[VerifyUserAttribute]
[HttpPost]
public JsonResult ChangePassword(TB_AdminMaster login)
{
try
{
string ReturnUrl = "";
long id = Convert.ToInt64(Session["ADMIN_ID"]);
var user = db.TB_AdminMaster.Where(a => a.PASSWORD.Equals(login.CurrentPassword) && a.ADMIN_ID == id && a.STATUS == "Active").FirstOrDefault();
if (user != null && login.PASSWORD.Equals(login.ConfirmPassword) == true && login.PASSWORD != login.CurrentPassword)
{
FormsAuthentication.SetAuthCookie(login.MOBILE_NO, true);
if (Url.IsLocalUrl(ReturnUrl))
{
return Json("Please enter correct password.");
}
else
{
user.PASSWORD = login.PASSWORD;
db.SaveChanges();
send("Use '" + user.PASSWORD + "' as a No1Waiter security code. Please dont share any one else.", login.MOBILE_NO);
ViewBag.CorrectMobileNumber = "Please check your mobile phone message.";
return Json("Login successful");
}
}
else
{
return Json("Please enter correct password.");
}
}
catch (Exception ex)
{
}
ModelState.Remove("Password");
return Json("Please enter correct password.");
}
#endregion
public JsonResult getAllAdmin()
{
var _adminList = db.TB_AdminMaster.Select(a => new { a.ADMIN_ID, a.ADMIN_NAME, a.MOBILE_NO, a.EMAIL, a.STATUS }).ToList();
return Json(_adminList, JsonRequestBehavior.AllowGet);
}
public JsonResult getAdminById(long id)
{
var _admin = db.TB_AdminMaster.Where(x => x.ADMIN_ID == id).Select(x => new { x.ADMIN_ID, x.ADMIN_NAME, x.ADDRESS, x.EMAIL, x.MOBILE_NO, x.PASSWORD, x.ADHARCARD_NO, x.ROLES, x.REG_DATE, x.STATUS }).SingleOrDefault();
return Json(_admin, JsonRequestBehavior.AllowGet);
}
// GET: Admin/getModule
public JsonResult getModule()
{
var _getModule = db.TB_Module.Where(x => x.STATUS == "Active").Select(a => new { a.MODULE_ID, a.MODULE_NAME, a.STATUS, Selected = false }).ToList();
return Json(_getModule, JsonRequestBehavior.AllowGet);
}
// GET: Admin/getModuleUpdate
public JsonResult getModuleUpdate(long id)
{
var _getModules = db.TB_Roles.Where(y => y.ADMIN_ID == id && y.STATUS == "Active").Select(x => x.MODULE_ID).ToList();
var _getModule = db.TB_Module.Where(x => x.STATUS == "Active").Select(a => new { a.MODULE_ID, a.MODULE_NAME, a.STATUS }).ToList();
List<TB_Module> listModule = new List<TB_Module>();
TB_Module obj;
var _getM = listModule;
foreach (var item in _getModule)
{
obj = new TB_Module();
obj.MODULE_ID = item.MODULE_ID;
obj.MODULE_NAME = item.MODULE_NAME;
obj.STATUS = item.STATUS;
obj.MODULE_ID = item.MODULE_ID;
if (_getModules.Contains(item.MODULE_ID))
obj.Selected = true;
else
obj.Selected = false;
listModule.Add(obj);
}
var aaaaa = listModule;
return Json(aaaaa, JsonRequestBehavior.AllowGet);
}
public string Add(TB_AdminMaster tb_AdminRegistration)
{
if (tb_AdminRegistration != null)
{
tb_AdminRegistration.STATUS = "Active";
tb_AdminRegistration.REG_DATE = DateTime.Now;
if (tb_AdminRegistration.ROLES == "Admin")
{
tb_AdminRegistration.ROLE_ID = 1;
}
else
{
tb_AdminRegistration.ROLE_ID = 2;
}
db.TB_AdminMaster.Add(tb_AdminRegistration);
db.SaveChanges();
return "Admin register successfully";
}
return "Admin not register successfully";
}
public string Edit(TB_AdminMaster tb_AdminRegistration)
{
if (tb_AdminRegistration != null)
{
TB_AdminMaster admin = db.TB_AdminMaster.Where(x => x.ADMIN_ID == tb_AdminRegistration.ADMIN_ID).FirstOrDefault();
admin.ADMIN_NAME = tb_AdminRegistration.ADMIN_NAME;
admin.MOBILE_NO = tb_AdminRegistration.MOBILE_NO;
admin.EMAIL = tb_AdminRegistration.EMAIL;
admin.ADHARCARD_NO = tb_AdminRegistration.ADHARCARD_NO;
admin.ADDRESS = tb_AdminRegistration.ADDRESS;
admin.ROLES = tb_AdminRegistration.ROLES;
if (tb_AdminRegistration.ROLES == "Admin")
{
admin.ROLE_ID = 1;
}
else
{
admin.ROLE_ID = 2;
}
db.SaveChanges();
var _getModules = db.TB_Roles.Where(y => y.ADMIN_ID == tb_AdminRegistration.ADMIN_ID).Select(x => x.MODULE_ID).ToList();
Master.excutescalerqryString("Update TB_Roles set STATUS = 'Deactive' Where ADMIN_ID = " + tb_AdminRegistration.ADMIN_ID + "");
string connectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
if (con.State == System.Data.ConnectionState.Open) { con.Close(); }
con.Open();
if (tb_AdminRegistration.TB_Roles.Count() > 0)
{
foreach (var item in tb_AdminRegistration.TB_Roles)
{
if (_getModules.Contains(item.MODULE_ID))
{
TB_Roles ap = new TB_Roles();
using (dbConnection dc = new dbConnection())
{
SqlCommand cmd = new SqlCommand("Update_TB_Roles", con);
cmd.Parameters.AddWithValue("@ADMIN_ID", tb_AdminRegistration.ADMIN_ID);
cmd.Parameters.AddWithValue("@STATUS", "Active");
cmd.Parameters.AddWithValue("@MODULE_ID", item.MODULE_ID);
cmd.CommandType = CommandType.StoredProcedure;
int result = Convert.ToInt32(cmd.ExecuteScalar());
}
}
else
{
TB_Roles ap = new TB_Roles();
using (dbConnection dc = new dbConnection())
{
SqlCommand cmd = new SqlCommand("Update_TB_Roles", con);
cmd.Parameters.AddWithValue("@ADMIN_ID", tb_AdminRegistration.ADMIN_ID);
cmd.Parameters.AddWithValue("@STATUS", "Active");
cmd.Parameters.AddWithValue("@MODULE_ID", item.MODULE_ID);
cmd.CommandType = CommandType.StoredProcedure;
int result = Convert.ToInt32(cmd.ExecuteScalar());
}
}
}
}
con.Close();
return "Admin updated successfully";
}
return "Admin not updated successfully";
}
public ActionResult Profile()
{
return View();
}
public JsonResult getProfileDetails()
{
long id = 1;
//Convert.ToInt64(Session["ADMIN_ID"]);
var _admin = db.TB_AdminMaster.Where(x => x.ADMIN_ID == id).Select(x => new { x.ADMIN_ID, x.ADMIN_NAME, x.ADDRESS, x.EMAIL, x.MOBILE_NO, x.PASSWORD, x.ADHARCARD_NO }).SingleOrDefault();
return Json(_admin, JsonRequestBehavior.AllowGet);
}
public string ChangeStatus(long id)
{
if (id != null)
{
TB_AdminMaster Admin = db.TB_AdminMaster.Where(b => b.ADMIN_ID == id).SingleOrDefault();
if (Admin.STATUS == "Active")
{
Admin.STATUS = "Deactive";
db.SaveChanges();
}
else
{
Admin.STATUS = "Active";
db.SaveChanges();
}
}
return "Status change Successfully.";
}
}
}
View
@{
ViewBag.Title = "AdminList";
}
<style>
.statusActive {
background-color: green;
}
.statusDeactive {
background-color: red;
}
</style>
<div ng-controller="AdminCtrl">
<div ng-show="PreloderShow" id="loader"></div>
<div class="page-header">
<h1>
Admin
<button type="button" ng-click="Add()" class="btn btn-primary btn-sm pull-right"><span class="fa glyphicon-plus"></span> Add New</button>
@*<small>
<i class="ace-icon fa fa-angle-double-right"></i>
Common form elements and layouts
</small>*@
</h1>
</div><!-- /.page-header -->
<div class="page-content">
<div class="main-content">
<div ng-show="AdminShow">
<form name="adminForm" ng-submit="adminSubmit()" data-toggle="validator" role="form">
<div class="col-md-6">
<div class="form-group col-md-12" ng-class="{'has-error':adminForm.ADMIN_NAME.$invalid && !adminForm.ADMIN_NAME.$pristine}">
<label class="control-label">Admin Name</label>
<input type="text" id="ADMIN_ID" ng-model="ADMIN_ID" name="ADMIN_ID" hidden />
<input type="text" name="ADMIN_NAME" class="form-control" ng-model="ADMIN_NAME" required />
<small ng-show="adminForm.ADMIN_NAME.$invalid && !adminForm.ADMIN_NAME.$pristine" class="help-block">Full name of admin is required.</small>
</div>
<div class="form-group col-md-12" ng-class="{'has-error' : adminForm.MOBILE_NO.$invalid && !adminForm.MOBILE_NO.$pristine}">
<label class="control-label">Mobile Number</label>
<input type="text" name="MOBILE_NO" class="form-control" ng-model="MOBILE_NO" maxlength="10" min="10" ng-minlength="10" ng-maxlength="10" required />
<small ng-show="adminForm.MOBILE_NO.$invalid && !adminForm.MOBILE_NO.$pristine" class="help-block">Mobile number is required.</small>
<small ng-show="adminForm.MOBILE_NO.$error.minlength" class="help-block"> Mobile number too small.</small>
</div>
<div class="form-group col-md-12" ng-class="{'has-error' : adminForm.EMAIL.$invalid && !adminForm.EMAIL.$pristine}">
<label class="control-label">Email Address <i>(Optional)</i></label>
<input type="email" class="form-control" name="EMAIL" ng-model="EMAIL" />
<small ng-show="adminForm.EMAIL.$invalid" class="help-block">Please enter valid email address</small>
</div>
<div class="form-group col-md-12" ng-class="{'has-error' : adminForm.ADHARCARD_NO.$invalid && !adminForm.ADHARCARD_NO.$pristine}">
<label class="control-label">Adharcard Number <i>(Optional)</i></label>
<input type="text" class="form-control" name="ADHARCARD_NO" ng-model="ADHARCARD_NO" maxlength="12" min="12" ng-minlength="12" ng-maxlength="12" />
<small ng-show="adminForm.ADHARCARD_NO.$invalid && !adminForm.ADHARCARD_NO.$pristine" class="help-block">Adharcard number is required</small>
</div>
<div class="form-group col-md-12" ng-class="{'has-error' : adminForm.ADDRESS.$invalid && !adminForm.ADDRESS.$pristine}">
<label class="control-label">Address</label>
<textarea type="text" class="form-control" name="ADDRESS" ng-model="ADDRESS" rows="5" required></textarea>
<small ng-show="adminForm.ADDRESS.$invalid && !adminForm.ADDRESS.$pristine" class="help-block">Address is required</small>
</div>
<div ng-show="showPassword">
<div class="form-group col-md-12" ng-class="{'has-error' : adminForm.PASSWORD.$invalid && !adminForm.PASSWORD.$pristine}">
<label class="control-label">Password</label>
<input type="password" class="form-control" id="PASSWORD" name="PASSWORD" ng-model="PASSWORD" ng-minlength="6" min="6" maxlength="30" required />
<input type="checkbox" onclick="myFunction()">Show Password
<small ng-show="adminForm.PASSWORD.$invalid && !adminForm.PASSWORD.$pristine" class="help-block">Password is required.</small>
<small ng-show="adminForm.PASSWORD.$error.minlength" class="help-block">Password is too small.</small>
</div>
</div>
<div class="form-group col-md-12">
<div class="radio">
<label class="radio-inline"><input type="radio" class="ace input-lg" ng-model="ROLES" name="Admin" value="Admin"><span class="lbl bigger-120"> Admin</span></label>
<label class="radio-inline"><input type="radio" class="ace input-lg" ng-model="ROLES" name="SubAdmin" value="SubAdmin" checked><span class="lbl bigger-120"> Sub-Admin</span></label>
</div>
</div>
<div class="form-group col-md-12">
<input type="button" value="{{Action}}" ng-click="AddUpdate(admin)" class="btn btn-success btn-sm" ng-disabled="adminForm.$invalid" />
<input type="button" value="Cancel" ng-click="Cancel()" class="btn btn-danger btn-sm" />
</div>
</div>
<div class="col-md-6">
<!-- checkbox -->
<label class="control-label">Modules of the project...</label>
<div class="checkbox block" ng-repeat="roles in ROLE">
<label for="chkCustomer_{{roles.MODULE_ID}}">
<input id="chkCustomer_{{roles.MODULE_ID}}" type="checkbox" ng-model="roles.Selected" class="ace input-lg" />
<span class="lbl bigger-120"> {{roles.MODULE_NAME}}</span>
</label>
</div>
</div>
</form>
</div>
</div>
<div ng-show="AdminList">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Action</th>
<th>#</th>
<th>Name</th>
<th>Mobile NO</th>
<th>Email</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td><input type="text" class="form-control" placeholder="Admin" ng-model="searchText0.ADMIN_NAME" /></td>
<td><input type="text" class="form-control" placeholder="Mobile" ng-model="searchText1.MOBILE_NO" /></td>
<td><input type="text" class="form-control" placeholder="Email" ng-model="searchText2.EMAIL" /></td>
<td><input type="text" class="form-control" placeholder="Status" ng-model="searchText3.STATUS" /></td>
</tr>
<tr ng-repeat="admin in AdminList | filter:searchText0 | filter:searchText1 | filter:searchText2 | filter:searchText3">
<td>
<div class="hidden-sm hidden-xs btn-group">
<button class="btn btn-xs btn-success">
<i class="ace-icon fa fa-check bigger-120" ng-click="view(admin)" data-toggle="modal" data-target="#myModal"></i>
</button>
<button class="btn btn-xs btn-info">
<i class="ace-icon fa fa-pencil bigger-120" ng-click="edit(admin)"></i>
</button>
<button class="btn btn-xs btn-warning">
<i class="ace-icon fa fa-flag bigger-120" ng-click="changeStatus(admin)" data-toggle="modal" data-target="#changeStatus"></i>
</button>
</div>
@*<span class="btn btn-warning btn-sm" ng-click="edit(admin)">Edit</span>*@
</td>
<td>{{$index+1}}</td>
<td>{{admin.ADMIN_NAME}}</td>
<td>{{admin.MOBILE_NO}}</td>
<td>{{admin.EMAIL}}</td>
<td>
<span class="label label-sm" ng-class="{statusActive:admin.STATUS=='Active' , statusDeactive:admin.STATUS=='Deactive'}">{{admin.STATUS}}</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Modal Change Status-->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Admin Details</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="row">
<div class="col-xs-4 col-sm-4 center">
<div>
<span class="profile-picture">
<img id="avatar" check-image class="editable img-responsive xs" alt="User" src="~/assets/images/avatars/user.jpg" />
</span>
<div class="space-4"></div>
<div class="width-80 label label-info label-xlg arrowed-in arrowed-in-right">
<div class="inline position-relative">
<a href="#" class="user-title-label dropdown-toggle" data-toggle="dropdown">
<span class="white">{{_admin.ADMIN_NAME}}</span>
</a>
</div>
</div>
</div>
<div class="clearfix">
<div class="grid1">
@*<span class="bigger-175 blue">{{_user.RETINGS}}</span>
<br />
Rating*@
</div>
</div>
</div>
<div class="col-xs-8 col-sm-8">
<div class="profile-user-info">
<div class="profile-info-row">
<div class="profile-info-name"> Admin Id </div>
<div class="profile-info-value">
<span ng-model="_user.USER_ID">{{_admin.ADMIN_ID}}</span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Mobile No. </div>
<div class="profile-info-value">
<span>{{_admin.MOBILE_NO}}</span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Email </div>
<div class="profile-info-value">
<span>{{_admin.EMAIL}}</span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Address </div>
<div class="profile-info-value">
<i class="fa fa-map-marker light-orange bigger-110"></i>
<span>{{_admin.ADDRESS}}</span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Adharcard Number </div>
<div class="profile-info-value">
<span>{{_admin.ADHARCARD_NO}}</span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Registration Date </div>
<div class="profile-info-value">
<span>{{_admin.REG_DATE | jsonDate}}</span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Status </div>
<div class="profile-info-value">
<span>{{_admin.STATUS}}</span>
</div>
</div>
</div>
<div class="hr hr-8 dotted"></div>
<div class="form-group col-md-12">
<input type="button" value="Close" ng-click="Cancel()" class="btn btn-danger btn-sm pull-right" data-dismiss="modal" />
</div>
</div><!-- /.col -->
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modal Change Status-->
<div id="changeStatus" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Change Status</h4>
</div>
<div class="modal-body">
<div class="row">
<form name="annerForm" ng-submit="ChangeStatus()">
<div class="form-group col-md-12">
<label class="control-label">Are you sure to change admin status ?</label>
<br />
<label class="control-label" hidden>{{ADMIN_ID}}</label>
</div>
<div class="form-group col-md-12">
<input type="submit" class="btn btn-primary btn-sm" ng-click="btnChangeStatus(admin.ADMIN_ID)" value="Change Status" />
<input type="button" value="Cancel" class="btn btn-danger btn-sm " data-dismiss="modal" />
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
@section scripts{
<script src="~/assets/js/ace-elements.min.js"></script>
<script src="~/AngularJSCtrl/AdminCtrl.js"></script>
<script>
$(function () {
$('#DataTable').DataTable({
dom: 'Bfrtip',
buttons: [
'excel'
]
})
})
function myFunction() {
var x = document.getElementById("PASSWORD");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</script>
}
AngularJS
app.service("AdminService", function ($http) {
this.getAllAdmin = function () {
return $http.get("/Admin/getAllAdmin");
};
//Module
this.GetModule = function () {
return $http.get("/Admin/getModule");
}
//Module
this.GetModuleUpdate = function (id) {
return $http.get("/Admin/getModuleUpdate?id=" + id);
}
this.getAdminById = function (id) {
var response = $http({
method: "GET",
url: "/Admin/getAdminById",
params: {
id: JSON.stringify(id)
}
});
return response;
};
this.add = function (admin) {
var response = $http({
method: "POST",
url: "/Admin/Add",
data: JSON.stringify(admin),
dataType: "json"
});
return response;
};
this.edit = function (admin) {
var response = $http({
method: "POST",
url: "/Admin/Edit",
data: JSON.stringify(admin),
dataType: "json"
});
return response;
};
this.getChangeStatus = function (id) {
var response = $http({
method: "POST",
url: "/Admin/ChangeStatus",
params: {
id: JSON.stringify(id)
}
});
return response;
};
});
app.controller("AdminCtrl", function ($scope, AdminService) {
$scope.AdminShow = false;
GetAll();
function GetAll() {
$scope.Action = "List";
debugger;
var getAdmin = AdminService.getAllAdmin();
getAdmin.then(function (response) {
$scope.AdminList = response.data;
}, function () {
$.notify("Error to load data...", "error");
});
};
function getMoule() {
var getsubadmin = AdminService.GetModule();
$scope.showLoader = true;
getsubadmin.then(function (response) {
$scope.ROLE = response.data;
}, function () {
alert("Error to load data...")
});
$scope.showLoader = false;
}
function getMouleUpdate(id) {
var getsubadmin = AdminService.GetModuleUpdate(id);
$scope.showLoader = true;
getsubadmin.then(function (response) {
$scope.ROLE = response.data;
}, function () {
alert("Error to load data...")
});
$scope.showLoader = false;
}
$scope.edit = function (admin) {
getMouleUpdate(admin.ADMIN_ID);
$scope.PreloderShow = true;
var getAdmin = AdminService.getAdminById(admin.ADMIN_ID);
getAdmin.then(function (response) {
$scope._admin = response.data;
$scope.ADMIN_ID = $scope._admin.ADMIN_ID;
$scope.ADMIN_NAME = $scope._admin.ADMIN_NAME;
$scope.MOBILE_NO = $scope._admin.MOBILE_NO;
$scope.EMAIL = $scope._admin.EMAIL;
$scope.ADDRESS = $scope._admin.ADDRESS;
$scope.ADHARCARD_NO = $scope._admin.ADHARCARD_NO;
$scope.PASSWORD = $scope._admin.PASSWORD;
$scope.ROLES = $scope._admin.ROLES;
$scope.Action = "Update";
$scope.AdminShow = true;
$scope.showPassword = false;
$scope.AdminList = false;
$scope.PreloderShow = false;
}, function () {
$.notify("Error to load data...", "error");
});
};
$scope.view = function (admin) {
getMouleUpdate(admin.ADMIN_ID);
$scope.PreloderShow = true;
var getAdmin = AdminService.getAdminById(admin.ADMIN_ID);
getAdmin.then(function (response) {
$scope._admin = response.data;
$scope.PreloderShow = false;
}, function () {
$.notify("Error to load data...", "error");
});
};
$scope.AddUpdate = function () {
$scope.PreloderShow = true;
var list = [];
for (var i = 0; i < $scope.ROLE.length; i++) {
if ($scope.ROLE[i].Selected) {
var Id = $scope.ROLE[i].MODULE_ID;
var Name = $scope.ROLE[i].MODULE_NAME;
TB_Roles = {
MODULE_ID: Id,
STATUS: "Active"
}
list.push(TB_Roles);
}
}
var Admin = {
ADMIN_NAME: $scope.ADMIN_NAME,
MOBILE_NO: $scope.MOBILE_NO,
EMAIL: $scope.EMAIL,
ADDRESS: $scope.ADDRESS,
ADHARCARD_NO: $scope.ADHARCARD_NO,
PASSWORD: $scope.PASSWORD,
ROLES: $scope.ROLES,
TB_Roles: list
};
var Task = $scope.Action;
if (Task == "Update") {
Admin.ADMIN_ID = $scope.ADMIN_ID;
var getAdmin = AdminService.edit(Admin);
getAdmin.then(function (msg) {
$.notify(msg.data, "success");
GetAll();
$scope.AdminShow = false;
$scope.AdminList = true;
}, function () {
$.notify('Error to load data...', "error");
});
}
else if (Task == "New") {
var getAdmin = AdminService.add(Admin);
getAdmin.then(function (msg) {
$.notify(msg.data, "success");
GetAll();
$scope.AdminShow = false;
$scope.AdminList = true;
}, function () {
$.notify('Error to load data...', "error");
});
}
$scope.PreloderShow = false;
};
$scope.btnChangeStatus = function () {
var getStatus = AdminService.getChangeStatus($scope.ADMIN_ID);
getStatus.then(function (response) {
$.notify(response.data, "error");
location.reload();
}, function () {
$.notify("Error to load data...", "error");
});
};
$scope.changeStatus = function (admin) {
$scope.ADMIN_ID = admin.ADMIN_ID;
};
$scope.Add = function () {
$scope.showPassword = true;
$scope.AdminShow = true;
$scope.AdminList = false;
Clear();
getMoule();
$scope.Action = "New";
};
$scope.Cancel = function () {
$scope.AdminShow = false;
$scope.AdminList = true;
$scope.ADMIN_NAME = "";
$scope.MOBILE_NO = "";
$scope.EMAIL = "";
$scope.ADDRESS = "";
$scope.ADHARCARD_NO = "";
$scope.PASSWORD = "";
$scope.ROLES = "";
GetAll();
};
function Clear() {
$scope.ADMIN_NAME = "";
$scope.MOBILE_NO = "";
$scope.ALTERNATE_MOBILE = "";
$scope.EMAIL = "";
$scope.ADDRESS = "";
$scope.ADHARCARD_NO = "";
$scope.PASSWORD = "";
$scope.ROLES = "";
};
});
Class file
public long ADMIN_ID { get; set; }
public string ADMIN_NAME { get; set; }
public string MOBILE_NO { get; set; }
public string PASSWORD { get; set; }
public string ADDRESS { get; set; }
public string ADHARCARD_NO { get; set; }
public string STATUS { get; set; }
public Nullable<System.DateTime> REG_DATE { get; set; }
public string EMAIL { get; set; }
public Nullable<long> ROLE_ID { get; set; }
public string ROLES { get; set; }
[NotMapped]
public string CurrentPassword { get; set; }
[NotMapped]
public string ConfirmPassword { get; set; }
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
namespace NoOneWaiter.Controllers.Account
{
public class AdminController : Controller
{
dbConnection db = new dbConnection();
// GET: Admin
public ActionResult AdminList()
{
return View();
}
#region Login Using TB_AdminMaster
public ActionResult Login()
{
Session.Clear();
return View();
}
[HttpPost]
public ActionResult Login(TB_AdminMaster tb_AdminMaster)
{
if (tb_AdminMaster != null)
{
TB_AdminMaster user = db.TB_AdminMaster.Where(x => x.MOBILE_NO == tb_AdminMaster.MOBILE_NO && x.PASSWORD == tb_AdminMaster.PASSWORD && x.STATUS == "Active").FirstOrDefault();
if (user != null)
{
Session["ADMIN_ID"] = user.ADMIN_ID;
Session["ADMIN_NAME"] = user.ADMIN_NAME;
return RedirectToAction("Dashboard", "Dashboard");
}
else
{
ViewBag.Message = "Please enter valid user name and password.";
}
}
return View();
}
public JsonResult AccessList()
{
Int64 id = Convert.ToInt64(Session["ADMIN_ID"]);
var list = db.TB_Roles.Where(x => x.ADMIN_ID == id).Select(y => new { y.TB_Module.MODULE_NAME }).ToList();
Session["Permission"] = list;
return Json(list, JsonRequestBehavior.AllowGet);
}
public ActionResult ForgotPassword()
{
return View();
}
[HttpPost]
public ActionResult ForgotPassword(string MobileNumber)
{
if (MobileNumber != null)
{
TB_AdminMaster user = db.TB_AdminMaster.Where(x => x.MOBILE_NO == MobileNumber && x.STATUS == "Active").FirstOrDefault();
if (user != null)
{
FormsAuthentication.SetAuthCookie(user.ADMIN_NAME, true);
send("Use '" + user.PASSWORD + "' as a NumberOneWaiter security code. Please dont share any one else.", user.MOBILE_NO);
return RedirectToAction("Login", "Admin");
}
else
{
ViewBag.Message = "Please enter correct mobile number";
}
}
return View();
}
#endregion
#region Login using TB_Admin_Registration
//public ActionResult Login()
//{
// return View();
//}
//[HttpPost]
//public ActionResult Login(TB_AdminRegistration tb_AdminRegistration)
//{
// if (tb_AdminRegistration != null)
// {
// TB_AdminRegistration admin = db.TB_AdminRegistration.Where(x => x.USER_NAME == tb_AdminRegistration.USER_NAME && x.PASSWORD == tb_AdminRegistration.PASSWORD && x.STATUS == "Active").FirstOrDefault();
// if (admin != null)
// {
// Session["ADMIN_ID"] = admin.ADMIN_ID;
// Session["USER_NAME"] = admin.USER_NAME;
// return RedirectToAction("AdminList", "Admin");
// }
// else
// {
// ViewBag.Message = "Please enter valid user name and password.";
// }
// }
// return View();
//}
//public ActionResult ForgotPassword()
//{
// return View();
//}
//[HttpPost]
//public ActionResult ForgotPassword(TB_AdminRegistration tb_AdminRegistration)
//{
// if (tb_AdminRegistration != null)
// {
// TB_AdminRegistration admin = db.TB_AdminRegistration.Where(x => x.MOBILE_NUMBER == tb_AdminRegistration.MOBILE_NUMBER && x.STATUS == "Active").FirstOrDefault();
// if (admin != null)
// {
// FormsAuthentication.SetAuthCookie(tb_AdminRegistration.USER_NAME, true);
// send("Use '" + admin.PASSWORD + "' as a G-infotech security code. Please dont share any one else.", admin.MOBILE_NUMBER);
// return RedirectToAction("Login", "Admin");
// }
// else
// {
// ViewBag.Message = "Please enter correct mobile number";
// }
// }
// return View();
//}
#endregion
#region Send Message
public static void send(string varMSG, string varPhNo)
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://nimbusit.co.in/api/swsend.asp?username=t1wowinfotech&password=33022096&sender=Wowinf&sendto=" + varPhNo + "&message=" + varMSG + "");
//HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://nimbusit.co.in/api/swsend.asp?username=" + varUserName + "&password=" + varPWD + "&sender=" + varSenderID + "&sendto=" + varPhNo + "&message=" + varMSG + "");
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
string responseString = respStreamReader.ReadToEnd();
respStreamReader.Close();
myResp.Close();
}
#endregion
#region Change Password And Forget Password
[VerifyUserAttribute]
public ActionResult ChangePassword()
{
return View();
}
[VerifyUserAttribute]
[HttpPost]
public JsonResult ChangePassword(TB_AdminMaster login)
{
try
{
string ReturnUrl = "";
long id = Convert.ToInt64(Session["ADMIN_ID"]);
var user = db.TB_AdminMaster.Where(a => a.PASSWORD.Equals(login.CurrentPassword) && a.ADMIN_ID == id && a.STATUS == "Active").FirstOrDefault();
if (user != null && login.PASSWORD.Equals(login.ConfirmPassword) == true && login.PASSWORD != login.CurrentPassword)
{
FormsAuthentication.SetAuthCookie(login.MOBILE_NO, true);
if (Url.IsLocalUrl(ReturnUrl))
{
return Json("Please enter correct password.");
}
else
{
user.PASSWORD = login.PASSWORD;
db.SaveChanges();
send("Use '" + user.PASSWORD + "' as a No1Waiter security code. Please dont share any one else.", login.MOBILE_NO);
ViewBag.CorrectMobileNumber = "Please check your mobile phone message.";
return Json("Login successful");
}
}
else
{
return Json("Please enter correct password.");
}
}
catch (Exception ex)
{
}
ModelState.Remove("Password");
return Json("Please enter correct password.");
}
#endregion
public JsonResult getAllAdmin()
{
var _adminList = db.TB_AdminMaster.Select(a => new { a.ADMIN_ID, a.ADMIN_NAME, a.MOBILE_NO, a.EMAIL, a.STATUS }).ToList();
return Json(_adminList, JsonRequestBehavior.AllowGet);
}
public JsonResult getAdminById(long id)
{
var _admin = db.TB_AdminMaster.Where(x => x.ADMIN_ID == id).Select(x => new { x.ADMIN_ID, x.ADMIN_NAME, x.ADDRESS, x.EMAIL, x.MOBILE_NO, x.PASSWORD, x.ADHARCARD_NO, x.ROLES, x.REG_DATE, x.STATUS }).SingleOrDefault();
return Json(_admin, JsonRequestBehavior.AllowGet);
}
// GET: Admin/getModule
public JsonResult getModule()
{
var _getModule = db.TB_Module.Where(x => x.STATUS == "Active").Select(a => new { a.MODULE_ID, a.MODULE_NAME, a.STATUS, Selected = false }).ToList();
return Json(_getModule, JsonRequestBehavior.AllowGet);
}
// GET: Admin/getModuleUpdate
public JsonResult getModuleUpdate(long id)
{
var _getModules = db.TB_Roles.Where(y => y.ADMIN_ID == id && y.STATUS == "Active").Select(x => x.MODULE_ID).ToList();
var _getModule = db.TB_Module.Where(x => x.STATUS == "Active").Select(a => new { a.MODULE_ID, a.MODULE_NAME, a.STATUS }).ToList();
List<TB_Module> listModule = new List<TB_Module>();
TB_Module obj;
var _getM = listModule;
foreach (var item in _getModule)
{
obj = new TB_Module();
obj.MODULE_ID = item.MODULE_ID;
obj.MODULE_NAME = item.MODULE_NAME;
obj.STATUS = item.STATUS;
obj.MODULE_ID = item.MODULE_ID;
if (_getModules.Contains(item.MODULE_ID))
obj.Selected = true;
else
obj.Selected = false;
listModule.Add(obj);
}
var aaaaa = listModule;
return Json(aaaaa, JsonRequestBehavior.AllowGet);
}
public string Add(TB_AdminMaster tb_AdminRegistration)
{
if (tb_AdminRegistration != null)
{
tb_AdminRegistration.STATUS = "Active";
tb_AdminRegistration.REG_DATE = DateTime.Now;
if (tb_AdminRegistration.ROLES == "Admin")
{
tb_AdminRegistration.ROLE_ID = 1;
}
else
{
tb_AdminRegistration.ROLE_ID = 2;
}
db.TB_AdminMaster.Add(tb_AdminRegistration);
db.SaveChanges();
return "Admin register successfully";
}
return "Admin not register successfully";
}
public string Edit(TB_AdminMaster tb_AdminRegistration)
{
if (tb_AdminRegistration != null)
{
TB_AdminMaster admin = db.TB_AdminMaster.Where(x => x.ADMIN_ID == tb_AdminRegistration.ADMIN_ID).FirstOrDefault();
admin.ADMIN_NAME = tb_AdminRegistration.ADMIN_NAME;
admin.MOBILE_NO = tb_AdminRegistration.MOBILE_NO;
admin.EMAIL = tb_AdminRegistration.EMAIL;
admin.ADHARCARD_NO = tb_AdminRegistration.ADHARCARD_NO;
admin.ADDRESS = tb_AdminRegistration.ADDRESS;
admin.ROLES = tb_AdminRegistration.ROLES;
if (tb_AdminRegistration.ROLES == "Admin")
{
admin.ROLE_ID = 1;
}
else
{
admin.ROLE_ID = 2;
}
db.SaveChanges();
var _getModules = db.TB_Roles.Where(y => y.ADMIN_ID == tb_AdminRegistration.ADMIN_ID).Select(x => x.MODULE_ID).ToList();
Master.excutescalerqryString("Update TB_Roles set STATUS = 'Deactive' Where ADMIN_ID = " + tb_AdminRegistration.ADMIN_ID + "");
string connectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
if (con.State == System.Data.ConnectionState.Open) { con.Close(); }
con.Open();
if (tb_AdminRegistration.TB_Roles.Count() > 0)
{
foreach (var item in tb_AdminRegistration.TB_Roles)
{
if (_getModules.Contains(item.MODULE_ID))
{
TB_Roles ap = new TB_Roles();
using (dbConnection dc = new dbConnection())
{
SqlCommand cmd = new SqlCommand("Update_TB_Roles", con);
cmd.Parameters.AddWithValue("@ADMIN_ID", tb_AdminRegistration.ADMIN_ID);
cmd.Parameters.AddWithValue("@STATUS", "Active");
cmd.Parameters.AddWithValue("@MODULE_ID", item.MODULE_ID);
cmd.CommandType = CommandType.StoredProcedure;
int result = Convert.ToInt32(cmd.ExecuteScalar());
}
}
else
{
TB_Roles ap = new TB_Roles();
using (dbConnection dc = new dbConnection())
{
SqlCommand cmd = new SqlCommand("Update_TB_Roles", con);
cmd.Parameters.AddWithValue("@ADMIN_ID", tb_AdminRegistration.ADMIN_ID);
cmd.Parameters.AddWithValue("@STATUS", "Active");
cmd.Parameters.AddWithValue("@MODULE_ID", item.MODULE_ID);
cmd.CommandType = CommandType.StoredProcedure;
int result = Convert.ToInt32(cmd.ExecuteScalar());
}
}
}
}
con.Close();
return "Admin updated successfully";
}
return "Admin not updated successfully";
}
public ActionResult Profile()
{
return View();
}
public JsonResult getProfileDetails()
{
long id = 1;
//Convert.ToInt64(Session["ADMIN_ID"]);
var _admin = db.TB_AdminMaster.Where(x => x.ADMIN_ID == id).Select(x => new { x.ADMIN_ID, x.ADMIN_NAME, x.ADDRESS, x.EMAIL, x.MOBILE_NO, x.PASSWORD, x.ADHARCARD_NO }).SingleOrDefault();
return Json(_admin, JsonRequestBehavior.AllowGet);
}
public string ChangeStatus(long id)
{
if (id != null)
{
TB_AdminMaster Admin = db.TB_AdminMaster.Where(b => b.ADMIN_ID == id).SingleOrDefault();
if (Admin.STATUS == "Active")
{
Admin.STATUS = "Deactive";
db.SaveChanges();
}
else
{
Admin.STATUS = "Active";
db.SaveChanges();
}
}
return "Status change Successfully.";
}
}
}
View
@{
ViewBag.Title = "AdminList";
}
<style>
.statusActive {
background-color: green;
}
.statusDeactive {
background-color: red;
}
</style>
<div ng-controller="AdminCtrl">
<div ng-show="PreloderShow" id="loader"></div>
<div class="page-header">
<h1>
Admin
<button type="button" ng-click="Add()" class="btn btn-primary btn-sm pull-right"><span class="fa glyphicon-plus"></span> Add New</button>
@*<small>
<i class="ace-icon fa fa-angle-double-right"></i>
Common form elements and layouts
</small>*@
</h1>
</div><!-- /.page-header -->
<div class="page-content">
<div class="main-content">
<div ng-show="AdminShow">
<form name="adminForm" ng-submit="adminSubmit()" data-toggle="validator" role="form">
<div class="col-md-6">
<div class="form-group col-md-12" ng-class="{'has-error':adminForm.ADMIN_NAME.$invalid && !adminForm.ADMIN_NAME.$pristine}">
<label class="control-label">Admin Name</label>
<input type="text" id="ADMIN_ID" ng-model="ADMIN_ID" name="ADMIN_ID" hidden />
<input type="text" name="ADMIN_NAME" class="form-control" ng-model="ADMIN_NAME" required />
<small ng-show="adminForm.ADMIN_NAME.$invalid && !adminForm.ADMIN_NAME.$pristine" class="help-block">Full name of admin is required.</small>
</div>
<div class="form-group col-md-12" ng-class="{'has-error' : adminForm.MOBILE_NO.$invalid && !adminForm.MOBILE_NO.$pristine}">
<label class="control-label">Mobile Number</label>
<input type="text" name="MOBILE_NO" class="form-control" ng-model="MOBILE_NO" maxlength="10" min="10" ng-minlength="10" ng-maxlength="10" required />
<small ng-show="adminForm.MOBILE_NO.$invalid && !adminForm.MOBILE_NO.$pristine" class="help-block">Mobile number is required.</small>
<small ng-show="adminForm.MOBILE_NO.$error.minlength" class="help-block"> Mobile number too small.</small>
</div>
<div class="form-group col-md-12" ng-class="{'has-error' : adminForm.EMAIL.$invalid && !adminForm.EMAIL.$pristine}">
<label class="control-label">Email Address <i>(Optional)</i></label>
<input type="email" class="form-control" name="EMAIL" ng-model="EMAIL" />
<small ng-show="adminForm.EMAIL.$invalid" class="help-block">Please enter valid email address</small>
</div>
<div class="form-group col-md-12" ng-class="{'has-error' : adminForm.ADHARCARD_NO.$invalid && !adminForm.ADHARCARD_NO.$pristine}">
<label class="control-label">Adharcard Number <i>(Optional)</i></label>
<input type="text" class="form-control" name="ADHARCARD_NO" ng-model="ADHARCARD_NO" maxlength="12" min="12" ng-minlength="12" ng-maxlength="12" />
<small ng-show="adminForm.ADHARCARD_NO.$invalid && !adminForm.ADHARCARD_NO.$pristine" class="help-block">Adharcard number is required</small>
</div>
<div class="form-group col-md-12" ng-class="{'has-error' : adminForm.ADDRESS.$invalid && !adminForm.ADDRESS.$pristine}">
<label class="control-label">Address</label>
<textarea type="text" class="form-control" name="ADDRESS" ng-model="ADDRESS" rows="5" required></textarea>
<small ng-show="adminForm.ADDRESS.$invalid && !adminForm.ADDRESS.$pristine" class="help-block">Address is required</small>
</div>
<div ng-show="showPassword">
<div class="form-group col-md-12" ng-class="{'has-error' : adminForm.PASSWORD.$invalid && !adminForm.PASSWORD.$pristine}">
<label class="control-label">Password</label>
<input type="password" class="form-control" id="PASSWORD" name="PASSWORD" ng-model="PASSWORD" ng-minlength="6" min="6" maxlength="30" required />
<input type="checkbox" onclick="myFunction()">Show Password
<small ng-show="adminForm.PASSWORD.$invalid && !adminForm.PASSWORD.$pristine" class="help-block">Password is required.</small>
<small ng-show="adminForm.PASSWORD.$error.minlength" class="help-block">Password is too small.</small>
</div>
</div>
<div class="form-group col-md-12">
<div class="radio">
<label class="radio-inline"><input type="radio" class="ace input-lg" ng-model="ROLES" name="Admin" value="Admin"><span class="lbl bigger-120"> Admin</span></label>
<label class="radio-inline"><input type="radio" class="ace input-lg" ng-model="ROLES" name="SubAdmin" value="SubAdmin" checked><span class="lbl bigger-120"> Sub-Admin</span></label>
</div>
</div>
<div class="form-group col-md-12">
<input type="button" value="{{Action}}" ng-click="AddUpdate(admin)" class="btn btn-success btn-sm" ng-disabled="adminForm.$invalid" />
<input type="button" value="Cancel" ng-click="Cancel()" class="btn btn-danger btn-sm" />
</div>
</div>
<div class="col-md-6">
<!-- checkbox -->
<label class="control-label">Modules of the project...</label>
<div class="checkbox block" ng-repeat="roles in ROLE">
<label for="chkCustomer_{{roles.MODULE_ID}}">
<input id="chkCustomer_{{roles.MODULE_ID}}" type="checkbox" ng-model="roles.Selected" class="ace input-lg" />
<span class="lbl bigger-120"> {{roles.MODULE_NAME}}</span>
</label>
</div>
</div>
</form>
</div>
</div>
<div ng-show="AdminList">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Action</th>
<th>#</th>
<th>Name</th>
<th>Mobile NO</th>
<th>Email</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td><input type="text" class="form-control" placeholder="Admin" ng-model="searchText0.ADMIN_NAME" /></td>
<td><input type="text" class="form-control" placeholder="Mobile" ng-model="searchText1.MOBILE_NO" /></td>
<td><input type="text" class="form-control" placeholder="Email" ng-model="searchText2.EMAIL" /></td>
<td><input type="text" class="form-control" placeholder="Status" ng-model="searchText3.STATUS" /></td>
</tr>
<tr ng-repeat="admin in AdminList | filter:searchText0 | filter:searchText1 | filter:searchText2 | filter:searchText3">
<td>
<div class="hidden-sm hidden-xs btn-group">
<button class="btn btn-xs btn-success">
<i class="ace-icon fa fa-check bigger-120" ng-click="view(admin)" data-toggle="modal" data-target="#myModal"></i>
</button>
<button class="btn btn-xs btn-info">
<i class="ace-icon fa fa-pencil bigger-120" ng-click="edit(admin)"></i>
</button>
<button class="btn btn-xs btn-warning">
<i class="ace-icon fa fa-flag bigger-120" ng-click="changeStatus(admin)" data-toggle="modal" data-target="#changeStatus"></i>
</button>
</div>
@*<span class="btn btn-warning btn-sm" ng-click="edit(admin)">Edit</span>*@
</td>
<td>{{$index+1}}</td>
<td>{{admin.ADMIN_NAME}}</td>
<td>{{admin.MOBILE_NO}}</td>
<td>{{admin.EMAIL}}</td>
<td>
<span class="label label-sm" ng-class="{statusActive:admin.STATUS=='Active' , statusDeactive:admin.STATUS=='Deactive'}">{{admin.STATUS}}</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Modal Change Status-->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Admin Details</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="row">
<div class="col-xs-4 col-sm-4 center">
<div>
<span class="profile-picture">
<img id="avatar" check-image class="editable img-responsive xs" alt="User" src="~/assets/images/avatars/user.jpg" />
</span>
<div class="space-4"></div>
<div class="width-80 label label-info label-xlg arrowed-in arrowed-in-right">
<div class="inline position-relative">
<a href="#" class="user-title-label dropdown-toggle" data-toggle="dropdown">
<span class="white">{{_admin.ADMIN_NAME}}</span>
</a>
</div>
</div>
</div>
<div class="clearfix">
<div class="grid1">
@*<span class="bigger-175 blue">{{_user.RETINGS}}</span>
<br />
Rating*@
</div>
</div>
</div>
<div class="col-xs-8 col-sm-8">
<div class="profile-user-info">
<div class="profile-info-row">
<div class="profile-info-name"> Admin Id </div>
<div class="profile-info-value">
<span ng-model="_user.USER_ID">{{_admin.ADMIN_ID}}</span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Mobile No. </div>
<div class="profile-info-value">
<span>{{_admin.MOBILE_NO}}</span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Email </div>
<div class="profile-info-value">
<span>{{_admin.EMAIL}}</span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Address </div>
<div class="profile-info-value">
<i class="fa fa-map-marker light-orange bigger-110"></i>
<span>{{_admin.ADDRESS}}</span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Adharcard Number </div>
<div class="profile-info-value">
<span>{{_admin.ADHARCARD_NO}}</span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Registration Date </div>
<div class="profile-info-value">
<span>{{_admin.REG_DATE | jsonDate}}</span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Status </div>
<div class="profile-info-value">
<span>{{_admin.STATUS}}</span>
</div>
</div>
</div>
<div class="hr hr-8 dotted"></div>
<div class="form-group col-md-12">
<input type="button" value="Close" ng-click="Cancel()" class="btn btn-danger btn-sm pull-right" data-dismiss="modal" />
</div>
</div><!-- /.col -->
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modal Change Status-->
<div id="changeStatus" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Change Status</h4>
</div>
<div class="modal-body">
<div class="row">
<form name="annerForm" ng-submit="ChangeStatus()">
<div class="form-group col-md-12">
<label class="control-label">Are you sure to change admin status ?</label>
<br />
<label class="control-label" hidden>{{ADMIN_ID}}</label>
</div>
<div class="form-group col-md-12">
<input type="submit" class="btn btn-primary btn-sm" ng-click="btnChangeStatus(admin.ADMIN_ID)" value="Change Status" />
<input type="button" value="Cancel" class="btn btn-danger btn-sm " data-dismiss="modal" />
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
@section scripts{
<script src="~/assets/js/ace-elements.min.js"></script>
<script src="~/AngularJSCtrl/AdminCtrl.js"></script>
<script>
$(function () {
$('#DataTable').DataTable({
dom: 'Bfrtip',
buttons: [
'excel'
]
})
})
function myFunction() {
var x = document.getElementById("PASSWORD");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</script>
}
AngularJS
app.service("AdminService", function ($http) {
this.getAllAdmin = function () {
return $http.get("/Admin/getAllAdmin");
};
//Module
this.GetModule = function () {
return $http.get("/Admin/getModule");
}
//Module
this.GetModuleUpdate = function (id) {
return $http.get("/Admin/getModuleUpdate?id=" + id);
}
this.getAdminById = function (id) {
var response = $http({
method: "GET",
url: "/Admin/getAdminById",
params: {
id: JSON.stringify(id)
}
});
return response;
};
this.add = function (admin) {
var response = $http({
method: "POST",
url: "/Admin/Add",
data: JSON.stringify(admin),
dataType: "json"
});
return response;
};
this.edit = function (admin) {
var response = $http({
method: "POST",
url: "/Admin/Edit",
data: JSON.stringify(admin),
dataType: "json"
});
return response;
};
this.getChangeStatus = function (id) {
var response = $http({
method: "POST",
url: "/Admin/ChangeStatus",
params: {
id: JSON.stringify(id)
}
});
return response;
};
});
app.controller("AdminCtrl", function ($scope, AdminService) {
$scope.AdminShow = false;
GetAll();
function GetAll() {
$scope.Action = "List";
debugger;
var getAdmin = AdminService.getAllAdmin();
getAdmin.then(function (response) {
$scope.AdminList = response.data;
}, function () {
$.notify("Error to load data...", "error");
});
};
function getMoule() {
var getsubadmin = AdminService.GetModule();
$scope.showLoader = true;
getsubadmin.then(function (response) {
$scope.ROLE = response.data;
}, function () {
alert("Error to load data...")
});
$scope.showLoader = false;
}
function getMouleUpdate(id) {
var getsubadmin = AdminService.GetModuleUpdate(id);
$scope.showLoader = true;
getsubadmin.then(function (response) {
$scope.ROLE = response.data;
}, function () {
alert("Error to load data...")
});
$scope.showLoader = false;
}
$scope.edit = function (admin) {
getMouleUpdate(admin.ADMIN_ID);
$scope.PreloderShow = true;
var getAdmin = AdminService.getAdminById(admin.ADMIN_ID);
getAdmin.then(function (response) {
$scope._admin = response.data;
$scope.ADMIN_ID = $scope._admin.ADMIN_ID;
$scope.ADMIN_NAME = $scope._admin.ADMIN_NAME;
$scope.MOBILE_NO = $scope._admin.MOBILE_NO;
$scope.EMAIL = $scope._admin.EMAIL;
$scope.ADDRESS = $scope._admin.ADDRESS;
$scope.ADHARCARD_NO = $scope._admin.ADHARCARD_NO;
$scope.PASSWORD = $scope._admin.PASSWORD;
$scope.ROLES = $scope._admin.ROLES;
$scope.Action = "Update";
$scope.AdminShow = true;
$scope.showPassword = false;
$scope.AdminList = false;
$scope.PreloderShow = false;
}, function () {
$.notify("Error to load data...", "error");
});
};
$scope.view = function (admin) {
getMouleUpdate(admin.ADMIN_ID);
$scope.PreloderShow = true;
var getAdmin = AdminService.getAdminById(admin.ADMIN_ID);
getAdmin.then(function (response) {
$scope._admin = response.data;
$scope.PreloderShow = false;
}, function () {
$.notify("Error to load data...", "error");
});
};
$scope.AddUpdate = function () {
$scope.PreloderShow = true;
var list = [];
for (var i = 0; i < $scope.ROLE.length; i++) {
if ($scope.ROLE[i].Selected) {
var Id = $scope.ROLE[i].MODULE_ID;
var Name = $scope.ROLE[i].MODULE_NAME;
TB_Roles = {
MODULE_ID: Id,
STATUS: "Active"
}
list.push(TB_Roles);
}
}
var Admin = {
ADMIN_NAME: $scope.ADMIN_NAME,
MOBILE_NO: $scope.MOBILE_NO,
EMAIL: $scope.EMAIL,
ADDRESS: $scope.ADDRESS,
ADHARCARD_NO: $scope.ADHARCARD_NO,
PASSWORD: $scope.PASSWORD,
ROLES: $scope.ROLES,
TB_Roles: list
};
var Task = $scope.Action;
if (Task == "Update") {
Admin.ADMIN_ID = $scope.ADMIN_ID;
var getAdmin = AdminService.edit(Admin);
getAdmin.then(function (msg) {
$.notify(msg.data, "success");
GetAll();
$scope.AdminShow = false;
$scope.AdminList = true;
}, function () {
$.notify('Error to load data...', "error");
});
}
else if (Task == "New") {
var getAdmin = AdminService.add(Admin);
getAdmin.then(function (msg) {
$.notify(msg.data, "success");
GetAll();
$scope.AdminShow = false;
$scope.AdminList = true;
}, function () {
$.notify('Error to load data...', "error");
});
}
$scope.PreloderShow = false;
};
$scope.btnChangeStatus = function () {
var getStatus = AdminService.getChangeStatus($scope.ADMIN_ID);
getStatus.then(function (response) {
$.notify(response.data, "error");
location.reload();
}, function () {
$.notify("Error to load data...", "error");
});
};
$scope.changeStatus = function (admin) {
$scope.ADMIN_ID = admin.ADMIN_ID;
};
$scope.Add = function () {
$scope.showPassword = true;
$scope.AdminShow = true;
$scope.AdminList = false;
Clear();
getMoule();
$scope.Action = "New";
};
$scope.Cancel = function () {
$scope.AdminShow = false;
$scope.AdminList = true;
$scope.ADMIN_NAME = "";
$scope.MOBILE_NO = "";
$scope.EMAIL = "";
$scope.ADDRESS = "";
$scope.ADHARCARD_NO = "";
$scope.PASSWORD = "";
$scope.ROLES = "";
GetAll();
};
function Clear() {
$scope.ADMIN_NAME = "";
$scope.MOBILE_NO = "";
$scope.ALTERNATE_MOBILE = "";
$scope.EMAIL = "";
$scope.ADDRESS = "";
$scope.ADHARCARD_NO = "";
$scope.PASSWORD = "";
$scope.ROLES = "";
};
});
Class file
public long ADMIN_ID { get; set; }
public string ADMIN_NAME { get; set; }
public string MOBILE_NO { get; set; }
public string PASSWORD { get; set; }
public string ADDRESS { get; set; }
public string ADHARCARD_NO { get; set; }
public string STATUS { get; set; }
public Nullable<System.DateTime> REG_DATE { get; set; }
public string EMAIL { get; set; }
public Nullable<long> ROLE_ID { get; set; }
public string ROLES { get; set; }
[NotMapped]
public string CurrentPassword { get; set; }
[NotMapped]
public string ConfirmPassword { get; set; }