Exemplo n.º 1
0
        public async Task <ActionResult> Entry(string id, EntryViewModel model)
        {
            var entry = await this.GetByPermalink(id);

            if (entry == null)
            {
                return(this.NotFound());
            }

            if (!this.ModelState.IsValid)
            {
                model.BlogEntry          = entry;
                model.RelatedBlogEntries = await this.GetRelatedBlogEntries(entry);

                return(this.View(model));
            }

            var blogEntryComment = new BlogEntryComment()
            {
                Name        = model.Comment.Name,
                Email       = model.Comment.Email,
                Homepage    = model.Comment.Homepage,
                Comment     = model.Comment.Comment,
                AdminPost   = this.User.Identity.IsAuthenticated,
                BlogEntryId = entry.Id
            };

            await this.addBlogEntryCommentCommandHandler.HandleAsync(new AddBlogEntryCommentCommand()
            {
                Entity  = blogEntryComment,
                Referer = this.Request.GetTypedHeaders().Referer?.ToString()
            });

            return(this.RedirectToAction(nameof(this.Entry), new { Id = id }));
        }
Exemplo n.º 2
0
        public IHttpActionResult PostBlogEntriesComment(BlogEntryCommentModel comment)
        {
            try
            {
                _logger.Debug(string.Format("ini process - PostBlogEntriesComment,idUser:{0}", CurrentIdUser));

                if (!ModelState.IsValid)
                {
                    _logger.Debug(string.Format("ini PostBlogEntriesComment - inValid,idUser:{0}", CurrentIdUser));
                    return(BadRequest(ModelState));
                }

                BlogEntryComment blogEntryComment = AutoMapper.Mapper.Map <BlogEntryComment>(comment);
                blogEntryComment.LastActivityIdUser = CurrentIdUser;
                blogEntryComment.CreationIdUser     = CurrentIdUser;


                _blogEntryCommentBL.Insert(blogEntryComment);
                _logger.Debug(string.Format("finish PostBlogEntriesComment - success,idUser:{0}", CurrentIdUser));

                return(Ok(new JsonResponse {
                    Success = true, Message = "Comment was Saved successfully", Data = blogEntryComment
                }));
            }
            catch (Exception ex)
            {
                LogError(ex);
                return(InternalServerError(ex));
            }
        }
Exemplo n.º 3
0
        public void Update(BlogEntryComment entity)
        {
            /* Not used UnitOfWork attribute, because this method only calls one repository method and repoository can manage it's connection/transaction. */

            System.DateTime currentDate = _commonRepository.GetCurrentDateTime();
            entity.LastActivityDate   = currentDate;
            entity.LastActivityIdUser = entity.LastActivityIdUser;
            _repository.Update(entity);
        }
Exemplo n.º 4
0
        public async virtual Task <ActionResult> Entry(string id, [Bind(Include = "Name, Email, Homepage, Comment")] BlogEntryComment blogEntryComment)
        {
            var entry = await this.GetByHeader(id);

            if (entry == null)
            {
                return(new HttpNotFoundResult());
            }

            this.ModelState.Remove("BlogEntryId");

            if (!ModelState.IsValid)
            {
                var errorModel = new BlogEntryDetail()
                {
                    BlogEntry = entry
                };

                if (this.Request.IsAjaxRequest())
                {
                    return(this.PartialView(MVC.Blog.Views._CommentsControl, errorModel));
                }
                else
                {
                    errorModel.RelatedBlogEntries = await this.GetRelatedBlogEntries(entry);

                    return(this.View(errorModel));
                }
            }

            blogEntryComment.AdminPost   = this.Request.IsAuthenticated;
            blogEntryComment.BlogEntryId = entry.Id;
            entry.BlogEntryComments.Add(blogEntryComment);

            await this.addBlogEntryCommentCommandHandler.HandleAsync(new AddBlogEntryCommentCommand()
            {
                Entity = blogEntryComment
            });

            var model = new BlogEntryDetail()
            {
                BlogEntry           = entry,
                HideNewCommentsForm = true
            };

            if (this.Request.IsAjaxRequest())
            {
                return(this.PartialView(MVC.Blog.Views._CommentsControl, model));
            }
            else
            {
                model.RelatedBlogEntries = await this.GetRelatedBlogEntries(entry);

                return(this.View(model));
            }
        }
Exemplo n.º 5
0
        public IHttpActionResult Post([FromBody] BlogEntryComment model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            context.BlogEntryComments.Add(model);
            context.SaveChanges();
            return(CreatedAtRoute("DefaultApi", new { id = model.BlogEntryCommentId }, model));
        }
 public ActionResult saveComment(BlogEntryCommentViewModel model)
 {
     if (ModelState.IsValid)
     {
         BlogEntryComment comment = new BlogEntryComment(new { model.CommentText, model.Author });
         using (var db = new Datalayer.Models.DatabaseContext())
         {
             db.BlogEntryComments.Add(model);
             db.BlogEntries.BlogEntryComment.Comment.Add(model);
             db.SaveChanges();
         }
     }
 }
Exemplo n.º 7
0
 public ActionResult saveComment(BlogEntryCommentViewModel model)
 {
     if (ModelState.IsValid)
     {
         BlogEntryComment comment = new BlogEntryComment {
             CommentText = model.CommentText, Author = model.Author
         };
         using (var db = new Datalayer.Models.DatabaseContext())
         {
             db.BlogEntryComments.Add(comment);
             var blog = db.BlogEntries.Find(model.BlogID);
             blog.Comments.Add(comment);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("BlogEntry", "BlogEntries"));
 }
Exemplo n.º 8
0
        public DeleteBlogEntryCommentCommandHandlerTest()
        {
            this.unitOfWork = new InMemoryDatabaseFactory().CreateContext();

            var blogEntry = new BlogEntry()
            {
                ShortContent = "Test",
                Header       = "Test"
            };

            this.comment = new BlogEntryComment()
            {
                Name        = "Test",
                Comment     = "Test",
                BlogEntryId = blogEntry.Id
            };
            this.unitOfWork.BlogEntries.Add(blogEntry);
            this.unitOfWork.BlogEntryComments.Add(this.comment);
            this.unitOfWork.SaveChanges();

            Assert.Single(this.unitOfWork.BlogEntryComments);
        }