Beispiel #1
0
        public async Task <IActionResult> UpdateCommentAsync(Guid commentId, EditCommentViewModel model)
        {
            try
            {
                if (model == null)
                {
                    return(BadRequest());
                }

                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status422UnprocessableEntity));
                }

                var endPoint = await BusConfigurator.GetEndPointAsync(RabbitMqConstants.ArticleWriteServiceQueue);

                await endPoint.Send <IUpdateCommentCommand>(new
                {
                    model.Id,
                    model.AddedBy,
                    model.AddedDate,
                    model.Comment,
                    model.UserIp
                });

                return(Accepted());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Beispiel #2
0
        public async Task UpdateComment(EditCommentViewModel model)
        {
            var content = model.Content;

            if (string.IsNullOrWhiteSpace(content))
            {
                throw new NullReferenceException("Comment is required.");
            }

            var comment = new Comment
            {
                AuthorId  = model.CommentAuthorId,
                Id        = model.CommentId,
                Content   = model.Content,
                CreatedOn = DateTime.Parse(model.CreatedOn),
                IsDeleted = model.IsDeleted,
                PostId    = model.PostId
            };

            this.commentRepo.Update(comment);

            try
            {
                await this.commentRepo.SaveChangesAsync();
            }
            catch (Exception e)
            {
                this.logger.LogDebug(e.Message);

                throw new InvalidOperationException("Sorry an error occurred whille trying to edit your comment.");
            }
        }
        public EditCommentViewModel GetCommentById(int commentId)
        {
            var query = from c in _repository.Comments
                        where c.CommentID == commentId
                        orderby c.UpdatedDate descending
                        select new
            {
                CommentID    = c.CommentID,
                Body         = c.Body,
                AddedBy      = c.AddedBy,
                AddedByEmail = c.AddedByEmail,
                AddedByWeb   = c.AddedByWeb,
                AddedByIP    = c.AddedByIP,
                AddedDate    = c.AddedDate,
                ArticleLID   = c.Article.LID
            };
            var comments = query.ToList();

            if (comments.Count > 0)
            {
                EditCommentViewModel model = new EditCommentViewModel();
                model.InjectFrom(comments[0]);
                return(model);
            }
            return(null);
        }
        public IHttpActionResult EditComment(EditCommentViewModel commentViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var editCommentDto = _mapper.Map <EditCommentViewModel, EditCommentDTO>(commentViewModel);

            SetOrganizationAndUser(editCommentDto);

            try
            {
                _commentService.EditComment(editCommentDto);
                return(Ok());
            }
            catch (UnauthorizedException)
            {
                return(BadRequest());
            }
            catch (ValidationException e)
            {
                return(BadRequestWithError(e));
            }
        }
        public ActionResult Edit(EditCommentViewModel viewModel)
        {
            var comment = _db.Blog_Comments.Find(viewModel.Id);

            if (comment == null)
            {
                return(HttpNotFound());
            }

            if (!User.IsInRole("Admin") && (String.IsNullOrEmpty(comment.OwnerId) || User.Identity.GetUserId() != comment.OwnerId))
            {
                return(new HttpUnauthorizedResult());
            }

            comment.Content    = viewModel.Content;
            comment.DateEdited = DateTime.Now;

            if (ModelState.IsValid)
            {
                _db.Entry(comment).State = EntityState.Modified;
                _db.SaveChanges();
                return(RedirectToAction("Details", "Entry", new { Id = comment.EntryId }));
            }

            return(View(viewModel));
        }
        public ActionResult UpdateComment(int?id, int?postId)
        {
            ViewBag.Message = "Edit Comment";

            if (id.HasValue && postId.HasValue)
            {
                var comment = DbContext.Comments.FirstOrDefault(p => p.Id == id.Value);

                if (comment != null)
                {
                    var model = new EditCommentViewModel();

                    model.Body       = comment.Body;
                    model.EditReason = comment.UpdatedReason;

                    if (model.EditReason != null)
                    {
                        model.EditReason = comment.UpdatedReason;
                    }

                    return(View(model));
                }
            }
            return(RedirectToAction(nameof(BlogController.Index)));
        }
        public async Task <IActionResult> EditComment(EditCommentViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var currentUser = await this.userManager.GetUserAsync(this.User);

                var isInCommentRole = await this.commentsService.IsInCommentRole(currentUser, model.CommentId);

                if (!isInCommentRole)
                {
                    this.TempData["Error"] = ErrorMessages.InvalidInputModel;
                    return(this.RedirectToAction("Index", "Post", new { id = model.PostId }));
                }

                var isCommentIdCorrect = await this.commentsService.IsCommentIdCorrect(model.CommentId, model.PostId);

                if (!isCommentIdCorrect)
                {
                    this.TempData["Error"] = ErrorMessages.InvalidInputModel;
                    return(this.RedirectToAction("Index", "Post", new { id = model.PostId }));
                }

                Tuple <string, string> tuple = await this.commentsService.EditComment(model);

                this.TempData[tuple.Item1] = tuple.Item2;

                return(this.RedirectToAction("Index", "Post", new { id = model.PostId }));
            }

            this.TempData["Error"] = ErrorMessages.InvalidInputModel;
            return(this.RedirectToAction("Index", "Blog"));
        }
Beispiel #8
0
        public ActionResult Edit(EditCommentViewModel model)
        {
            if (!Request.IsAuthenticated)
            {
                throw new AuthenticationException();
            }

            if (!ModelState.IsValid)
            {
                return(View("editcomment", model));
            }

            var comment = DataService.PerThread.CommentSet.SingleOrDefault(x => x.Id == model.Id);

            if (comment == null)
            {
                throw new BusinessLogicException("Указан неверный идентификатор комментария");
            }

            if (comment.UserId != UserContext.Current.Id)
            {
                throw new BusinessLogicException("Нельзя редактировать чужие комментарии");
            }
            if (DateTime.Now - comment.DateTime > ConstHelper.CommentEditTimeSpan.Add(ConstHelper.CommentEditTimeSpan))
            {
                throw new BusinessLogicException("Время на редактирование вышло");
            }

            comment.Text = model.Text;

            DataService.PerThread.SaveChanges();

            return(Redirect(model.ReturnUrl));
        }
Beispiel #9
0
        public IActionResult EditComment(EditCommentViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            var presenter = _presenterFactory.Edit(MessageHandler, ErrorHandler);
            var request   = vm.ToRequest(CurrentUserId);

            try
            {
                var uc       = _useCaseFactory.EditComment;
                var response = uc.Execute(request);
                return(RedirectToAction(nameof(Index), new { id = presenter.Present(response) }));
            }
            catch (InvalidRequestException ire)
            {
                presenter.PresentErrors(ire.Message, ire.Errors);
                return(View(vm));
            }
            catch (Exception e)
            {
                presenter.PresentMessage(MessageType.Error, e.Message);
                return(View(vm));
            }
        }
Beispiel #10
0
 public async Task<Comment> Save(EditCommentViewModel model)
 {
     var currentUser = await _userService.GetCurrentUser();
     var comment = base.GetById(model.Id) ?? new Comment { CenterId = model.CenterId, UserId = currentUser.Id};
     comment.Message = model.Message;
     return base.AddOrUpdate(comment);
 }
        public ActionResult UpdateComment(int?id, int?postId, EditCommentViewModel formData)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            Comment comment;
            var     userId = User.Identity.GetUserId();
            var     post   = DbContext.Posts.FirstOrDefault(p => p.Id == postId);

            comment = DbContext.Comments.FirstOrDefault(p => p.Id == id);

            if (comment == null)
            {
                return(RedirectToAction(nameof(BlogController.Index)));
            }

            comment.UserId        = userId;
            comment.Body          = formData.Body;
            comment.DateUpdated   = DateTime.Now;
            comment.UpdatedReason = formData.EditReason;

            DbContext.SaveChanges();

            return(RedirectToAction(nameof(BlogController.PostDetails), routeValues: new { slug = post.Slug }));
        }
Beispiel #12
0
        public ActionResult Edit(int id, EditCommentViewModel formData)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            commentForSaving = DbContext.Comments.FirstOrDefault(
                p => p.Id == id);
            var post = DbContext.Posts.FirstOrDefault(p => p.Id == commentForSaving.PostId);

            commentForSaving.DateUpdated   = DateTime.Now;
            commentForSaving.Body          = formData.Body;
            commentForSaving.ReasonUpdated = formData.ReasonUpdated;

            if (commentForSaving == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.ExpectationFailed));
                //return RedirectToAction(nameof(CommentController.Index));
            }

            DbContext.SaveChanges();

            return(RedirectToAction(nameof(PostController.DetailBySlug), "Post", new { slug = post.Slug }));
        }
Beispiel #13
0
        public ActionResult Edit(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction(nameof(CommentController.Index)));
            }

            var comment = DbContext.Comments.FirstOrDefault(
                p => p.Id == id.Value);

            if (comment == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.ExpectationFailed));
            }

            var model = new EditCommentViewModel();

            model.Body          = comment.Body;
            model.ReasonUpdated = comment.ReasonUpdated;
            model.UserEmail     = comment.UserEmail;
            model.DateCreated   = comment.DateCreated;

            if (comment.DateUpdated != null)
            {
                model.DateUpdated = comment.DateUpdated;
            }

            return(View(model));
        }
Beispiel #14
0
        public async Task EditCommentNullComment()
        {
            EditCommentViewModel model = new EditCommentViewModel
            {
                CommentId = Guid.NewGuid().ToString(),
                Content   = "Test",
            };

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var mockUserManager = new Mock <UserManager <ApplicationUser> >(
                new Mock <IUserStore <ApplicationUser> >().Object,
                new Mock <IOptions <IdentityOptions> >().Object,
                new Mock <IPasswordHasher <ApplicationUser> >().Object,
                new IUserValidator <ApplicationUser> [0],
                new IPasswordValidator <ApplicationUser> [0],
                new Mock <ILookupNormalizer>().Object,
                new Mock <IdentityErrorDescriber>().Object,
                new Mock <IServiceProvider>().Object,
                new Mock <ILogger <UserManager <ApplicationUser> > >().Object);

            using (var db = new ApplicationDbContext(options))
            {
                ICommentService commentService = new CommentService(db, mockUserManager.Object);
                var             result         =
                    await commentService.EditComment(model);

                Assert.Equal(0, db.Comments.Count());
                Assert.Equal("Error", result.Item1);
                Assert.Equal(ErrorMessages.InvalidInputModel, result.Item2);
            }
        }
        public void EditComment(EditCommentViewModel p)
        {
            var comment = GetComment(p.Id);

            comment.Content = p.Content;

            _db.SaveChanges();
        }
        public ActionResult Edit(EditCommentViewModel _comment)
        {
            var comment = Mapper.Map <EditCommentViewModel, Comment>(_comment);

            db.Comments.Add(comment);
            db.Entry(comment).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Details", "Posts", new { id = comment.PostId }));
        }
        public async Task <OutCommentViewModel> Patch([FromBody] EditCommentViewModel comment)
        {
            var currentUser = CurrentUser();

            var dataModel       = _mapper.Map <EditCommentViewModel, Comment>(comment);
            var insertedComment = await _commentService.EditComment(dataModel, currentUser);

            return(_mapper.Map <Comment, OutCommentViewModel>(insertedComment));
        }
 public static EditCommentRequest ToRequest(this EditCommentViewModel vm, string userId)
 {
     return(new EditCommentRequest(userId)
     {
         WorkTaskId = Identity.FromString(vm.WorkTask.Id),
         CommentId = Identity.FromString(vm.CommentId),
         Content = vm.Content,
     });
 }
Beispiel #19
0
        public ActionResult EditComment(EditCommentViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            _commentService.UpdateComment(_mapper.Map <EditCommentViewModel, EditCommentDto>(model));

            return(RedirectToAction("AddComment"));
        }
Beispiel #20
0
        public async Task EditEventComment(EditCommentViewModel comment)
        {
            var userId   = _httpContextAccessor.HttpContext.User.GetClaim(JwtTypes.jti);
            var userRole = _httpContextAccessor.HttpContext.User.GetClaim(JwtTypes.Role);

            var user = await _userService.GetUserById(userId);

            var _comment = await _commentService.EditCommentAsync(comment, Guid.Parse(userId), userRole);

            await _commentService.Commit();
        }
        public ActionResult EditComment([Bind(Include = "ID,Content,CallbackId")] EditCommentViewModel comment)
        {
            if (ModelState.IsValid)
            {
                _postRepository.EditComment(comment);

                return(RedirectToAction("SinglePost", "Post", new { id = comment.CallbackId }));
            }
            ModelState.AddModelError("", "All fields should be filled!");
            return(View(comment));
        }
Beispiel #22
0
        public async Task <IActionResult> Save(EditCommentViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(nameof(Edit), model));
            }

            var savedComment = await _commentService.Save(model);

            return(RedirectToAction(nameof(PostComments), new { id = savedComment.CenterId }));
        }
Beispiel #23
0
 public EditCommentViewModel GetForEdit(int commentId)
 {
     var comment = base.GetById(commentId);
     var model = new EditCommentViewModel
     {
         Id = commentId,
         CenterId = comment.CenterId,
         Message = comment.Message
     };
     return model;
 }
Beispiel #24
0
        public async Task EditCommetAsync(EditCommentViewModel model)
        {
            var comment = this.GetComment(model.Id);

            if (comment != null)
            {
                comment.Content = model.Content;
            }

            await this.repository.SaveChangesAsync();
        }
Beispiel #25
0
 public ActionResult EditComment(EditCommentViewModel model)
 {
     if (ModelState.IsValid)
     {
         var comment = db.ApplicationComments.Find(model.Id);
         comment.Comment   = model.Comment;
         comment.ArticleId = model.ArticleId;
         comment.UserId    = User.Identity.GetUserId();
     }
     return(View(model));
 }
        public async Task <IActionResult> Edit(EditCommentViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            await this.service.EditCommetAsync(model);

            return(this.RedirectToAction("Index", "Home", new { area = string.Empty }));
        }
        public ActionResult EditComment(EditCommentViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            this.comments.UpdateComment(model.Id, model.Content);

            this.TempData["Notification"] = "You successfully update your comment.";
            return this.Redirect(this.Request.UrlReferrer.ToString());
        }
Beispiel #28
0
        public ActionResult EditComment(EditCommentViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            m_Comments.UpdateComment(model.Id, model.Content);

            TempData["Notification"] = "You successfully update your comment.";
            return(Redirect(Request.UrlReferrer.ToString()));
        }
        public EditCommentViewModel BuildEditCommentViewModel(int id)
        {
            var comment = _postRepository.GetComment(id);
            var model   = new EditCommentViewModel()
            {
                Id         = comment.Id,
                Content    = comment.Content,
                CallbackId = comment.PostId
            };

            return(model);
        }
Beispiel #30
0
        public async Task <IActionResult> EditPhotoComment(EditCommentViewModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }
            var photoId = this.commentsService.GetPhotoIdByCommentId(input.CommentId);
            var userId  = this.userManager.GetUserId(this.User);

            await this.commentsService.EditPhotoComment(input.CommentId, input.Content, userId);

            return(this.Redirect($"/Photos/Photo?id={photoId}"));
        }
Beispiel #31
0
        public void EditComment(EditCommentViewModel vm)
        {
            var comment = _db.Comments.SingleOrDefault(c => c.Id == vm.Id);

            if (comment == null)
            {
                throw new Exception("Can not find comment to edit!");
            }

            comment.Content = vm.Content;

            _db.SaveChanges();
        }
Beispiel #32
0
        public ActionResult Edit(EditCommentViewModel model)
        {
            if (!Request.IsAuthenticated)
                throw new AuthenticationException();

            if (!ModelState.IsValid)
                return View("editcomment", model);

            var comment = DataService.PerThread.CommentSet.SingleOrDefault(x => x.Id == model.Id);
            if (comment == null)
                throw new BusinessLogicException("Указан неверный идентификатор комментария");

            if (comment.UserId != UserContext.Current.Id)
                throw new BusinessLogicException("Нельзя редактировать чужие комментарии");
            if (DateTime.Now - comment.DateTime > ConstHelper.CommentEditTimeSpan.Add(ConstHelper.CommentEditTimeSpan))
                throw new BusinessLogicException("Время на редактирование вышло");

            comment.Text = model.Text;

            DataService.PerThread.SaveChanges();

            return Redirect(model.ReturnUrl);
        }