コード例 #1
0
ファイル: BlogController.cs プロジェクト: evisional1/mixerp
        public async Task <ActionResult> HomeAsync(int pageNumber = 1)
        {
            try
            {
                if (pageNumber <= 0)
                {
                    pageNumber = 1;
                }

                var awaiter = await ContentModel.GetBlogContentsAsync(this.Tenant, pageNumber).ConfigureAwait(true);

                var contents = awaiter?.ToList() ?? new List <Content>();

                if (!contents.Any())
                {
                    return(this.View(GetLayoutPath(this.Tenant) + "404.cshtml"));
                }

                foreach (var content in contents)
                {
                    content.Contents =
                        await ContentExtensions.ParseHtmlAsync(this.Tenant, content.Contents).ConfigureAwait(false);
                }

                string theme  = this.GetTheme();
                string layout = ThemeConfiguration.GetBlogLayout(this.Tenant, theme).Or(ThemeConfiguration.GetLayout(this.Tenant, theme));

                var configuration = await Configurations.GetDefaultConfigurationAsync(this.Tenant).ConfigureAwait(false);

                var model = new Blog
                {
                    Contents   = contents,
                    LayoutPath = GetLayoutPath(this.Tenant),
                    Layout     = layout
                };

                if (configuration != null)
                {
                    model.Title       = configuration.BlogTitle;
                    model.Description = configuration.BlogDescription;
                }

                return(this.View(this.GetRazorView <AreaRegistration>("Frontend/Blog/Home.cshtml", this.Tenant), model));
            }
            catch (NpgsqlException ex)
            {
                Log.Error($"An exception was encountered while trying to get blog contents. Exception: {ex}");
            }

            return(null);
        }