public async Task <IActionResult> CreateReply(CreateReplyDto input) { var token = GetToken(); var userId = LoginHelper.GetClaim(token, "UserId"); if (input.UserId != Guid.Parse(userId)) { return(Unauthorized()); } var reply = await _replyAppService.CreateReply(input); bool status = reply.Id != Guid.Empty; return(Ok(new{ status })); }
public async Task <long> CreateReply(CreateReplyDto model) { if (model != null) { var createReply = new Reply { ReplyBody = model.ReplyBody, CreatedOn = model.CreatedOn, Author = model.Author, CommentID = model.CommentID }; await _skinHubAppDbContext.AddAsync(createReply); await _skinHubAppDbContext.SaveChangesAsync(); return(createReply.ID); } return(0); }
public async Task <Reply> CreateReply(CreateReplyDto input) { var reply = new Reply { Content = input.Content, UserId = input.UserId, CommentId = input.CommentId }; if (input.ParentId != null) { reply.ParentId = input.ParentId; } await _replyRepository.AddAsync(reply); var user = await _userRepository.GetByIdAsync(input.UserId); var comment = await _commentRepository.GetByIdAsync(input.CommentId); var post = await _postRepository.GetByIdAsync(comment.PostId); var community = await _communityRepository.GetByIdAsync(post.CommunityId); if (comment.UserId == user.Id) { return(reply); } var notify = new Notification { Content = user.Username + " " + "yorumuna yanıt verdi: " + input.Content, OwnerUserId = comment.UserId, Type = NotifyContentType.CommentReply, TargetName = community.Slug + "/" + post.Slug, ImgPath = user.ProfileImagePath, TargetId = post.Id }; await _notificationRepository.AddAsync(notify); return(reply); }
public async Task <IActionResult> Create([FromBody] CreateReplyDto model) { try { if (ModelState.IsValid) { var checkName = await _replyServices.IsNameExist(model.ReplyBody, model.CommentID); if (checkName == true) { return(BadRequest("Sorry!, This name already exists on our database. Choose another name")); } var createReply = await _replyServices.CreateReply(model); return(StatusCode(201, $"Reply created Successfully.")); } return(BadRequest("Sorry! Your task cannot be completed")); } catch (Exception ex) { return(BadRequest($"{ex.Message}, Error! Your task failed, Please try again")); } }