public async Task <string> AddComment(ComentInsertDto coment) { var places = await TuristPlaceRepository.GetAll(); var place = places.Find(p => p.Id == coment.TuristPlace); try { var user = await userManager.FindByIdAsync(coment.UserId); CommentRepository.Insert(new Comment() { RecordDate = DateTime.Now, Text = coment.comment, TuristPlaceId = place.Id, UserId = user.Id }); await CommentRepository.Save(); return("we add your comment ."); } catch { throw new KeyNotFoundException("not found this user"); } }
public async Task <IActionResult> CreateComment([FromBody] ComentInsertDto coment) { if (!ModelState.IsValid) { return(BadRequest()); } var result = await CommentServise.AddComment(coment); return(Ok(result)); }