I have 2 types of roles for users eg: User & admin.
I want to show Update link when login role is user , but when role is Admin n update and delete both link should appear in view Module.
how can I achieve this ? here is my code of view. in which I want to put both link for update and delete based on user role.
@model List<WebApplication5.Models.MyModel>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Show</title>
</head>
<body style="background-color:aliceblue">
<div>
@TempData["Message"]
<b><center>Data Of Table</center></b>
<table style="background-color:azure" border="1" align="center" title="DATA OF EMPLOYEE">
@foreach (var objmymodel in Model)
{
<tr>
<td>@objmymodel.Username</td>
<td>@objmymodel.Password</td>
<td>@Html.ActionLink("delete", "Delete", new {id=@objmymodel.Id })</td>
<td>@Html.ActionLink("update", "Update", new { id = @objmymodel.Id })</td>
</tr>
}
</table>
</div>
<div>@Html.ActionLink("Logout","Login","Mycontroller")</div>
</body>
</html>
here is code of ADO class if i enter admin as user name and password than redirect to show data page as admin or check in data base for username
public static void Logindata(MyModel objmymodel)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=c:\users\nisarg parekh\documents\visual studio 2013\Projects\WebApplication5\WebApplication5\App_Data\Database1.mdf;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework");
con.Open();
if(objmymodel.Username=="admin" && objmymodel.Password=="admin")
{
usernamestring = "admin";
message = "welcome " + objmymodel.Username;
}
else
{
string check = "select Username,Password from tb1 where Username='"+objmymodel.Username+"' and Password='"+objmymodel.Password+"'";
SqlCommand cmd = new SqlCommand(check,con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
usernamestring = objmymodel.Username;
message ="welcome "+ objmymodel.Username;
}
else
{
message = "FAIL";
}
}
here is code of Controller
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(MyModel objmymodel)
{
ado.Logindata(objmymodel);
TempData["Message"] = ado.message;
if (ado.message == "FAIL")
{
objmymodel.Username = "";
objmymodel.Password = "";
return RedirectToAction("Login");
}
else
{
TempData["Message"] = ado.usernamestring;
return RedirectToAction("Show");
}
}