public ConsoleResultModel Run() { var tab = PortalSettings.ActiveTab; List <ModuleInfoModel> lst = null; if (Deleted.HasValue) { // If deleted is true, then user wants modules from recycle bin // Since we're dealing with module instance models rather than module info models, // don't follwo the normal output flow. var newList = GetDeletedModules(PortalId, (bool)Deleted, ModuleName, ModuleTitle); return(new ConsoleResultModel(string.Format("{0} module{1} found", newList.Count, (newList.Count != 1 ? "s" : string.Empty))) { data = newList }); } else if (All) { // if --all passed then, since it gets all modules in the portal, that takes precendence lst = GetModulesInPortal(ModuleName); } else if (ModuleId.HasValue) { lst = GetModuleById(); } else { lst = GetModulesOnPage((int)PageId, ModuleName); } if (lst.Count > 0) { if (!string.IsNullOrEmpty(ModuleTitle)) { var lstFiltered = from o in lst where o.Title.ToLowerInvariant().Contains(ModuleTitle.ToLowerInvariant()) select o; lst = lstFiltered.ToList(); } } // ensure an empty value is passed back if (lst == null) { lst = new List <ModuleInfoModel>(); } return(new ConsoleResultModel(string.Format("{0} module{1} found", lst.Count, (lst.Count != 1 ? "s" : string.Empty))) { data = lst }); }
public override IConsoleResultModel Run() { var max = Max <= 0 ? 10 : (Max > 500 ? 500 : Max); int total; var portalDesktopModules = DesktopModuleController.GetPortalDesktopModules(PortalId); var pageIndex = (Page > 0 ? Page - 1 : 0); pageIndex = pageIndex < 0 ? 0 : pageIndex; var pageSize = Max; pageSize = pageSize > 0 && pageSize <= 100 ? pageSize : 10; ModuleName = ModuleName?.Replace("*", ""); ModuleTitle = ModuleTitle?.Replace("*", ""); var modules = ModuleController.Instance.GetModules(PortalSettings.PortalId) .Cast <ModuleInfo>().Where(ModulePermissionController.CanViewModule); if (!string.IsNullOrEmpty(ModuleName)) { modules = modules.Where(module => module.DesktopModule.ModuleName.IndexOf(ModuleName, StringComparison.OrdinalIgnoreCase) >= 0); } if (!string.IsNullOrEmpty(ModuleTitle)) { modules = modules.Where(module => module.ModuleTitle.IndexOf(ModuleTitle, StringComparison.OrdinalIgnoreCase) >= 0); } //Return only deleted modules with matching criteria. if (PageId.HasValue && PageId.Value > 0) { modules = modules.Where(x => x.TabID == PageId.Value); } if (Deleted.HasValue) { modules = modules.Where(module => module.IsDeleted == Deleted); } //Get distincts. modules = modules.GroupBy(x => x.ModuleID).Select(group => group.First()).OrderBy(x => x.ModuleID); var moduleInfos = modules as IList <ModuleInfo> ?? modules.ToList(); total = moduleInfos.Count; modules = moduleInfos.Skip(pageIndex * pageSize).Take(pageSize) .Where(m => { var moduleDefinition = ModuleDefinitionController.GetModuleDefinitionByID(m.ModuleDefID); return(portalDesktopModules.Any(kvp => kvp.Value.DesktopModuleID == moduleDefinition?.DesktopModuleID)); }); var results = modules.Select(x => PromptModuleInfo.FromDnnModuleInfo(x, Deleted)); var totalPages = total / max + (total % max == 0 ? 0 : 1); var pageNo = Page > 0 ? Page : 1; return(new ConsoleResultModel { Data = results, PagingInfo = new PagingInfo { PageNo = pageNo, TotalPages = totalPages, TotalRecords = total, PageSize = max }, Records = results.Count(), Output = results.Count() == 0 ? LocalizeString("Prompt_NoModules") : "" }); }