/// <summary> /// Perform the search of catalogues in the pagination buttons /// </summary> /// <param name="sortedColumn">Sorted column</param> /// <param name="page">Selected Page</param> /// <param name="sortDirection">Sort direction</param> /// <returns>PartialViewResult</returns> public PartialViewResult SearchCatalogueListPaginated(SortDirection? sortDirection, string sortedColumn, int? page) { int pageSize = Cotecna.Vestalis.Web.Properties.Settings.Default.PageSize; Guid? businessApplicationId = Session["catalogueBusinessApplicationId"] as Guid?; PaginatedList<CatalogueModel> model = new PaginatedList<CatalogueModel>(); ParameterSearchCatalogues parameters = new ParameterSearchCatalogues() { BusinessApplicationId = businessApplicationId.GetValueOrDefault(), PageSize = pageSize, SortDirection = sortDirection.GetValueOrDefault(), SortedColumn = sortedColumn, SelectedPage = page.GetValueOrDefault(), UserName = UserName }; model = CatalogueBusiness.SearchCategoryCatalogue(parameters); return PartialView("_CatalogueGrid", model); }
/// <summary> /// Perform the search of catalogues /// </summary> /// <param name="page">Selected page</param> /// <param name="businessApplicationId">Id of business application</param> /// <returns>PartialViewResult</returns> public PartialViewResult SearchCatalogueList(int? page, Guid? businessApplicationId) { int pageSize = Cotecna.Vestalis.Web.Properties.Settings.Default.PageSize; PaginatedList<CatalogueModel> model = new PaginatedList<CatalogueModel>(); ParameterSearchCatalogues parameters = new ParameterSearchCatalogues() { BusinessApplicationId = businessApplicationId.GetValueOrDefault(), PageSize = pageSize, SortDirection = SortDirection.Ascending, SortedColumn = "BusinessApplicationName", SelectedPage = page.GetValueOrDefault(), UserName = UserName }; model = CatalogueBusiness.SearchCategoryCatalogue(parameters); Session.Add("catalogueBusinessApplicationId", businessApplicationId); return PartialView("_CatalogueGrid", model); }
/// <summary> /// Retrieve the list of catalogues for exporting to excel /// </summary> /// <param name="businessAppId">Id of business application</param> public void SearchCatalogueCategoriesExcel(Guid? businessAppId) { PaginatedList<CatalogueModel> model = new PaginatedList<CatalogueModel>(); ParameterSearchCatalogues parameters = new ParameterSearchCatalogues() { BusinessApplicationId = businessAppId.GetValueOrDefault(), PageSize = 0, SortDirection = SortDirection.Ascending, SortedColumn = "BusinessApplicationName", SelectedPage = 0, IsExport = true, UserName = UserName }; model = CatalogueBusiness.SearchCategoryCatalogue(parameters); Session.Add("SearchCatalogueCategoriesExcel", model); }
/// <summary> /// Retrieve the list of catalogues by business application id /// </summary> /// <param name="parameters">Search parameters</param> /// <param name="temResult">Result</param> /// <param name="currentIndex">Current page index</param> /// <param name="countElements">Total elements</param> /// <param name="context">Database context</param> private static void GetCataloguesByBusinessAppId(ParameterSearchCatalogues parameters, ref List<CatalogueModel> temResult, int currentIndex, ref int countElements, VestalisEntities context) { countElements = (from catalogue in context.Catalogues where catalogue.IsDeleted == false && catalogue.BusinessApplicationId == parameters.BusinessApplicationId select catalogue).Count(); var filterTemResult = (from catalogue in context.Catalogues.Include("BusinessApplication") where catalogue.IsDeleted == false && catalogue.BusinessApplicationId == parameters.BusinessApplicationId orderby catalogue.CatalogueCategoryName select new CatalogueModel { BusinessApplicationName = catalogue.BusinessApplication.BusinessApplicationName, CatalogueId = catalogue.CatalogueId, CatalogueCategoryName = catalogue.CatalogueCategoryName }); if (parameters.IsExport) { //order the result temResult = (parameters.SortDirection == SortDirection.Ascending ? filterTemResult.OrderBy(ExtensionMethods.GetField<CatalogueModel>(parameters.SortedColumn)) : filterTemResult.OrderByDescending(ExtensionMethods.GetField<CatalogueModel>(parameters.SortedColumn))).ToList(); } else { //order the result temResult = (parameters.SortDirection == SortDirection.Ascending ? filterTemResult.OrderBy(ExtensionMethods.GetField<CatalogueModel>(parameters.SortedColumn)) : filterTemResult.OrderByDescending(ExtensionMethods.GetField<CatalogueModel>(parameters.SortedColumn))) .Skip(currentIndex).Take(parameters.PageSize).ToList(); } }
/// <summary> /// Retrieve the list of catalogues for all business applications /// </summary> /// <param name="parameters">Search parameters</param> /// <param name="temResult">Result</param> /// <param name="currentIndex">Current page index</param> /// <param name="countElements">Total elements</param> /// <param name="context">Database context</param> private static void GetAllCataloguesGlobalAdmin(ParameterSearchCatalogues parameters, ref List<CatalogueModel> temResult, int currentIndex, ref int countElements, VestalisEntities context) { var tempQueryResults = (from catalogue in context.Catalogues.Include("BusinessApplication") where catalogue.IsDeleted == false select new CatalogueModel { BusinessApplicationName = catalogue.BusinessApplication.BusinessApplicationName, CatalogueId = catalogue.CatalogueId, CatalogueCategoryName = catalogue.CatalogueCategoryName }).ToList(); var groupResults = (from resultTemp in tempQueryResults group resultTemp by resultTemp.BusinessApplicationName into resultGroup select resultGroup); foreach (var item in groupResults.OrderBy(data => data.Key).AsEnumerable()) { temResult.AddRange(item.OrderBy(data => data.CatalogueCategoryName).AsEnumerable()); } countElements = temResult.Count; temResult = (parameters.SortDirection == SortDirection.Ascending ? temResult.OrderBy(ExtensionMethods.GetField<CatalogueModel>(parameters.SortedColumn)) : temResult.OrderByDescending(ExtensionMethods.GetField<CatalogueModel>(parameters.SortedColumn))).ToList(); if (!parameters.IsExport) temResult = temResult.Skip(currentIndex).Take(parameters.PageSize).ToList(); }
/// <summary> /// Retrieve the list of catalogues by business application /// </summary> /// <param name="parameters">Parameters</param> /// <returns>List of Catalogue</returns> public static PaginatedList<CatalogueModel> SearchCategoryCatalogue(ParameterSearchCatalogues parameters) { PaginatedList<CatalogueModel> finalResult = new PaginatedList<CatalogueModel>(); List<CatalogueModel> temResult = new List<CatalogueModel>(); int currentIndex = (parameters.SelectedPage - 1) * parameters.PageSize; int countElements = 0; using (VestalisEntities context = new VestalisEntities()) { //if the user doesn't select any business application, the system will retrieve the completed list of catalogues //otherwise the system will retrieve the list of catalogues filtered by business application if (parameters.BusinessApplicationId != Guid.Empty) { GetCataloguesByBusinessAppId(parameters, ref temResult, currentIndex, ref countElements, context); } else { if (Roles.IsUserInRole(parameters.UserName, "GlobalAdministrator")) { GetAllCataloguesGlobalAdmin(parameters, ref temResult, currentIndex, ref countElements, context); } else { List<BusinessApplicationByUser> businessAplicationsByUser = AuthorizationBusiness.GetBusinessApplicationsByUser(parameters.UserName); string[] roles = Roles.GetRolesForUser(parameters.UserName); List<Guid?> businessAppsIds = new List<Guid?>(); foreach (var item in businessAplicationsByUser) { string localAdminRoles = string.Format("ApplicationAdministrator_{0}", item.Prefix); if (roles.Contains(localAdminRoles)) businessAppsIds.Add(item.Id); } GetCataloguesByBusinessAppId(parameters, businessAppsIds, ref temResult, currentIndex, ref countElements, context); } } //if exists results, the system makes the pagination if (temResult != null) { finalResult.SortDirection = parameters.SortDirection; finalResult.SortedColumn = parameters.SortedColumn; //set the paginated colletion finalResult.Collection = temResult; //set the quantity of elements without pagination finalResult.TotalCount = countElements; //set the number of pages finalResult.NumberOfPages = (int)Math.Ceiling((double)finalResult.TotalCount / (double)parameters.PageSize); //set the current page finalResult.Page = parameters.SelectedPage; //set the page size finalResult.PageSize = parameters.PageSize; } } return finalResult; }