public static string DeleteUserRole(string record_id, string user_id, string RequestID) { //Security Check if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "delete")) { throw new Exception("No Access."); } LINQ_SystemDataContext dc = new LINQ_SystemDataContext(); SYS_UserRole the_record = (from c in dc.SYS_UserRoles where c.RoleID == record_id && c.Active == true select c).FirstOrDefault(); if (the_record == null) { return("Error~We can't find"); } the_record.Active = false; the_record.ModifiedOn = DateTime.Now; the_record.ModifiedBy = user_id; the_record.LastAction = Guid.NewGuid().ToString(); dc.SubmitChanges(); return("Success~"); }
public static string SaveUserRole(string record_id, string user_id, string role_name, string role_code, string menulist, string RequestID) { try { LINQ_SystemDataContext dc = new LINQ_SystemDataContext(); SYS_UserRole the_record = new SYS_UserRole(); if (record_id == "" || record_id == null) { the_record = (from c in dc.SYS_UserRoles where c.RoleCode == role_code && c.Active == true select c).FirstOrDefault(); if (the_record == null) { //Security Check if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "create")) { throw new Exception("No Access."); } the_record = new SYS_UserRole() { CreatedBy = user_id, CreatedOn = DateTime.Now, Active = true, RoleID = Guid.NewGuid().ToString(), RoleMenu = "", LastAction = Guid.NewGuid().ToString() }; dc.SYS_UserRoles.InsertOnSubmit(the_record); } else { return("Error~Duplicate Country Code"); } } else { //Security Check if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "update")) { throw new Exception("No Access."); } the_record = (from c in dc.SYS_UserRoles where c.RoleID == record_id select c).FirstOrDefault(); if (the_record == null) { throw new Exception("System cannot find the record"); } } the_record.ModifiedBy = user_id; the_record.ModifiedOn = DateTime.Now; the_record.LastAction = Guid.NewGuid().ToString(); the_record.RoleName = role_name; the_record.RoleCode = role_code; #region Clear old menu List <SYS_UserRoleMenu> old_menu = (from c in dc.SYS_UserRoleMenus where c.RoleID == the_record.RoleID select c).ToList(); dc.SYS_UserRoleMenus.DeleteAllOnSubmit(old_menu); #endregion if (menulist != "") { List <SYS_UserRoleMenu> new_child_menu = new List <SYS_UserRoleMenu>(); List <SYS_UserRoleMenu> new_node_menu = new List <SYS_UserRoleMenu>(); List <string> node_menu = new List <string>(); List <string> menus = menulist.Split(',').ToList(); //ids foreach (string menu in menus) { if (menu != "") { string node_id = (from c in dc.SYS_UserRoleMenuViews where c.MenuID == menu select c.NoteMenuID).FirstOrDefault(); if (!node_menu.Contains(node_id)) { node_menu.Add(node_id); } #region childNode bool is_node = (from c in dc.SYS_Menus where c.MenuID == menu select c.IsNode).FirstOrDefault(); if (!is_node) { new_child_menu.Add(new SYS_UserRoleMenu() { RoleMenuID = Guid.NewGuid().ToString(), RoleID = the_record.RoleID, MenuID = menu, }); } #endregion } } dc.SYS_UserRoleMenus.InsertAllOnSubmit(new_child_menu); dc.SubmitChanges(); #region parentNode foreach (string menu in node_menu) { if (menu != "" && menu != null) { new_node_menu.Add(new SYS_UserRoleMenu() { RoleMenuID = Guid.NewGuid().ToString(), RoleID = the_record.RoleID, MenuID = menu, }); } } dc.SYS_UserRoleMenus.InsertAllOnSubmit(new_node_menu); #endregion } dc.SubmitChanges(); return("Success~" + the_record.RoleID); } catch (Exception ex) { return("Error~" + ex.Message); } }