//[ValidModel]
        public async Task <IActionResult> CommentAdd(CommentAddDto commentAddDto)
        {
            commentAddDto.PostedTime = DateTime.Now;
            await _commentService.AddAsync(_mapper.Map <Comment>(commentAddDto));

            return(Created("", commentAddDto));
        }
        public async Task <JsonResult> Add(CommentAddDto commentAddDto)
        {
            if (ModelState.IsValid)
            {
                var result = await _commentService.AddAsync(commentAddDto);

                if (result.ResultStatus == ResultStatus.Success)
                {
                    var commentAddAjaxViewModel = JsonSerializer.Serialize(new CommentAddAjaxViewModel
                    {
                        CommentDto        = result.Data,
                        CommentAddPartial = await this.RenderViewToStringAsync("_CommentAddPartial", commentAddDto)
                    }, new JsonSerializerOptions
                    {
                        ReferenceHandler = ReferenceHandler.Preserve
                    });
                    return(Json(commentAddAjaxViewModel));
                }
                ModelState.AddModelError("", result.Message);
            }
            var commentAddAjaxErrorModel = JsonSerializer.Serialize(new CommentAddAjaxViewModel
            {
                CommentAddDto     = commentAddDto,
                CommentAddPartial = await this.RenderViewToStringAsync("_CommentAddPartial", commentAddDto)
            });

            return(Json(commentAddAjaxErrorModel));
        }
Beispiel #3
0
        public async Task <IActionResult> AddComment(CommentAddDto model)
        {
            model.PostedTime = DateTime.Now;
            await _commentService.AddAsync(_mapper.Map <Comment>(model));

            return(RedirectToAction("Detail", new { id = model.BlogId }));
        }
Beispiel #4
0
        public async Task <IActionResult> CreateComment([FromQuery] CommentAddDto commentAddDto)
        {
            commentAddDto.CommentDate = DateTime.Now;
            await _commentService.AddAsync(_mapper.Map <Comment>(commentAddDto));

            return(Created("", commentAddDto));
        }
Beispiel #5
0
        public IResult Add(CommentAddDto commentAddDto)
        {
            var comment      = _mapper.Map <Comment>(commentAddDto);
            var addedComment = _unitOfWork.Comment.Add(comment);

            _unitOfWork.Save();
            return(new Result(ResultStatus.Success, $"{addedComment.Text} adlı yorum başarı ile eklenmiştir"));
        }
 public async Task <IActionResult> AddComment(CommentAddDto model)
 {
     if (ModelState.IsValid)
     {
         await _commentService.AddAsync(model.Adapt <Comment>());
     }
     return(RedirectToAction("Detail", "Home", new { id = model.ArticleId }));
 }
Beispiel #7
0
        public async Task <IDataResult <CommentDto> > AddAsync(CommentAddDto commentAddDto)
        {
            var comment      = Mapper.Map <Comment>(commentAddDto);
            var addedComment = await UnitOfWork.Comments.AddAsync(comment);

            await UnitOfWork.SaveAsync();

            return(new DataResult <CommentDto>(ResultStatus.Success, Messages.Comment.Add(commentAddDto.CreatedByName), new CommentDto
            {
                Comment = addedComment,
            }));
        }
Beispiel #8
0
        public async Task <IActionResult> AddComment(CommentAddDto commentAddDto)
        {
            if (commentAddDto.AuthorName.Contains("Admin") || commentAddDto.AuthorName.Contains("admin"))
            {
                commentAddDto.AuthorName = "ÇakalKarlos";
            }

            commentAddDto.PostedTime = DateTime.Now;
            commentAddDto.IsApproved = false;
            await _commentService.AddAsync(_mapper.Map <Comment>(commentAddDto));

            return(Created("", commentAddDto));
        }
Beispiel #9
0
        public async Task <IActionResult> AddComment(CommentAddDto commentAddDto)
        {
            var result = await _articleService.Get(commentAddDto.ArticleId);

            var article = result.Data.Article;

            if (ModelState.IsValid)
            {
                var createdName = commentAddDto.FirstName + commentAddDto.LastName;
                await _commentService.Add(commentAddDto, createdName);

                return(RedirectToAction("BlogDetail", new { name = SeoHelper.ToSeoUrl(article.Title), id = article.Id }));
            }
            return(RedirectToAction("BlogDetail", new { name = SeoHelper.ToSeoUrl(article.Title), id = article.Id }));
        }
Beispiel #10
0
        public async Task <IDataResult <CommentDto> > Add(CommentAddDto commentAddDto, string createdByName)
        {
            var comment = _mapper.Map <Comment>(commentAddDto);

            comment.CreatedByName  = createdByName;
            comment.ModifiedByName = createdByName;
            comment.ModifiedTime   = DateTime.Now;
            var addedComment = await _unitOfWork.Comment.AddAsync(comment);

            await _unitOfWork.SaveAsync();

            return(new DataResult <CommentDto>(ResultStatus.Success, "İşlem başarılı..", new CommentDto
            {
                Comment = addedComment,
                Message = "İşlem başarılı..",
                ResultStatus = ResultStatus.Success
            }));
        }
        public async Task <IDataResult <CommentDto> > AddAsync(CommentAddDto commentAddDto)
        {
            var article = await UnitOfWork.Articles.GetAsync(a => a.Id == commentAddDto.ArticleId);

            if (article == null)
            {
                return(new DataResult <CommentDto>(ResultStatus.Error, Messages.Article.NotFound(isPlural: false), null));
            }
            var comment      = Mapper.Map <Comment>(commentAddDto);
            var addedComment = await UnitOfWork.Comments.AddAsync(comment);

            article.CommentCount += 1;
            await UnitOfWork.Articles.UpdateAsync(article);

            await UnitOfWork.SaveAsync();

            return(new DataResult <CommentDto>(ResultStatus.Success, Messages.Comment.Add(commentAddDto.CreatedByName), new CommentDto
            {
                Comment = addedComment,
            }));
        }
Beispiel #12
0
        /// <summary>
        /// 新增评论
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <CommonResultDto <string> > Post(CommentAddDto dto)
        {
            tbl_comment tbl = new tbl_comment
            {
                Id              = Guid.NewGuid().ToString(),
                BlogId          = dto.BlogId,
                Content         = dto.Content,
                From            = dto.From,
                To              = dto.To,
                CurrentFloorNum = dto.CurrentFloorNum,
                ToFloorNum      = dto.ToFloorNum,
                CreateAt        = DateTime.Now,
                LikeTimes       = 0
            };
            await _context.tbl_comment.AddAsync(tbl);

            await _context.SaveChangesAsync();

            return(new CommonResultDto <string> {
                Msg = "新增成功", Success = true
            });
        }
        public async Task <IDataResult <CommentDto> > AddAsync(CommentAddDto commentAddDto)
        {
            var post = await UnitOfWork.Posts.GetAsync(p => p.Id == commentAddDto.PostId);

            if (post == null)
            {
                return(new DataResult <CommentDto>(ResultStatus.Error, Messages.Comment.NotFound(false),
                                                   null));
            }
            var comment      = Mapper.Map <Comment>(commentAddDto);
            var addedComment = await UnitOfWork.Comments.AddAsync(comment);

            post.CommentCount += 1;
            await UnitOfWork.Posts.UpdateAsync(post);

            await UnitOfWork.SaveAsync();

            return(new DataResult <CommentDto>(ResultStatus.Success, Messages.Comment.Add(commentAddDto.CreatedByName), new CommentDto
            {
                Comment = addedComment,
            }));
        }
Beispiel #14
0
        public async Task <IActionResult> Add(CommentAddDto commentAddDto)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new JResult
                {
                    Status = Status.BadRequest,
                    Message = "Eksik veya hatalı kayıtlar mevcut!"
                }));
            }


            var comment = _mapper.Map <Comment>(commentAddDto);

            await _commentService.AddAsync(comment);

            try
            {
                var userInDb = await _userManager.FindByNameAsync("admin");

                var body = new StringBuilder();
                body.AppendLine($"Ad Soyad:  {commentAddDto.Name}");
                body.AppendLine($"<br />");
                body.AppendLine($"Email: {commentAddDto.EmailAdress}");
                body.AppendLine($"<br />");
                body.AppendLine($"Mesaj : {commentAddDto.Content}");
                SendMail.MailSender($"BerendBebe - Yeni Yorum", body.ToString(), userInDb.Email);
            }
            catch (Exception)
            {
            }

            return(Json(new JResult
            {
                Status = Status.Ok,
                Message = "Yorumunuz alınmıştır. Değerlendikten sonra onaylanacaktır."
            }));
        }
Beispiel #15
0
 public IActionResult AddComment([FromForm] CommentAddDto commentDto)
 {
     commentDto.CommentDate = DateTime.Now;
     _commentService.Add(_mapper.Map <Comment>(commentDto));
     return(Created("", commentDto));
 }
Beispiel #16
0
 public async Task <CommonResultDto <string> > Post([FromBody] CommentAddDto dto)
 {
     return(await _commentService.Post(dto));
 }