public IActionResult Create([FromBody] CreateReplyViewModel postReplyToCreate) { var reply = new PostReply(); var identity = (ClaimsIdentity)User.Identity; IEnumerable <Claim> claims = identity.Claims; reply.Content = postReplyToCreate.Content; reply.Post.Id = postReplyToCreate.PostId; reply.User.Id = int.Parse(claims.ElementAt(2).Value); _postReply.Create(reply); return(View()); }
public async Task <IActionResult> CreateReply(long id, [FromBody] CreateReplyViewModel vm) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.Select(v => v.Errors))); } var topicExist = await _topicsRepository.Contains(vm.TopicId); var userExist = await _topicsRepository.Contains(vm.UserId); if (topicExist) { var reply = _mapper.Map <Reply>(vm); await _repliesRepository.AddAsync(reply); return(Ok()); } return(BadRequest()); }