protected SortCriterionRecord CreateSortRecord(string category, string type, string state, QueryPartRecord queryPartRecord) { SortCriterionRecord sortRecord = new SortCriterionRecord(); sortRecord.Category = category; sortRecord.Type = type; sortRecord.State = state; sortRecord.QueryPartRecord = queryPartRecord; queryPartRecord.SortCriteria.Add(sortRecord); sortRecord.Position = 0; this.sortRepository.Create(sortRecord); return(sortRecord); }
public ActionResult EditPost(int id, string category, string type, [DefaultValue(-1)] int sortCriterionId, FormCollection formCollection) { var query = _queryService.GetQuery(id); var sortCriterion = _projectionManager.DescribeSortCriteria().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == category && x.Type == type); var model = new SortCriterionEditViewModel(); TryUpdateModel(model); // validating form values _formManager.Validate(new ValidatingContext { FormName = sortCriterion.Form, ModelState = ModelState, ValueProvider = ValueProvider }); if (ModelState.IsValid) { var sortCriterionRecord = query.SortCriteria.FirstOrDefault(f => f.Id == sortCriterionId); // add new sort criteria record if it's a newly created one if (sortCriterionRecord == null) { sortCriterionRecord = new SortCriterionRecord { Category = category, Type = type, Position = query.SortCriteria.Count }; query.SortCriteria.Add(sortCriterionRecord); } var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get); // save form parameters sortCriterionRecord.State = FormParametersHelper.ToString(dictionary); sortCriterionRecord.Description = model.Description; return(RedirectToAction("Edit", "Admin", new { id })); } // model is invalid, display it again var form = _formManager.Build(sortCriterion.Form); _formManager.Bind(form, formCollection); var viewModel = new SortCriterionEditViewModel { Id = id, Description = model.Description, SortCriterion = sortCriterion, Form = form }; return(View(viewModel)); }
private static void SortStaffProfileQuery(QueryPart staffProfileQuery) { var sortDictionary = new Dictionary <string, string>(); sortDictionary.Add("Description", "Staff Group"); sortDictionary.Add("Sort", "false"); //sort by name var profileNameCriteria = staffProfileQuery.SortCriteria.FirstOrDefault(); if (profileNameCriteria == null) { profileNameCriteria = new SortCriterionRecord { Category = "TitlePartRecord", Type = "Title", Description = "Profile Name", Position = 1 }; } profileNameCriteria.State = FormParametersHelper.ToString(sortDictionary); staffProfileQuery.SortCriteria.Add(profileNameCriteria); }
public int EditPost(int id, ProjectionEditViewModel viewModel, IEnumerable <string> pickedFileds) { ListViewPart listViewPart; ProjectionPart projectionPart; QueryPart queryPart; if (id == 0) { listViewPart = _contentManager.New <ListViewPart>("ListViewPage"); listViewPart.ItemContentType = viewModel.ItemContentType; queryPart = _contentManager.New <QueryPart>("Query"); var layout = new LayoutRecord { Category = "Html", Type = "ngGrid", Description = "DefaultLayoutFor" + queryPart.Name, Display = 1 }; queryPart.Layouts.Add(layout); projectionPart = listViewPart.As <ProjectionPart>(); projectionPart.Record.LayoutRecord = layout; projectionPart.Record.QueryPartRecord = queryPart.Record; var filterGroup = new FilterGroupRecord(); queryPart.Record.FilterGroups.Add(filterGroup); var filterRecord = new FilterRecord { Category = "Content", Type = "ContentTypes", Position = filterGroup.Filters.Count, State = GetContentTypeFilterState(viewModel.ItemContentType) }; filterGroup.Filters.Add(filterRecord); _contentManager.Create(queryPart.ContentItem); _contentManager.Create(projectionPart.ContentItem); } else { listViewPart = _contentManager.Get <ListViewPart>(id, VersionOptions.Latest); projectionPart = listViewPart.As <ProjectionPart>(); var queryId = projectionPart.Record.QueryPartRecord.Id; queryPart = _contentManager.Get <QueryPart>(queryId, VersionOptions.Latest); } if (pickedFileds == null) { pickedFileds = new List <string>(); } listViewPart.VisableTo = viewModel.VisableTo; listViewPart.As <TitlePart>().Title = viewModel.DisplayName; listViewPart.IsDefault = viewModel.IsDefault; queryPart.Name = "Query for Public View"; projectionPart.Record.ItemsPerPage = viewModel.PageRowCount; //Post Selected Fields var layoutRecord = projectionPart.Record.LayoutRecord; layoutRecord.Properties.Clear(); var category = viewModel.ItemContentType + "ContentFields"; const string settingName = "CoeveryTextFieldSettings.IsDispalyField"; try { UpdateLayoutProperties(viewModel.ItemContentType, ref layoutRecord, category, settingName, pickedFileds); } catch (Exception exception) { Services.Notifier.Add(NotifyType.Error, T(exception.Message)); } layoutRecord.State = GetLayoutState(queryPart.Id, layoutRecord.Properties.Count, layoutRecord.Description); // sort queryPart.SortCriteria.Clear(); if (!string.IsNullOrEmpty(viewModel.SortedBy)) { var sortCriterionRecord = new SortCriterionRecord { Category = category, Type = viewModel.SortedBy, Position = queryPart.SortCriteria.Count, State = GetSortState(viewModel.SortedBy, viewModel.SortMode), Description = viewModel.SortedBy + " " + viewModel.SortMode }; queryPart.SortCriteria.Add(sortCriterionRecord); } return(listViewPart.Id); }