Ejemplo n.º 1
0
        public async Task <ActionResult> EntryEdit_Partial(EditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }
            using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) {
                BlogEntry data = await dataProvider.GetItemAsync(model.Identity);

                if (data == null)
                {
                    throw new Error(this.__ResStr("notFound", "Blog entry with id {0} not found"), model.Identity);
                }
                // save updated item
                data = model.GetData(data); // merge new data into original
                model.SetData(data);        // and all the data back into model for final display

                UpdateStatusEnum status = await dataProvider.UpdateItemAsync(data);

                if (status != UpdateStatusEnum.OK)
                {
                    throw new Error(this.__ResStr("errSaving", "An unexpected error occurred saving the blog entry - {0}", status));
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "Blog entry saved")));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> CategoryHeader(int?blogEntry)
        {
            int category;

            Manager.TryGetUrlArg <int>("BlogCategory", out category);
            int entry = (int)(blogEntry ?? 0);

            if (entry != 0)
            {
                using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) {
                    BlogEntry data = await entryDP.GetItemAsync(entry);

                    if (data != null)
                    {
                        category = data.CategoryIdentity;
                    }
                }
            }
            if (category != 0)
            {
                using (BlogCategoryDataProvider dataProvider = new BlogCategoryDataProvider()) {
                    BlogCategory data = await dataProvider.GetItemAsync(category);

                    if (data != null)
                    {
                        DisplayModel model = new DisplayModel();
                        model.SetData(data);
                        Module.Title = data.Category.ToString();
                        return(View(model));
                    }
                }
            }
            return(new EmptyResult());
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> CommentAdd(int?blogEntry)
        {
            int entryNum = blogEntry ?? 0;
            int blogCategory;

            using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) {
                BlogEntry data = null;
                if (entryNum != 0)
                {
                    data = await entryDP.GetItemAsync(entryNum);
                }
                if (data == null)
                {
                    return(new EmptyResult());
                }
                blogCategory = data.CategoryIdentity;
                if (!data.OpenForComments)
                {
                    if (data.Comments == 0)
                    {
                        return(new EmptyResult());
                    }
                }
            }
            AddModel model = new AddModel {
                CategoryIdentity = blogCategory,
                EntryIdentity    = entryNum,
                Captcha          = new RecaptchaV2Data(),
            };
            await model.UpdateDataAsync();

            return(View(model));
        }
Ejemplo n.º 4
0
        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));
            }
        }
Ejemplo n.º 5
0
        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));
                    }
                }
            }
        }
Ejemplo n.º 6
0
            private async Task <bool> TestOpenForCommentsAsync(int blogEntry)
            {
                using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) {
                    BlogEntry ent = await entryDP.GetItemAsync(blogEntry);

                    if (ent == null)
                    {
                        throw new InternalError("Entry with id {0} not found", blogEntry);
                    }
                    return(ent.OpenForComments);
                }
            }
Ejemplo n.º 7
0
        public async Task <ActionResult> EntryEdit(int blogEntry)
        {
            using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) {
                EditModel model = new EditModel {
                };
                BlogEntry data  = await dataProvider.GetItemAsync(blogEntry);

                if (data == null)
                {
                    throw new Error(this.__ResStr("notFound", "Blog entry with id {0} not found"), blogEntry);
                }
                model.SetData(data);
                Module.Title = data.Title;
                return(View(model));
            }
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> CommentsDisplay(int?blogEntry)
        {
            int            entryNum = blogEntry ?? 0;
            BlogConfigData config   = await BlogConfigDataProvider.GetConfigAsync();

            DisplayModel model = new DisplayModel()
            {
            };

            CommentEditModule editMod = new CommentEditModule();

            using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) {
                BlogEntry entry = null;
                if (entryNum != 0)
                {
                    entry = await entryDP.GetItemAsync(entryNum);
                }
                if (entry == null)
                {
                    return(new EmptyResult());
                }
                model.OpenForComments = entry.OpenForComments;
            }
            using (BlogCommentDataProvider commentDP = new BlogCommentDataProvider(entryNum)) {
                DataProviderGetRecords <BlogComment> comments = await commentDP.GetItemsAsync(0, 0, null, null);

                if (!model.OpenForComments && comments.Total == 0)
                {
                    return(new EmptyResult());
                }

                model.ShowGravatars = config.ShowGravatar;
                model.CanApprove    = await Resource.ResourceAccess.IsResourceAuthorizedAsync(Info.Resource_AllowManageComments);

                model.CanRemove = await Resource.ResourceAccess.IsResourceAuthorizedAsync(Info.Resource_AllowManageComments);

                List <CommentData> list = new List <CommentData>();
                foreach (BlogComment d in comments.Data)
                {
                    ModuleAction editAction = await editMod.GetAction_EditAsync(Module.EditUrl, d.EntryIdentity, d.Identity);

                    ModuleAction approveAction = await Module.GetAction_ApproveAsync(d.CategoryIdentity, d.Identity);

                    ModuleAction removeAction = await Module.GetAction_RemoveAsync(d.CategoryIdentity, d.Identity);

                    if (model.CanApprove || model.CanRemove)
                    {
                        list.Add(new CommentData(d, editAction, approveAction, removeAction));
                    }
                    else
                    {
                        if (!d.Deleted && d.Approved)
                        {
                            list.Add(new CommentData(d, editAction, approveAction, removeAction));
                        }
                    }
                }
                model.Comments = list;

                int pending = (from d in comments.Data where !d.Deleted && !d.Approved select d).Count();
                model.PendingApproval = pending;
                int commentsTotal = (from c in comments.Data where !c.Deleted select c).Count();

                // set a module title
                string title;
                if (commentsTotal > 0 && pending > 0)
                {
                    if (commentsTotal > 1)
                    {
                        if (pending > 1)
                        {
                            title = this.__ResStr("commentsPs", "{0} Comments - {1} Comments Pending Approval", commentsTotal, pending);
                        }
                        else
                        {
                            title = this.__ResStr("commentsP", "{0} Comments - 1 Comment Pending Approval", commentsTotal);
                        }
                    }
                    else
                    {
                        title = this.__ResStr("commentP", "1 Comment Pending Approval");
                    }
                }
                else
                {
                    if (commentsTotal > 1)
                    {
                        title = this.__ResStr("comments", "{0} Comments", commentsTotal);
                    }
                    else if (commentsTotal == 1)
                    {
                        title = this.__ResStr("comment1", "1 Comment");
                    }
                    else
                    {
                        title = this.__ResStr("comment0", "No Comments");
                    }
                }
                Module.Title = title;

                return(View(model));
            }
        }