Controller - using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Security; using RoadSafetyMVC.Models.DB; using RoadSafetyMVC.Models.Super; using System.Web.SessionState; namespace RoadSafetyMVC.Controllers { public class SuperController : Controller { connection con = new connection(); public Data_Object_SQL_SERVER obj = new Data_Object_SQL_SERVER(); // // GET: /Super/ public ActionResult Default() { if (Session["UserId"] == null) { Session.Abandon(); return RedirectToAction("Login"); } else { return View(); } } public ActionResult LogOff() { Session.Abandon(); return RedirectToAction("Login"); } public ActionResult comp_maping_users() { if (Session["UserId"] == null) { Session.Abandon(); return RedirectToAction("Login"); } else { List<componentusertypemapping> perUserTypelst = new List<componentusertypemapping>(); if (ModelState.IsValid) { ComponentUserTypeMapping perUserType = new ComponentUserTypeMapping(); perUserType.PermissionList = new List<SelectListItem>(); int PTypeID = 0; foreach (var item in Listclass.GetPermissionList(PTypeID)) { perUserType.PermissionList.Add(new SelectListItem() { Text = item.PType, Value = item.PTypeID.ToString() }); } perUserTypelst.Add(perUserType); } return View(perUserTypelst); } } [HttpPost] public ActionResult comp_maping_users(string perid) { if (Session["UserId"] == null) { Session.Abandon(); return RedirectToAction("Login"); } else { List<componentusertypemapping> perUserTypeMap = new List<componentusertypemapping>(); if (ModelState.IsValid) { perUserTypeMap = Listclass.SelPermissionDetails(Convert.ToInt32(perid)); } ComponentUserTypeMapping perUserType = new ComponentUserTypeMapping(); perUserType.PermissionList = new List<SelectListItem>(); int PTypeID = 0; foreach (var item in Listclass.GetPermissionList(PTypeID)) { perUserType.PermissionList.Add(new SelectListItem() { Text = item.PType, Value = item.PTypeID.ToString() }); } ViewData["PermissionType"] = perUserType; return View(perUserTypeMap); } } public ActionResult ComponentMaster() { if (Session["UserId"] == null) { Session.Abandon(); return RedirectToAction("Login"); } else { List<componentmaster> compMaster = Listclass.CompDetails(); return View(compMaster); } } } } Model- public class ComponentUserTypeMapping { [Required(ErrorMessage = "Enter Component Name")] [Display(Name = "Enter Component Name")] [StringLength(100, ErrorMessage = "Must be of 100 Characters")] public string ComponentName { get; set; } [Required(ErrorMessage = "Enter Module Name")] [Display(Name = "Enter Module Name")] [StringLength(100, ErrorMessage = "Must be of 100 Characters")] public string module_name { get; set; } public int comp_id { get; set; } public int PTypeID { get; set; } public string PType { get; set; } public string Selvalue { get; set; } public List<SelectListItem> PermissionList { get; set; } } public static List<ComponentUserTypeMapping> GetPermissionList(int PTypeID) { List<ComponentUserTypeMapping> Permissionlst = new List<ComponentUserTypeMapping>(); DataSet ds = null; if (PTypeID == 0) { ds = con.simplefetch("select PTypeID, PType from St_PermissionType where Status='Active' order by PType"); } else if (PTypeID > 0) { ds = con.simplefetch("select PTypeID, PType from St_PermissionType where Status='Active' and PTypeID=" + PTypeID + " order by PType"); } foreach (DataRow row in ds.Tables[0].Rows) { ComponentUserTypeMapping permission = new ComponentUserTypeMapping(); permission.PTypeID = Convert.ToInt32(row["PTypeID"]); permission.PType = Convert.ToString(row["PType"]); Permissionlst.Add(permission); } return Permissionlst; } public static List<ComponentUserTypeMapping> SelPermissionDetails(int PTypeID) { DataSet ds = con.simplefetch("select c.*,m.module_name,(case when (select count(*) from map_component_usertype where status='Active' and comp_id=c.comp_id and ut_id='" + PTypeID + "')>0 then 'checked' else '' end) as chk from st_components c,st_module m where m.status='Active' and c.status='Active' and m.mod_id=c.mod_id order by m.module_name,c.comp_name"); List<ComponentUserTypeMapping> permlst = new List<ComponentUserTypeMapping>(); ComponentUserTypeMapping perm = new ComponentUserTypeMapping(); foreach (DataRow row in ds.Tables[0].Rows) { perm.PermissionList = new List<SelectListItem>(); //int permId = 0; perm.module_name = Convert.ToString(row["module_name"]); perm.ComponentName = Convert.ToString(row["comp_name"]); perm.comp_id = Convert.ToInt32(row["comp_id"]); perm.Selvalue = Convert.ToString(PTypeID); //foreach (var item in Listclass.GetPermissionList(permId)) //{ // perm.PermissionList.Add(new SelectListItem() { Text = item.PType, Value = item.PTypeID.ToString() }); //} permlst.Add(perm); } return permlst; } View - @model IEnumerable<roadsafetymvc.models.super.componentusertypemapping> @using RoadSafetyMVC.Models.Super; @using RoadSafetyMVC.Models.DB; @{ ViewBag.Title = "comp_maping_users"; Layout = "~/Views/Super/_SuperLayout.cshtml"; } <!DOCTYPE html> <link rel="stylesheet" href="@Href("~/Content/Site.css")" type="text/css" /> <html> <head> <title>Create</title> <script src="../../Scripts/jquery-1.4.1.js"></script> <script type="text/javascript"> $(function () { $("#item_PTypeID").change(function () { $.post("/Super/comp_maping_users", { perid: $("#item_PTypeID").val() }, function (response) { alert(response); }); }); }); </script> </head> <body> <form name="myform1" method="post"> <div style="width: 100%" align="center"> <table> <tr> <th colspan="3">Map Components with User Type</th> </tr> <tr> <td class="td_text"> <label for="ut">User Type:</label></td> <td> @{ if (ViewData["PermissionType"] != null) { List<componentusertypemapping> perUserTypelst = new List<componentusertypemapping>(); ComponentUserTypeMapping perUserType = new ComponentUserTypeMapping(); perUserType.PermissionList = new List<SelectListItem>(); int PTypeID = 0; foreach (var item in Listclass.GetPermissionList(PTypeID)) { perUserType.PermissionList.Add(new SelectListItem() { Text = item.PType, Value = item.PTypeID.ToString() }); } perUserTypelst.Add(perUserType); foreach (var item in perUserTypelst) { if (item.PermissionList != null && item.PermissionList.Count > 0) { @Html.DropDownListFor(modelItem => item.PTypeID, item.PermissionList, "--Select Permission--") } else { <select name="PTypeID"> <option value="0">--select--</option> </select> } } } else { foreach (var item in Model) { if (item.PermissionList != null && item.PermissionList.Count > 0) { @Html.DropDownListFor(modelItem => item.PTypeID, item.PermissionList, "--Select Permission--") } else { <select name="PTypeID"> <option value="0">--select--</option> </select> } } } } </componentusertypemapping></componentusertypemapping></td> </tr> </table> <br /> <table id="grdUsers" style="width: 100%"> <tr> <th>Sno.</th> <th>Component Name</th> <th>Module Name</th> <th>Select All<input type="checkbox" id="selectAll" onclick="SelectAllCheckboxes(this, 'grdUsers')" /></th> </tr> @{ int i = 1; foreach (var item in Model) { if (Convert.ToInt32(item.Selvalue) > 0 && item.Selvalue != null) { <tr> <td>@i</td> <td>@item.ComponentName</td> <td>@item.module_name</td> <td style="text-align: center;"> @* <input type="checkbox" name="chk" id="chk_item.comp_id" value="@item.comp_id" >*@ </td> </tr> i++; } else { <tr> <th colspan="4" style="text-align: center;">No Record Found. </th> </tr> } } <tr> <td colspan="4" style="text-align: center;"> <input type="submit" name="sub" id="sub" value="Proceed" onclick="return confirm('Are you sure to Proceed??')" /> </td> </tr> } </table> </div> </form> </body> </html></roadsafetymvc.models.super.componentusertypemapping></componentmaster></componentusertypemapping></componentusertypemapping></componentusertypemapping></componentusertypemapping>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)