コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: ProjectionService.cs プロジェクト: wezmag/Coevery
        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;
        }
コード例 #3
0
        public void EditPost(int id, ProjectionEditViewModel viewModel, IEnumerable<string> pickedFileds) {
            if (pickedFileds == null) {
                pickedFileds = new List<string>();
            }
            var projectionPart = _contentManager.Get<ProjectionPart>(id, VersionOptions.Latest);
            var queryId = projectionPart.Record.QueryPartRecord.Id;
            var queryPart = _contentManager.Get<QueryPart>(queryId, VersionOptions.Latest);

            //Post DisplayName
            queryPart.As<TitlePart>().Title = viewModel.DisplayName;

            //Post Selected Fields
            var layoutRecord = projectionPart.Record.LayoutRecord;
            layoutRecord.Properties.Clear();

            string category = viewModel.Name + "ContentFields";
            const string settingName = "CoeveryTextFieldSettings.IsDispalyField";
            var allFields = _contentDefinitionManager.GetPartDefinition(viewModel.Name).Fields.ToList();
            foreach (var property in pickedFileds) {
                var field = allFields.FirstOrDefault(c => c.Name == property);
                if (field == null) {
                    continue;
                }
                var propertyRecord = new PropertyRecord {
                    Category = category,
                    Type = string.Format("{0}.{1}.", viewModel.Name, property),
                    Description = field.DisplayName,
                    Position = layoutRecord.Properties.Count,
                    State = GetPropertyState(property),
                    LinkToContent = field.Settings.ContainsKey(settingName) && bool.Parse(field.Settings[settingName])
                };
                layoutRecord.Properties.Add(propertyRecord);
            }
            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);
            }

            // VisableTo and pageRowCount
            var layoutPropertyRecord = new LayoutPropertyRecord {
                VisableTo = viewModel.VisableTo,
                PageRowCount = viewModel.PageRowCount,
                QueryPartRecord_id = queryPart.Id
            };
            _layoutPropertyService.CreateLayoutProperty(layoutPropertyRecord);
        }
コード例 #4
0
ファイル: Migrations.cs プロジェクト: akhurst/ricealumni
		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);
		}