public async Task <ActionResult> EntryDisplay(int?blogEntry)
        {
            int entryNum = blogEntry ?? 0;

            using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) {
                BlogEntry data = null;
                if (entryNum != 0)
                {
                    data = await dataProvider.GetItemAsync(entryNum);
                }
                if (data == null)
                {
                    MarkNotFound();
                    return(View("NotFound"));
                }

                Manager.CurrentPage.EvaluatedCanonicalUrl = await BlogConfigData.GetEntryCanonicalNameAsync(entryNum);

                if (!string.IsNullOrWhiteSpace(data.Keywords))
                {
                    Manager.CurrentPage.Keywords = data.Keywords;
                    Manager.MetatagsManager.AddMetatag("news_keywords", data.Keywords.ToString());
                }
                Manager.CurrentPage.Description = data.Title;
                Manager.PageTitle = data.Title;

                DisplayModel model = new DisplayModel();
                model.SetData(data);
                Module.Title = data.Title;
                return(View(model));
            }
        }
Exemple #2
0
        public async Task <string> RenderViewAsync(BlogModule module, BlogModuleController.DisplayModel model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            int count = 0;

            if (model.StartDate != null)
            {
                hb.Append($@"
<div class='t_startdate'>
    {this.__ResStr("startDate", "Showing blog entries published on or before {0}.", Formatting.FormatDate(model.StartDate))}
</div>");
            }

            foreach (BlogModuleController.Entry blogEntry in model.BlogEntries)
            {
                ++count;

                hb.Append($@"
<h2>
    <a href='{Utility.HtmlAttributeEncode(await BlogConfigData.GetEntryCanonicalNameAsync(blogEntry.Identity))}' class='yaction-link'>
        {Utility.HtmlEncode(blogEntry.Title.ToString())}
    </a>
</h2>
<div class='t_entry t_entry{count}'>
    {await HtmlHelper.ForDisplayContainerAsync(blogEntry, "PropertyList")}
</div>");
            }

            return(hb.ToString());
        }
        public async Task <ActionResult> CommentAdd_Partial(AddModel model)
        {
            await model.UpdateDataAsync();

            using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) {
                BlogEntry blogEntry = await entryDP.GetItemAsync(model.EntryIdentity);

                if (blogEntry == null)
                {
                    throw new Error(this.__ResStr("notFound", "Blog entry with id {0} not found."), model.EntryIdentity);
                }
                if (!blogEntry.OpenForComments)
                {
                    throw new InternalError("Can't add comments to this blog entry");
                }
                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }
                using (BlogCommentDataProvider blogCommentDP = new BlogCommentDataProvider(model.EntryIdentity)) {
                    BlogComment blogComment = model.GetData();
                    if (!await blogCommentDP.AddItemAsync(blogComment))
                    {
                        throw new Error(this.__ResStr("alreadyExists", "An error occurred adding this new comment"));
                    }

                    // send notification email
                    BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync();

                    if (config.NotifyNewComment)
                    {
                        SendEmail sendEmail = new SendEmail();
                        object    parms     = new {
                            Description = !blogComment.Approved ? this.__ResStr("needApproval", "This comment requires your approval.") : this.__ResStr("autoApproval", "This comment has been automatically approved."),
                            Category    = (await blogEntry.GetCategoryAsync()).ToString(),
                            Title       = blogEntry.Title.ToString(),
                            Url         = Manager.CurrentSite.MakeUrl(await BlogConfigData.GetEntryCanonicalNameAsync(blogEntry.Identity)),
                            Comment     = Utility.HtmlDecode(model.Comment),
                            UserName    = model.Name,
                            UserEmail   = model.Email,
                            UserWebsite = model.Website,
                        };
                        string subject = this.__ResStr("newComment", "New Blog Comment ({0} - {1})", blogEntry.Title.ToString(), Manager.CurrentSite.SiteDomain);
                        await sendEmail.PrepareEmailMessageAsync(config.NotifyEmail, subject, await sendEmail.GetEmailFileAsync(Package.GetCurrentPackage(this), "New Comment.txt"), Parameters : parms);

                        await sendEmail.SendAsync(true);
                    }

                    if (!blogComment.Approved)
                    {
                        return(FormProcessed(model, this.__ResStr("okSavedReview", "New comment saved - It will be reviewed before becoming publicly viewable"), OnClose: OnCloseEnum.ReloadPage, OnPopupClose: OnPopupCloseEnum.ReloadParentPage));
                    }
                    else
                    {
                        return(FormProcessed(model, this.__ResStr("okSaved", "New comment added"), OnClose: OnCloseEnum.ReloadPage, OnPopupClose: OnPopupCloseEnum.ReloadParentPage));
                    }
                }
            }
        }
Exemple #4
0
        public async Task <ModuleAction> GetAction_DisplayAsync(int blogEntry, bool ReadMore = false)
        {
            string url = await BlogConfigData.GetEntryCanonicalNameAsync(blogEntry);

            return(new ModuleAction(this)
            {
                Url = url,
                Image = "#Display",
                LinkText = ReadMore ? this.__ResStr("moreLink", "Read More") : this.__ResStr("displayLink", "Display"),
                MenuText = ReadMore ? this.__ResStr("moreText", "Display") : this.__ResStr("displayText", "Display"),
                Tooltip = ReadMore ? this.__ResStr("moreTooltip", "Read the entire blog entry") : this.__ResStr("displayTooltip", "Display the blog entry"),
                Legend = ReadMore ? this.__ResStr("moreLegend", "Displays the entire blog entry") : this.__ResStr("displayLegend", "Displays an existing blog entry"),
                Style = ModuleAction.ActionStyleEnum.Normal,
                Category = ModuleAction.ActionCategoryEnum.Read,
                Mode = ModuleAction.ActionModeEnum.Any,
                Location = ModuleAction.ActionLocationEnum.NoAuto,
                SaveReturnUrl = true,
            });
        }