using FluentValidation; namespace zero.Pages; public class PagesStore : TreeEntityStore, IPagesStore { protected IPageTypeService PageTypes { get; private set; } public PagesStore(IStoreContext context, IPageTypeService pageTypes) : base(context) { PageTypes = pageTypes; } /// public override async Task IsAllowedAsChild(Page model, string parentId) { return true; // TODO v3 this method fails as it is also called on move and update (which should not happen) IEnumerable pageTypes = await PageTypes.GetAllowedTypes(parentId); return pageTypes.Any(x => x.Alias == model.Flavor); } /// public async Task Empty(string pageTypeAlias, string parentId = null) { FlavorConfig type = PageTypes.GetByAlias(pageTypeAlias); if (type == null) { return null; } Page model = await base.Empty(pageTypeAlias); model.ParentId = parentId; if (!await IsAllowedAsChild(model, parentId)) { return null; // TODO we have no way to return an error here :-/ } return model; } /// protected override void ValidationRules(ZeroValidator validator) { validator.RuleFor(x => x.Name).NotEmpty(); validator.RuleFor(x => x.Flavor).NotEmpty(); } } public interface IPagesStore : ITreeEntityStore { /// /// Get new instance of an entity for a specific page type /// Task Empty(string pageType, string parentId = null); }