コード例 #1
0
        public async Task <ActionResult> Index(string categoryAlias = "", string alias = "", bool isPost = false,
                                               FormCollection form  = null)
        {
            try
            {
                Log.Verbose($"Prepping \"{this.CurrentPageUrl}\".");

                var model = this.GetContents(categoryAlias, alias, isPost, form);

                if (model == null)
                {
                    Log.Error($"Could not serve the url \"{this.CurrentPageUrl}\" because the model was null.");
                    return(this.View(GetLayoutPath() + "404.cshtml"));
                }

                Log.Verbose($"Parsing custom content extensions for \"{this.CurrentPageUrl}\".");
                model.Contents = ContentExtensions.ParseHtml(this.Tenant, model.Contents);

                Log.Verbose($"Parsing custom form extensions for \"{this.CurrentPageUrl}\".");
                model.Contents = await FormsExtension.ParseHtml(model.Contents, isPost, form);

                model.Contents = HitHelper.Add(model.Contents);

                return(this.View(this.GetRazorView <AreaRegistration>("Index/Index.cshtml"), 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());
            }
        }
コード例 #2
0
        public ActionResult Home(int pageNumber = 1)
        {
            try
            {
                if (pageNumber <= 0)
                {
                    pageNumber = 1;
                }

                var contents = ContentModel.GetBlogContents(pageNumber);

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

                foreach (var content in contents)
                {
                    content.Contents = ContentExtensions.ParseHtml(this.Tenant, content.Contents);
                }

                string theme         = this.GetTheme();
                string layout        = ThemeConfiguration.GetBlogLayout(theme);
                var    configuration = Configurations.GetDefaultConfiguration();

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

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

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

            return(null);
        }
コード例 #3
0
        public ActionResult Post(string categoryAlias, string alias)
        {
            var model = ContentModel.GetContent(this.Tenant, categoryAlias, alias, true);

            if (model == null)
            {
                return(this.View(GetLayoutPath() + "404.cshtml"));
            }

            string path   = GetLayoutPath();
            string theme  = this.GetTheme();
            string layout = ThemeConfiguration.GetBlogLayout(theme);

            model.LayoutPath = path;
            model.Layout     = layout;
            model.Contents   = ContentExtensions.ParseHtml(this.Tenant, model.Contents);

            return(this.View(this.GetRazorView <AreaRegistration>("Blog/Post.cshtml"), model));
        }