public static UserPermissionsModel GetUserPermissionModel(Guid guid, int moduleId) { var userPermissionList = new UserPermissionsEntities().UserPermissions. AsQueryable().Where(x => x.user_id == guid).ToList(); if (moduleId == 0) { userPermissionList = userPermissionList.Where(x => x.item_id == 0).ToList(); } else { userPermissionList = userPermissionList.Where(x => x.module_id == moduleId && x.item_id != 0).ToList(); } // Dictionary <int, string> dict = new Dictionary <int, string>(); foreach (ModuleTypes item in Enum.GetValues(typeof(ModuleTypes))) { var text = string.Format("{0}", Home.TranslateWord.GetWord(item.ToString())); dict.Add((int)item, text); } var userPermissionModel = new UserPermissionsModel { ModuleList = dict, UserPermissionList = userPermissionList, ItemList = GetItemList(moduleId) }; return(userPermissionModel); }
public static List <int> GetModuleItemIds(ModuleTypes moduleType) { var result = new UserPermissionsEntities().UserPermissions.AsQueryable() .Where(x => x.user_id == new Guid(MySession.Current.UserGuid) && x.module_id == (int)moduleType && x.item_id != 0).AsEnumerable() .Select(x => x.item_id).ToList(); return(result); }
private static void SetDatabasePermissions() { var userPermissionList = new UserPermissionsEntities().UserPermissions. AsQueryable().Where(x => x.user_id == new Guid(MySession.Current.UserGuid)).ToList(); foreach (var item in userPermissionList) { var userPermission = MySession.Current.UserPermisionList .FirstOrDefault(x => x.module_id == item.module_id); if (userPermission != null) { userPermission.can_view = item.can_view; userPermission.can_edit = item.can_edit; userPermission.can_delete = item.can_delete; userPermission.can_add = item.can_add; } } }