protected override DriverResult Editor(ProjectionPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            var model = new ProjectionPartEditViewModel();

            if (updater.TryUpdateModel(model, Prefix, null, null))
            {
                var queryLayoutIds = model.QueryLayoutRecordId.Split(new[] { ';' });

                part.Record.DisplayPager    = model.DisplayPager;
                part.Record.Items           = model.Items;
                part.Record.ItemsPerPage    = model.ItemsPerPage;
                part.Record.Skip            = model.Skip;
                part.Record.MaxItems        = model.MaxItems;
                part.Record.PagerSuffix     = (model.PagerSuffix ?? String.Empty).Trim();
                part.Record.QueryPartRecord = _queryRepository.Get(Int32.Parse(queryLayoutIds[0]));
                part.Record.LayoutRecord    = part.Record.QueryPartRecord.Layouts.FirstOrDefault(x => x.Id == Int32.Parse(queryLayoutIds[1]));

                if (!String.IsNullOrWhiteSpace(part.Record.PagerSuffix) && !String.Equals(part.Record.PagerSuffix.ToSafeName(), part.Record.PagerSuffix, StringComparison.OrdinalIgnoreCase))
                {
                    updater.AddModelError("PagerSuffix", T("Suffix should not contain special characters."));
                }
            }

            return(Editor(part, shapeHelper));
        }
示例#2
0
        protected override DriverResult Editor(ProjectionWithDynamicSortPart part, dynamic shapeHelper)
        {
            return(ContentShape("Parts_ProjectionPart_Edit",
                                () =>
            {
                var model = new ProjectionPartEditViewModel
                {
                    DisplayPager = part.Record.DisplayPager,
                    Items = part.Record.Items,
                    ItemsPerPage = part.Record.ItemsPerPage,
                    Skip = part.Record.Skip,
                    PagerSuffix = part.Record.PagerSuffix,
                    MaxItems = part.Record.MaxItems,
                    QueryLayoutRecordId = "-1",
                };

                // concatenated Query and Layout ids for the view
                if (part.Record.QueryPartRecord != null)
                {
                    model.QueryLayoutRecordId = part.Record.QueryPartRecord.Id + ";";
                }

                if (part.Record.LayoutRecord != null)
                {
                    model.QueryLayoutRecordId += part.Record.LayoutRecord.Id.ToString();
                }
                else
                {
                    model.QueryLayoutRecordId += "-1";
                }

                // populating the list of queries and layouts
                var layouts = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).ToList();
                model.QueryRecordEntries = Services.ContentManager.Query <QueryPart>().Join <TitlePartRecord>().OrderBy(x => x.Title).List()
                                           .Select(x => new QueryRecordEntry
                {
                    Id = x.Id,
                    Name = x.Name,
                    LayoutRecordEntries = x.Layouts.Select(l => new LayoutRecordEntry
                    {
                        Id = l.Id,
                        Description = GetLayoutDescription(layouts, l)
                    })
                });


                return shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix);
            }));
        }
        protected override DriverResult Editor(DynamicProjectionPart part, dynamic shapeHelper)
        {
            // todo: we need a 'ManageAdminMenu' too?
            //if (!_authorizationService.TryCheckAccess(DynamicProjectionPermission.ManageContentMenus, _orchardServices.WorkContext.CurrentUser, part)) {
            //    return null;
            //}

            if (string.IsNullOrEmpty(part.AdminMenuPosition))
            {
                part.AdminMenuPosition = "2"; // GetDefaultPosition(part);
            }
            var model = new ProjectionPartEditViewModel {
                DisplayPager        = part.Record.DisplayPager,
                Items               = part.Record.Items,
                ItemsPerPage        = part.Record.ItemsPerPage,
                Skip                = part.Record.Skip,
                PagerSuffix         = part.Record.PagerSuffix,
                MaxItems            = part.Record.MaxItems,
                QueryLayoutRecordId = "-1",
            };

            // concatenated Query and Layout ids for the view
            if (part.Record.QueryPartRecord != null)
            {
                model.QueryLayoutRecordId = part.Record.QueryPartRecord.Id + ";";
            }

            if (part.Record.LayoutRecord != null)
            {
                model.QueryLayoutRecordId += part.Record.LayoutRecord.Id.ToString();
            }
            else
            {
                model.QueryLayoutRecordId += "-1";
            }

            // populating the list of queries and layouts
            var layouts = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).ToList();

            model.QueryRecordEntries = _orchardServices.ContentManager.Query <QueryPart, QueryPartRecord>().Join <TitlePartRecord>().OrderBy(x => x.Title).List()
                                       .Select(x => new QueryRecordEntry {
                Id   = x.Id,
                Name = x.Name,
                LayoutRecordEntries = x.Layouts.Select(l => new LayoutRecordEntry {
                    Id          = l.Id,
                    Description = GetLayoutDescription(layouts, l)
                })
            });
            var partvm = new DynamicProjectionPartVM();

            Mapper.Initialize(cfg => {
                cfg.CreateMap <DynamicProjectionPart, DynamicProjectionPartVM>();
            });
            Mapper.Map <DynamicProjectionPart, DynamicProjectionPartVM>(part, partvm);
            var newmodel = new DynamicProjectionVM {
                Projection = model,
                Part       = partvm,
                //  FormFile =part.FormFile,
                Tenant = _shellSettings.Name
            };

            return(ContentShape("Parts_Navigation_DynamicProjection_Edit",
                                () => shapeHelper.EditorTemplate(TemplateName: "Parts.Navigation.DynamicProjection.Edit", Model: newmodel, Prefix: Prefix)));
        }