| | 1 | | using System.Threading.Tasks; |
| | 2 | | using ApplicationCore.Analytics; |
| | 3 | | using Microsoft.AspNetCore.Http; |
| | 4 | |
|
| | 5 | | namespace ApplicationCore.Model |
| | 6 | | { |
| | 7 | | public class CommentFactory : ICommentFactory |
| | 8 | | { |
| | 9 | | private readonly ICommentFormFactory _commentFormFactory; |
| | 10 | | private readonly ITextAnalyzer _textAnalyzer; |
| | 11 | |
|
| 4 | 12 | | public CommentFactory(ICommentFormFactory commentFormFactory, ITextAnalyzer textAnalyzer) |
| 4 | 13 | | { |
| 4 | 14 | | _commentFormFactory = commentFormFactory; |
| 4 | 15 | | _textAnalyzer = textAnalyzer; |
| 4 | 16 | | } |
| | 17 | |
|
| | 18 | | public async Task<CommentResult> CreateFromFormAsync(IFormCollection form) |
| 2 | 19 | | { |
| 2 | 20 | | var commentForm = _commentFormFactory.CreateCommentForm(form); |
| 2 | 21 | | var commentResult = commentForm.TryCreateComment(); |
| | 22 | |
|
| 2 | 23 | | if (!commentForm.HasErrors) |
| 1 | 24 | | { |
| 1 | 25 | | commentResult = await _textAnalyzer.AnalyzeAsync(commentResult.Comment).ConfigureAwait(false); |
| 1 | 26 | | } |
| | 27 | |
|
| 2 | 28 | | return commentResult; |
| 2 | 29 | | } |
| | 30 | | } |
| | 31 | | } |