Ejemplo n.º 1
0
        /// <summary>
        /// Saves the comment.
        /// </summary>
        /// <param name="pageId">The unique page id</param>
        /// <param name="model">The comment model</param>
        public async Task SaveComment(Guid pageId, Models.Comment model)
        {
            var comment = await _db.PageComments
                          .FirstOrDefaultAsync(c => c.Id == model.Id);

            if (comment == null)
            {
                comment = new PageComment
                {
                    Id = model.Id
                };
                await _db.PageComments.AddAsync(comment);
            }

            comment.UserId     = model.UserId;
            comment.PageId     = pageId;
            comment.Author     = model.Author;
            comment.Email      = model.Email;
            comment.Url        = model.Url;
            comment.IsApproved = model.IsApproved;
            comment.Body       = model.Body;
            comment.Created    = model.Created;

            await _db.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a comment with the Episerver Social Framework.
        /// </summary>
        /// <param name="comment">The comment to add.</param>
        /// <returns>The added comment.</returns>
        public PageComment Add(PageComment comment)
        {
            var     newComment   = AdaptPageComment(comment);
            Comment addedComment = null;

            try
            {
                addedComment = this.commentService.Add(newComment);

                if (addedComment == null)
                {
                    throw new SocialRepositoryException("The newly posted comment could not be added. Please try again");
                }
            }
            catch (SocialAuthenticationException ex)
            {
                throw new SocialRepositoryException("The application failed to authenticate with Episerver Social.", ex);
            }
            catch (MaximumDataSizeExceededException ex)
            {
                throw new SocialRepositoryException("The application request was deemed too large for Episerver Social.", ex);
            }
            catch (SocialCommunicationException ex)
            {
                throw new SocialRepositoryException("The application failed to communicate with Episerver Social.", ex);
            }
            catch (SocialException ex)
            {
                throw new SocialRepositoryException("Episerver Social failed to process the application request.", ex);
            }

            return(AdaptComment(addedComment));
        }
Ejemplo n.º 3
0
        public IActionResult CreateComment(PageComment comment)
        {
            comment.IsDelete   = false;
            comment.CreateDate = DateTime.Now;
            comment.UserId     = _userService.GetUserIdByUserName(User.Identity.Name);
            pageRepoitory.AddComment(comment);

            return(View("ShowComment", pageRepoitory.GetPageComment(comment.PageID)));
        }
        public ActionResult Edit([Bind(Include = "CommentID,PageID,Name,Email,Website,Comment,CreateDate")] PageComment pageComment)
        {
            if (ModelState.IsValid)
            {
                pc.UpdatePageComment(pageComment);
                pc.SavePageComment();
                return(RedirectToAction("Index"));
            }
            int groupId = pa.GetPageById(pageComment.PageID).GroupID;

            ViewBag.GroupID = new SelectList(pg.GetAllPageGroup(), "GroupID", "GroupTitle", groupId);
            ViewBag.PageID  = new SelectList(pa.GetAllPage(), "PageID", "PageTitle", pageComment.PageID);
            return(View(pageComment));
        }
        public ActionResult AddComment(int id, string name, string email, string comment)
        {
            PageComment addcomment = new PageComment()
            {
                CreateDate = DateTime.Now,
                PageID     = id,
                Name       = name,
                Email      = email,
                Comment    = comment
            };

            pageCommentRepository.AddComment(addcomment);
            return(PartialView("ShowComment", pageCommentRepository.GetCommentByNewsId(id)));
        }
        // GET: AdminPanel/PageComments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PageComment pageComment = pc.GetPageCommentById(id.Value);

            if (pageComment == null)
            {
                return(HttpNotFound());
            }
            return(View(pageComment));
        }
        // GET: Admin/PageComments/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PageComment pageComment = db.PageCommentRepository.GetById(id);

            if (pageComment == null)
            {
                return(HttpNotFound());
            }
            return(View(pageComment));
        }
        /// <summary>
        /// Add an activity for the newly added comment.
        /// </summary>
        /// <param name="comment">The added comment.</param>
        private void AddCommentActivity(PageComment comment)
        {
            try
            {
                var commentActivity = new PageCommentActivity {
                    Body = comment.Body
                };

                _activityRepository.Add(comment.AuthorId, comment.Target, commentActivity);
            }
            catch (SocialRepositoryException ex)
            {
                AddMessage(MessageKey, new MessageViewModel(ex.Message, ErrorMessage));
            }
        }
Ejemplo n.º 9
0
        public IActionResult AddComment(int pageId, string name, string email, string commentText)
        {
            var         page    = db.Page.GetPageByID(pageId);
            PageComment comment = new PageComment()
            {
                CommentText = commentText,
                DateTime    = DateTime.Now,
                Email       = email,
                Name        = name,
                PageID      = pageId
            };

            db.PageComment.InsertComment(comment);
            return(RedirectToAction(nameof(ShowPage), new { id = page.PageID, title = page.PageTitle }));
        }
Ejemplo n.º 10
0
        public ActionResult AddComment(int id, string name, string email, string comment)
        {
            PageComment Comment = new PageComment()
            {
                Comment    = comment,
                Name       = name,
                Email      = email,
                PageID     = id,
                CreateDate = DateTime.Now
            };

            db.PageCommentRepository.Insert(Comment);
            db.Commit();
            return(PartialView("ShowComments", db.CustomRepositories.GetCommentsByPageId(id)));
        }
Ejemplo n.º 11
0
        public ActionResult AddComment(int id, string name, string email, string comment)
        {
            PageComment addcm = new PageComment()
            {
                CreateDate = DateTime.Now,
                PageID     = id,
                Comment    = comment,
                Show       = true,
                Name       = name,
                Email      = email,
            };

            pageCommentRepository.AddNewCommnet(addcm);

            return(PartialView("ShowCommnetByPageID", pageCommentRepository.GetAllCommentByID(id)));
        }
Ejemplo n.º 12
0
        public ActionResult AddComment(int id, string name, string email, string comment)
        {
            PageComment addcomment = new PageComment()
            {
                CreateDate = DateTime.Now,
                PageId     = id,
                Comment    = comment,
                Email      = email,
                Name       = name
            };

            db.PageCommentRepository.Insert(addcomment);
            db.Save();

            return(PartialView("ShowComments", db.PageCommentRepository.Get(c => c.PageId == id)));
        }
        /// <summary>
        /// Adds the comment in the CommentFormViewModel to the Episerver Social repository.
        /// </summary>
        /// <param name="formViewModel">The submitted comment form view model.</param>
        /// <returns>The added PageComment</returns>
        private PageComment AddComment(CommentFormViewModel formViewModel)
        {
            var         newComment   = AdaptCommentFormViewModelToSocialComment(formViewModel);
            PageComment addedComment = null;

            try
            {
                addedComment = _commentRepository.Add(newComment);
                AddMessage(MessageKey, new MessageViewModel(SubmitSuccessMessage, SuccessMessage));
            }
            catch (SocialRepositoryException ex)
            {
                AddMessage(MessageKey, new MessageViewModel(ex.Message, ErrorMessage));
            }

            return(addedComment);
        }
Ejemplo n.º 14
0
        public ActionResult Create([Bind(Include = "CommentID,PageID,Name,Email,Website,Comment,CreateDate")] PageComment pageComment)
        {
            if (ModelState.IsValid)
            {
                pageComment.CreateDate = DateTime.Now;
                pc.InsertPageComment(pageComment);
                pc.SavePageComment();
                return(RedirectToAction("Single_page", "Home", new { area = "", id = pageComment.PageID }));
            }
            int groupId = pa.GetPageById(pageComment.PageID).GroupID;

            ViewBag.GroupID = new SelectList(pg.GetAllPageGroup(), "GroupID", "GroupTitle", groupId);
            ViewBag.PageID  = new SelectList(pa.GetPageByGroupId(groupId), "PageID", "PageTitle", pageComment.PageID);
            //if (status == true)
            //    return RedirectToAction("Single_page", "Home", new { area = "", id = pageComment.PageID });
            //else
            return(View(pageComment));
        }
Ejemplo n.º 15
0
        // GET: AdminPanel/PageComments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PageComment pageComment = pc.GetPageCommentById(id.Value);

            if (pageComment == null)
            {
                return(HttpNotFound());
            }
            int groupId = pa.GetPageById(pageComment.PageID).GroupID;

            ViewBag.GroupID = new SelectList(pg.GetAllPageGroup(), "GroupID", "GroupTitle", groupId);
            ViewBag.PageID  = new SelectList(pa.GetAllPage(), "PageID", "PageTitle", pageComment.PageID);
            return(View(pageComment));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets the model data.
        /// </summary>
        /// <param name="id">The requested model id</param>
        /// <param name="draft">If the draft should be fetched</param>
        public virtual async Task <IActionResult> OnPostSaveComment(Guid id, bool draft = false)
        {
            // Create the comment
            var comment = new PageComment
            {
                IpAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString(),
                UserAgent = Request.Headers.ContainsKey("User-Agent") ? Request.Headers["User-Agent"].ToString() : "",
                Author    = CommentAuthor,
                Email     = CommentEmail,
                Url       = CommentUrl,
                Body      = CommentBody
            };

            await _api.Pages.SaveCommentAndVerifyAsync(id, comment);

            Data = await _loader.GetPageAsync <T>(id, HttpContext.User, draft);

            return(Redirect(Data.Permalink + "#comments"));
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Saves the comment and verifies if should be approved or not.
 /// </summary>
 /// <param name="pageId">The unique page id</param>
 /// <param name="model">The comment model</param>
 public Task SaveCommentAndVerifyAsync(Guid pageId, PageComment model)
 {
     return(SaveCommentAsync(pageId, model, true));
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Saves the comment.
 /// </summary>
 /// <param name="pageId">The unique page id</param>
 /// <param name="model">The comment model</param>
 public Task SaveCommentAsync(Guid pageId, PageComment model)
 {
     return(SaveCommentAsync(pageId, model, false));
 }
Ejemplo n.º 19
0
 public PageComment Add(PageComment comment)
 {
     return(new PageComment());
 }
 /// <summary>
 ///     Adapt the application PageComment to the Episerver Social Comment
 /// </summary>
 /// <param name="comment">The application's PageComment.</param>
 /// <returns>The Episerver Social Comment.</returns>
 private Comment AdaptPageComment(PageComment comment)
 {
     return(new Comment(Reference.Create(comment.Target), Reference.Create(comment.AuthorId), comment.Body,
                        true));
 }
Ejemplo n.º 21
0
 public void AddComment(PageComment comment)
 {
     _db.PageComments.Add(comment);
     _db.SaveChanges();
 }