public ActionResult EditPOST(int id, ProjectionEditViewModel viewModel, string picklist, string returnUrl) { var pickArray = picklist.Split(new[] { '$' }, StringSplitOptions.RemoveEmptyEntries); _projectionService.EditPost(id, viewModel, pickArray); return(Json(new { id = id })); }
public ProjectionEditViewModel GetProjectionViewModel(int id) { var viewModel = new ProjectionEditViewModel(); //Get Projection&QueryPart var projectionItem = _contentManager.Get(id, VersionOptions.Latest); var projectionPart = projectionItem.As <ProjectionPart>(); var queryId = projectionPart.Record.QueryPartRecord.Id; var queryPart = _contentManager.Get <QueryPart>(queryId, VersionOptions.Latest); var listViewPart = projectionItem.As <ListViewPart>(); viewModel.Id = id; viewModel.ItemContentType = listViewPart.ItemContentType; viewModel.DisplayName = listViewPart.As <TitlePart>().Title; viewModel.VisableTo = listViewPart.VisableTo; viewModel.PageRowCount = projectionPart.Record.ItemsPerPage; viewModel.IsDefault = listViewPart.IsDefault; //Get AllFields viewModel.Fields = GetFieldDescriptors(listViewPart.ItemContentType); var sortCriterion = queryPart.SortCriteria.FirstOrDefault(); if (sortCriterion != null) { var state = FormParametersHelper.ToDynamic(sortCriterion.State); viewModel.SortedBy = state.Type; var ascending = (bool)state.Sort; viewModel.SortMode = ascending ? "Asc" : "Desc"; } return(viewModel); }
public ActionResult Edit(int id) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit queries"))) { return(new HttpUnauthorizedResult()); } ProjectionEditViewModel viewModel = _projectionService.GetProjectionViewModel(id); return(View(viewModel)); }
public void OnCreated(string entityName) { var fields = _projectionService.GetFieldDescriptors(entityName).Select(x => x.Type); var viewModel = new ProjectionEditViewModel { ItemContentType = entityName, DisplayName = entityName + " DefaultView", PageRowCount = 50, IsDefault = true }; _projectionService.EditPost(0, viewModel, fields); }
public ActionResult Create(string id) { var pluralService = PluralizationService.CreateService(new CultureInfo("en-US")); if (pluralService.IsPlural(id)) { id = pluralService.Singularize(id); } if (!_contentMetadataService.CheckEntityPublished(id)) { return(Content(T("The \"{0}\" hasn't been published!", id).Text)); } var viewModel = new ProjectionEditViewModel { ItemContentType = id, DisplayName = string.Empty, Fields = _projectionService.GetFieldDescriptors(id) }; return(View("Edit", viewModel)); }
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); }