/// <summary>
        /// Processes the model on load.
        /// </summary>
        /// <param name="model">The model</param>
        /// <param name="blog">The blog page the post belongs to</param>
        /// <param name="isDraft">If this is a draft</param>
        private async Task OnLoadAsync(PostBase model, PageInfo blog, bool isDraft = false)
        {
            if (model != null)
            {
                // Format permalink
                model.Permalink = $"/{blog.Slug}/{model.Slug}";

                // Initialize model
                if (typeof(IDynamicModel).IsAssignableFrom(model.GetType()))
                {
                    await _factory.InitDynamicAsync((DynamicPost)model, App.PostTypes.GetById(model.TypeId));
                }
                else
                {
                    await _factory.InitAsync(model, App.PostTypes.GetById(model.TypeId));
                }

                App.Hooks.OnLoad(model);

                // Never cache drafts, dynamic or simple instances
                if (!isDraft && _cache != null && !(model is DynamicPost))
                {
                    if (model is PostInfo)
                    {
                        _cache.Set($"PostInfo_{model.Id.ToString()}", model);
                    }
                    else
                    {
                        _cache.Set(model.Id.ToString(), model);
                    }
                    _cache.Set($"PostId_{model.BlogId}_{model.Slug}", model.Id);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Processes the model on load.
        /// </summary>
        /// <param name="model">The model</param>
        /// <param name="blog">The blog page the post belongs to</param>
        private void OnLoad(PostBase model, PageInfo blog)
        {
            if (model != null)
            {
                // Format permalink
                model.Permalink = $"/{blog.Slug}/{model.Slug}";

                // Initialize model
                if (typeof(IDynamicModel).IsAssignableFrom(model.GetType()))
                {
                    _factory.InitDynamic((DynamicPost)model, App.PostTypes.GetById(model.TypeId));
                }
                else
                {
                    _factory.Init(model, App.PostTypes.GetById(model.TypeId));
                }

                App.Hooks.OnLoad <PostBase>(model);

                // Never cache dynamic or simple instances
                if (_cache != null && !(model is DynamicPost))
                {
                    if (model is PostInfo)
                    {
                        _cache.Set($"PostInfo_{model.Id.ToString()}", model);
                    }
                    else
                    {
                        _cache.Set(model.Id.ToString(), model);
                    }
                    _cache.Set($"PostId_{model.BlogId}_{model.Slug}", model.Id);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Processes the model on load.
        /// </summary>
        /// <param name="model">The model</param>
        /// <param name="blog">The blog page the post belongs to</param>
        /// <param name="isDraft">If this is a draft</param>
        private async Task OnLoadAsync(PostBase model, PageInfo blog, bool isDraft = false)
        {
            if (model != null)
            {
                // Format permalink
                model.Permalink = $"/{blog.Slug}/{model.Slug}";

                // Initialize model
                if (typeof(IDynamicModel).IsAssignableFrom(model.GetType()))
                {
                    await _factory.InitDynamicAsync((DynamicPost)model, App.PostTypes.GetById(model.TypeId));
                }
                else
                {
                    await _factory.InitAsync(model, App.PostTypes.GetById(model.TypeId));
                }

                // Initialize primary image
                if (model.PrimaryImage == null)
                {
                    model.PrimaryImage = new Extend.Fields.ImageField();
                }

                if (model.PrimaryImage.Id.HasValue)
                {
                    model.PrimaryImage.Media = await _mediaService.GetByIdAsync(model.PrimaryImage.Id.Value).ConfigureAwait(false);

                    // Clear id if the image has been deleted
                    if (model.PrimaryImage.Media == null)
                    {
                        model.PrimaryImage.Id = null;
                    }
                }

                App.Hooks.OnLoad(model);

                // Never cache drafts, dynamic or simple instances
                if (!isDraft && _cache != null && !(model is DynamicPost))
                {
                    if (model is PostInfo)
                    {
                        _cache.Set($"PostInfo_{model.Id.ToString()}", model);
                    }
                    else
                    {
                        _cache.Set(model.Id.ToString(), model);
                    }
                    _cache.Set($"PostId_{model.BlogId}_{model.Slug}", model.Id);
                }
            }
        }