public ActionResult Add(int id) { if (!Services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to manage queries"))) { return(new HttpUnauthorizedResult()); } var viewModel = new SortCriterionAddViewModel { Id = id, SortCriteria = _projectionManager.DescribeSortCriteria() }; return(View(viewModel)); }
public ActionResult Edit(int id) { if (!Services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to edit queries"))) { return(new HttpUnauthorizedResult()); } var query = _queryService.GetQuery(id); var viewModel = new AdminEditViewModel { Id = query.Id, Name = query.Name }; #region Load Filters var filterGroupEntries = new List <FilterGroupEntry>(); var allFilters = _projectionManager.DescribeFilters().SelectMany(x => x.Descriptors).ToList(); foreach (var group in query.FilterGroups) { var filterEntries = new List <FilterEntry>(); foreach (var filter in group.Filters) { var category = filter.Category; var type = filter.Type; var f = allFilters.FirstOrDefault(x => category == x.Category && type == x.Type); if (f != null) { filterEntries.Add( new FilterEntry { Category = f.Category, Type = f.Type, FilterRecordId = filter.Id, DisplayText = String.IsNullOrWhiteSpace(filter.Description) ? f.Display(new FilterContext { State = FormParametersHelper.ToDynamic(filter.State) }).Text : filter.Description }); } } filterGroupEntries.Add(new FilterGroupEntry { Id = group.Id, Filters = filterEntries }); } viewModel.FilterGroups = filterGroupEntries; #endregion #region Load Sort criterias var sortCriterionEntries = new List <SortCriterionEntry>(); var allSortCriteria = _projectionManager.DescribeSortCriteria().SelectMany(x => x.Descriptors).ToList(); foreach (var sortCriterion in query.SortCriteria.OrderBy(s => s.Position)) { var category = sortCriterion.Category; var type = sortCriterion.Type; var f = allSortCriteria.FirstOrDefault(x => category == x.Category && type == x.Type); if (f != null) { sortCriterionEntries.Add( new SortCriterionEntry { Category = f.Category, Type = f.Type, SortCriterionRecordId = sortCriterion.Id, DisplayText = String.IsNullOrWhiteSpace(sortCriterion.Description) ? f.Display(new SortCriterionContext { State = FormParametersHelper.ToDynamic(sortCriterion.State) }).Text : sortCriterion.Description }); } } viewModel.SortCriteria = sortCriterionEntries; #endregion #region Load Layouts var layoutEntries = new List <LayoutEntry>(); var allLayouts = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).ToList(); foreach (var layout in query.Layouts) { var category = layout.Category; var type = layout.Type; var f = allLayouts.FirstOrDefault(x => category == x.Category && type == x.Type); if (f != null) { layoutEntries.Add( new LayoutEntry { Category = f.Category, Type = f.Type, LayoutRecordId = layout.Id, DisplayText = String.IsNullOrWhiteSpace(layout.Description) ? f.Display(new LayoutContext { State = FormParametersHelper.ToDynamic(layout.State) }).Text : layout.Description }); } } viewModel.Layouts = layoutEntries; #endregion return(View(viewModel)); }