public async Task <int> SubmitCommentAsync(CommentDTOin comment) { bool recipeExists = await recipeRepo.All().AnyAsync(x => x.Id == comment.RecipeId && !x.IsDeleted); if (!recipeExists) { throw new ArgumentOutOfRangeException("Recipe not found!"); } RecipeComment new_comment = mapper.Map <RecipeComment>(comment); await this.commentRepo.AddAssync(new_comment); await this.commentRepo.SaveChangesAsync(); return(new_comment.Id); }
public async Task <ActionResult <int> > SubmitComment(CommentDTOin comment) { try { if (comment.AuthorId != UserId) { throw new ArgumentOutOfRangeException("Invalid User Credentials!"); } int newId = await this.commentService.SubmitCommentAsync(comment); return(newId); } catch (ArgumentOutOfRangeException ex) { return(BadRequest(new { reason = ex.Message })); } }