public ActionResult DeleteConfirmed(int id)
        {
            EntryComment entryComment = db.EntryComments.Find(id);

            db.EntryComments.Remove(entryComment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,BlogEntryId,AuthorId,Body,CreationDate,UpdatedDate,UpdateReason")] EntryComment entryComment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(entryComment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AuthorId    = new SelectList(db.Users, "Id", "FirstName", entryComment.AuthorId);
     ViewBag.BlogEntryId = new SelectList(db.Posts, "Id", "Slug", entryComment.BlogEntryId);
     return(View(entryComment));
 }
        // GET: EntryComments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EntryComment entryComment = db.EntryComments.Find(id);

            if (entryComment == null)
            {
                return(HttpNotFound());
            }
            return(View(entryComment));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EntryComment entryComment = db.EntryComments.Find(id);

            if (entryComment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AuthorId    = new SelectList(db.Users, "Id", "FirstName", entryComment.AuthorId);
            ViewBag.BlogEntryId = new SelectList(db.Posts, "Id", "Slug", entryComment.BlogEntryId);
            return(View(entryComment));
        }
        public ActionResult Create([Bind(Include = "BlogEntryId,Body")] EntryComment entryComment)
        {
            if (ModelState.IsValid)
            {
                entryComment.AuthorId     = User.Identity.GetUserId();
                entryComment.CreationDate = DateTime.Now;
                db.EntryComments.Add(entryComment);
                db.SaveChanges();
                var slug = db.Posts.Find(entryComment.BlogEntryId).Slug;
                return(RedirectToAction("Details", "BlogEntries", new { Slug = slug }));
            }

            ViewBag.AuthorId    = new SelectList(db.Users, "Id", "FirstName", entryComment.AuthorId);
            ViewBag.BlogEntryId = new SelectList(db.Posts, "Id", "Slug", entryComment.BlogEntryId);
            return(View(entryComment));
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ownerId"></param>
        /// <param name="postId"></param>
        /// <param name="sortOrder"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public List <EntryComment> GetComments(int?ownerId, int postId, SortOrder sortOrder, int?offset, int?count)
        {
            this.Manager.Method("wall.getComments");
            if (ownerId != null)
            {
                this.Manager.Params("owner_id", ownerId);//((type == MessageType.Outgoing) ? "1" : "0"));;
            }
            this.Manager.Params("post_id", postId);
            if (sortOrder != null)
            {
                this.Manager.Params("sort", ((sortOrder == SortOrder.Asc)?"asc":"desc"));
            }
            if (offset != null)
            {
                this.Manager.Params("offset", offset);
            }
            if (count != null)
            {
                this.Manager.Params("count", count);
            }
            string resp = this.Manager.Execute().GetResponseString();

            if (this.Manager.MethodSuccessed)
            {
                XmlDocument x     = this.Manager.GetXmlDocument(resp);
                XmlNodeList nodes = x.SelectNodes("/response/comment");
                if (nodes.Count > 0)
                {
                    List <EntryComment> comments = new List <EntryComment>();
                    foreach (XmlNode node in nodes)
                    {
                        EntryComment c = CommentsFactory.GetEntryComment(node);
                        comments.Add(c);
                    }
                    return(comments);
                }
                return(null);
            }
            return(null);
        }
Exemplo n.º 7
0
        public async Task <ActionResult <PodcastEntryCommentViewModel> > AddComment(
            string userSlug, string entrySlug, [FromBody] PodcastEntryCommentViewModel comment)
        {
            var entry = await _entryRepository
                        .GetAll()
                        .Where(e => e.Podcast.AppUser.Slug == userSlug && e.Slug == entrySlug)
                        .SingleOrDefaultAsync();

            if (entry is null)
            {
                return(BadRequest($"Could not find entry"));
            }

            var spamCheckComment = new AkismetComment {
                Blog = _config["SpamFilterSettings:BlogUrl"],
                CommentAuthorEmail = comment.FromEmail,
                CommentContent     = comment.Comment,
                UserIp             = _contextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(),
                UserAgent          = Request.Headers["User-Agent"]
            };

            comment.IsSpam = (await _akismet.CheckCommentAsync(spamCheckComment)).IsSpam;

            var newComment = new EntryComment()
            {
                CommentText   = comment.Comment,
                FromUser      = comment.FromName,
                FromUserEmail = comment.FromEmail,
                IsSpam        = comment.IsSpam
            };

            entry.Comments.Add(newComment);
            await _unitOfWork.CompleteAsync();

            return(Ok(comment));
        }