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); }
public async Task <ActionResult> PostAsync(string categoryAlias, string alias) { var model = await ContentModel.GetContentAsync(this.Tenant, categoryAlias, alias, true).ConfigureAwait(true); if (model == null) { return(this.View(GetLayoutPath(this.Tenant) + "404.cshtml")); } string path = GetLayoutPath(this.Tenant); string theme = this.GetTheme(); string layout = ThemeConfiguration.GetBlogLayout(this.Tenant, theme).Or(ThemeConfiguration.GetLayout(this.Tenant, theme)); model.LayoutPath = path; model.Layout = layout; model.Contents = await ContentExtensions.ParseHtmlAsync(this.Tenant, model.Contents).ConfigureAwait(true); return(this.View(this.GetRazorView <AreaRegistration>("Frontend/Blog/Post.cshtml", this.Tenant), model)); }
public async Task <ActionResult> IndexAsync(string categoryAlias = "", string alias = "", bool isPost = false, FormCollection form = null) { try { Log.Verbose($"Prepping \"{this.CurrentPageUrl}\"."); var model = await this.GetContentsAsync(categoryAlias, alias, isPost, form).ConfigureAwait(true); if (model == null) { Log.Error($"Could not serve the url \"{this.CurrentPageUrl}\" because the model was null."); return(this.View(GetLayoutPath(this.Tenant) + "404.cshtml")); } Log.Verbose($"Parsing custom content extensions for \"{this.CurrentPageUrl}\"."); model.Contents = await ContentExtensions.ParseHtmlAsync(this.Tenant, model.Contents).ConfigureAwait(true); Log.Verbose($"Parsing custom form extensions for \"{this.CurrentPageUrl}\"."); model.Contents = await FormsExtension.ParseHtmlAsync(this.Tenant, model.Contents, isPost, form).ConfigureAwait(true); model.Contents = HitHelper.Add(model.Contents); return(this.View(this.GetRazorView <AreaRegistration>("Index/Index.cshtml", this.Tenant), model)); } catch (NpgsqlException ex) { Log.Error ( "An exception was encountered while trying to get content. More info:\nCategory alias: {categoryAlias}, alias: {alias}, is post: {isPost}, form: {form}. Exception\n{ex}.", categoryAlias, alias, isPost, form, ex); return(new HttpNotFoundResult()); } }