protected override DriverResult Editor(DynamicProjectionPart part, IUpdateModel updater, dynamic shapeHelper) { //if (!_authorizationService.TryCheckAccess(DynamicProjectionPermission.ManageContentMenus, _orchardServices.WorkContext.CurrentUser, part)) // return null; var newmodel = new DynamicProjectionVM(); updater.TryUpdateModel(newmodel, Prefix, null, null); if (newmodel.Part.OnAdminMenu) { if (string.IsNullOrEmpty(newmodel.Part.AdminMenuText)) { updater.AddModelError("AdminMenuText", T("The AdminMenuText field is required")); } if (string.IsNullOrEmpty(newmodel.Part.AdminMenuPosition)) { newmodel.Part.AdminMenuPosition = "2";// GetDefaultPosition(part); } } else { newmodel.Part.AdminMenuPosition = ""; } Mapper.Initialize(cfg => { cfg.CreateMap <DynamicProjectionPartVM, DynamicProjectionPart>(); }); Mapper.Map <DynamicProjectionPartVM, DynamicProjectionPart>(newmodel.Part, part); // part.FormFile = newmodel.FormFile; // projection var model = newmodel.Projection; 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(); if (model.QueryLayoutRecordId != null) { var queryLayoutIds = model.QueryLayoutRecordId.Split(new[] { ';' }); 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)); }
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 ViewModels.DynamicProjectionPartEditViewModel { 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))); }