예제 #1
0
        public async Task <IActionResult> Edit(CommentEditDto dto)
        {
            var comment = await _commentService.GetByIdAsync(dto.Id);

            comment.Data.IsActive = true;
            await _commentService.UpdateAsync(comment.Data);

            return(RedirectToAction("Index", "Comment", new { area = "Admin" }));
        }
예제 #2
0
        protected virtual async Task Update(CommentEditDto input)
        {
            //TODO:更新前的逻辑判断,是否允许更新

            var entity = await _commentRepository.GetAsync(input.Id.Value);

            //  input.MapTo(entity);
            //将input属性的值赋值到entity中
            ObjectMapper.Map(input, entity);
            await _commentManager.UpdateAsync(entity);
        }
예제 #3
0
        protected virtual async Task <CommentEditDto> Create(CommentEditDto input)
        {
            //TODO:新增前的逻辑判断,是否允许新增

            var entity = ObjectMapper.Map <Comment>(input);

            entity.Id = SequentialGuidGenerator.Instance.Create();

            //调用领域服务
            entity = await _commentManager.CreateAsync(entity);

            var dto = ObjectMapper.Map <CommentEditDto>(entity);

            return(dto);
        }
예제 #4
0
        public async Task EditAsync_WithInvalidCommentId_ShouldEditCommentAndReturnTrue()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.commentsService = new CommentsService(context);

            CommentEditDto expectedResult = (await context.Comments.FirstAsync()).To <CommentEditDto>();

            expectedResult.ModifiedOn  = DateTime.UtcNow;
            expectedResult.Description = "New description when edited";
            expectedResult.Id          = "Invalid Id";

            var ex = await Assert.ThrowsAsync <NullReferenceException>(() => this.commentsService.EditAsync(expectedResult));

            Assert.Equal(string.Format(ErrorMessages.CommentIdNullReference, expectedResult.Id), ex.Message);
        }
예제 #5
0
        public async Task <GetCommentForEditOutput> GetForEdit(NullableIdDto <Guid> input)
        {
            var            output = new GetCommentForEditOutput();
            CommentEditDto editDto;

            if (input.Id.HasValue)
            {
                var entity = await _commentRepository.GetAsync(input.Id.Value);

                editDto = ObjectMapper.Map <CommentEditDto>(entity);
            }
            else
            {
                editDto = new CommentEditDto();
            }



            output.Comment = editDto;
            return(output);
        }
예제 #6
0
        public async Task EditAsync_WithValidData_ShouldEditCommentAndReturnTrue()
        {
            string errorMessagePrefix = "CommentsService EditAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.commentsService = new CommentsService(context);

            CommentEditDto expectedResult = (await context.Comments.FirstAsync()).To <CommentEditDto>();

            expectedResult.ModifiedOn  = DateTime.UtcNow;
            expectedResult.Description = "New description when edited";

            await this.commentsService.EditAsync(expectedResult);

            var actualResult = (await context.Comments.FirstAsync()).To <CommentEditDto>();

            Assert.True(expectedResult.ModifiedOn == actualResult.ModifiedOn, errorMessagePrefix + " " + "ModifiedOn is not created properly.");
            Assert.True(expectedResult.Description == actualResult.Description, errorMessagePrefix + " " + "Description is not changed properly.");
        }
예제 #7
0
        public virtual async Task<CommentModel> UpdateAsync(CommentEditDto dto)
        {
            var comment = await _commentsRepository.GetAsync(dto.Id);
            var commentLinkPreview = _commentLinkPreviewService.GetCommentsLinkPreviewAsync(comment.Id);

            comment.ModifyDate = DateTime.UtcNow;
            comment.Text = dto.Text;

            await _commentsRepository.UpdateAsync(comment);

            if (dto.LinkPreviewId.HasValue)
            {
                if (commentLinkPreview?.Id != dto.LinkPreviewId)
                {
                    await _commentLinkPreviewService.UpdateLinkPreviewAsync(dto.Id, dto.LinkPreviewId.Value);
                }
            }
            else
            {
                await _commentLinkPreviewService.RemovePreviewRelationsAsync(dto.Id);
            }

            return comment.Map<CommentModel>();
        }
예제 #8
0
        public virtual CommentModel Update(CommentEditDto dto)
        {
            var comment = _commentsRepository.Get(dto.Id);
            var commentLinkPreview = _commentLinkPreviewService.GetCommentsLinkPreview(comment.Id);

            comment.ModifyDate = DateTime.UtcNow;
            comment.Text = dto.Text;

            _commentsRepository.Update(comment);

            if (dto.LinkPreviewId.HasValue)
            {
                if (commentLinkPreview?.Id != dto.LinkPreviewId)
                {
                    _commentLinkPreviewService.UpdateLinkPreview(dto.Id, dto.LinkPreviewId.Value);
                }
            }
            else
            {
                _commentLinkPreviewService.RemovePreviewRelations(dto.Id);
            }

            return comment.Map<CommentModel>();
        }
예제 #9
0
 public EditCommentCommand(ISingleLinkedList <ContextData> context, CommentEditDto editDto) : base(context)
 {
     EditDto = editDto;
 }
예제 #10
0
 public EditCommentCommand(Guid targetId, Enum targetType, CommentEditDto editDto) : base(targetId, targetType)
 {
     EditDto = editDto;
 }