public int CreateModule(ModuleRPS module) { if (string.IsNullOrEmpty(module.Description)) { module.Description = string.Empty; } string sqlString = "INSERT INTO MODULES " + " (NAME, [DESCRIPTION], LINKURL, PARENTID, SORTID, ISDELETED, CODE, ICON ) " + "VALUES(@Name, @Description, @LinkUrl, @ParentId, @SortId, 0, @Code, @Icon); "; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@Name", module.Name), new SqlParameter("@Description", module.Description), new SqlParameter("@LinkUrl", module.LinkURL), new SqlParameter("@ParentId", module.ParentId), new SqlParameter("@SortId", module.SortId), new SqlParameter("@Code", module.Code), new SqlParameter("@Icon", module.Icon) }; ExecNonQuery(sqlString, param); ////TODO: if SortId is updated, change all sortId for that parent UpdateSortId(module, 0); return(0); }
public int UpdateModule(ModuleRPS module, int oldSortId) { if (string.IsNullOrEmpty(module.Description)) { module.Description = string.Empty; } string sqlString = "UPDATE MODULES SET NAME = @Name, DESCRIPTION = @Description, " + "LINKURL = @LinkUrl, PARENTID = @ParentId, SORTID = @SortId, " + "CODE = @Code, ICON = @Icon " + "WHERE ID = @ModuleID "; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@Name", module.Name), new SqlParameter("@Description", module.Description), new SqlParameter("@LinkUrl", string.IsNullOrEmpty(module.LinkURL) ? string.Empty : module.LinkURL), new SqlParameter("@ParentId", module.ParentId), new SqlParameter("@SortId", module.SortId), new SqlParameter("@Code", module.Code), new SqlParameter("@Icon", module.Icon), new SqlParameter("@ModuleID", module.ID) }; ExecNonQuery(sqlString, param); //TODO: if SortId is updated, change all sortId for that parent UpdateSortId(module, oldSortId); return(0); }
private ModuleRPS BindDataRow(DataRow dr) { ModuleRPS m = new ModuleRPS { ID = Convert.ToInt32(dr["ID"]), Name = dr["Name"].ToString(), Description = dr["Description"].ToString(), LinkURL = dr["LinkURL"].ToString(), ParentId = Convert.ToInt32(dr["ParentId"]), SortId = Convert.ToInt32(dr["SortId"]), Code = dr["CODE"].ToString(), Icon = dr["ICON"].ToString() }; //IsAuthorized is only used in RoleModule try { m.IsAuthorized = Convert.ToInt32(dr["IsAuth"]) > 0 ? true : false; } catch { m.IsAuthorized = true; } //m.Icon = GetRandomCSS(); return(m); }
public ActionResult Filter(ModuleRPS module) { ViewBag.Message = "Updating Parent/Child Pages"; if (module.ID == 0) { return(RedirectToAction("Create", new { parentId = module.ParentId })); } else { return(RedirectToAction("Edit", new { id = module.ID, parentId = module.ParentId })); } }
public ActionResult Create(ModuleRPS module) { string a = ""; if (ModelState.IsValid) { module.Create(); return(RedirectToAction("Index", new { msg = "Created module successfully." })); } ViewBag.ParentList = module.GetParentDropdown(); ViewBag.SortList = module.GetSortDropdown(); return(View(module)); }
public ActionResult Edit(ModuleRPS module, string oldSortId) { if (ModelState.IsValid) { //Save changes module.Update(Convert.ToInt32(oldSortId)); return(RedirectToAction("Index", new { msg = string.Format("Updated {0} Successfully", module.Name) })); } ViewBag.Message = "Failed to update Module"; ViewBag.ParentList = module.GetParentDropdown(); ViewBag.SortList = module.GetSortDropdown(); return(View(module)); }
public RoleModule GetRoleModule(int roleId) { string sqlString = string.Empty; sqlString += "SELECT ID, NAME, ISDEFAULT, ISACTIVE FROM [ROLES] WHERE ID = @RoleId; "; sqlString += "select b.ID, b.[Name], b.DESCRIPTION, b.LINKURL, b.PARENTID, b.SORTID, " + "(select Count(MODULE_ID) from ROLEMODULES WHERE ROLE_ID = @RoleId AND MODULE_ID = b.ID) as IsAuth " + "FROM MODULES b WHERE ISDELETED = 0;"; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@RoleId", roleId) }; DataSet ds = QuerySet(sqlString, param); //table[0] = Role //table[1] = Module RoleModule roleModule = new RoleModule(); if (ds.Tables[0].Rows.Count > 0) { DataRow dr = ds.Tables[0].Rows[0]; RoleRPS rle = new RoleRPS { ID = Convert.ToInt32(dr["ID"]), Name = dr["NAME"].ToString(), IsActive = Convert.ToBoolean(dr["ISACTIVE"]), IsDefault = Convert.ToBoolean(dr["ISDEFAULT"]) }; roleModule.Role = rle; } if (ds.Tables[1].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[1].Rows) { ModuleRPS mod = new ModuleRPS { ID = Convert.ToInt32(dr["id"]), Name = dr["Name"].ToString(), Description = dr["DESCRIPTION"].ToString(), LinkURL = dr["LINKURL"].ToString(), ParentId = Convert.ToInt32(dr["PARENTID"]), SortId = Convert.ToInt32(dr["SORTID"]), IsAuthorized = Convert.ToInt32(dr["IsAuth"]) > 0 ? true : false }; roleModule.Module.Add(mod); } } return(roleModule); }
public ActionResult Create(string parentId) { ModuleRPS module = new ModuleRPS { ID = 0, ParentId = 0 }; if (!string.IsNullOrEmpty(parentId)) { module.ParentId = Convert.ToInt32(parentId); } ViewBag.ParentList = module.GetParentDropdown(); ViewBag.SortList = module.GetSortDropdown(); return(View(module)); }
//For Admin to edit Modules public List <ModuleRPS> GetAllModules() { string sqlString = "SELECT b.ID, NAME, [DESCRIPTION], LINKURL, PARENTID, SORTID, ISDELETED, CODE, ICON " + "FROM [MODULES] b " + "WHERE ISDELETED = 0; "; DataTable dt = QueryTable(sqlString); List <ModuleRPS> list = new List <ModuleRPS>(); if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { ModuleRPS m = BindDataRow(dr); list.Add(m); } } return(list); }
private int UpdateSortId(ModuleRPS module, int oldSortId) { string sqlString = string.Empty; if (oldSortId == 0) { oldSortId = 999; } //Belom Jadi Lagi sqlString = "update Modules set SORTID = SORTID + 1 WHERE PARENTID = @ParentId " + "AND SORTID >= @SortId AND ID != @ModuleId"; SqlParameter[] param1 = new SqlParameter[] { new SqlParameter("@ParentId", module.ParentId), new SqlParameter("@SortId", module.SortId), new SqlParameter("@ModuleId", module.ID) }; return(ExecNonQuery(sqlString, param1)); }
public ActionResult Edit(string id, string parentId) { //kalau takda id, redirect ke index if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Index")); } int idNo = Convert.ToInt32(id); ModuleRPS module = ModuleRPS.GetModule(idNo); //kalau ada parentId dlm querystring, //filter sortId kepada subMenu dlm parent if (!string.IsNullOrEmpty(parentId)) { module.ParentId = Convert.ToInt32(parentId); module.SortId = 0; } ViewBag.ParentList = module.GetParentDropdown(); ViewBag.SortList = module.GetSortDropdown(); return(View(module)); }
public List <ModuleRPS> GetListModules(int roleid) { string sqlString = "SELECT b.ID, NAME, [DESCRIPTION], LINKURL, PARENTID, SORTID, ISDELETED, CODE, ICON " + "FROM [dbo].[ROLEMODULES] a JOIN [MODULES] b ON a.MODULE_ID = b.ID " + "WHERE a.ROLE_ID = @Role_id; "; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@Role_id", roleid) }; DataTable dt = QueryTable(sqlString, param); List <ModuleRPS> list = new List <ModuleRPS>(); if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { ModuleRPS m = BindDataRow(dr); list.Add(m); } } return(list); }