Exemplo n.º 1
0
        public async Task <TextPieceResponceV1> Create(CreateMemoRequestV1 request)
        {
            var id         = _newIdGenerator.Generate();
            var paragraphs = request.TextFragment.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                             .Select(s => new TextParagraphEntity {
                ParagraphText = s
            })
                             .ToList();
            var textStatistics = _textStatisticsCalculator.CalculateStatistics(paragraphs);
            var entity         = new TextPieceEntity
            {
                Id            = id,
                Paragraphs    = paragraphs,
                Statistics    = textStatistics,
                CreatedAtUtc  = DateTime.UtcNow,
                ModifiedAtUtc = DateTime.UtcNow
            };

            await _repository.SaveAsync(entity);

            return(EntityMapper.ToV1Response(entity));
        }
Exemplo n.º 2
0
        public async Task <Dtos.V2.TextPieceResponceV2> Create(Dtos.V2.CreateMemoRequestV2 request)
        {
            var id             = _newIdGenerator.Generate();
            var textParagraphs = request.Paraagraphs.Select(s => s.ParagraphText).ToArray();

            textParagraphs = DoSort(request.Sort, textParagraphs).ToArray();
            var paragraphs = textParagraphs.Select(s => new TextParagraphEntity {
                ParagraphText = s
            }).ToList();
            var textStatistics = _textStatisticsCalculator.CalculateStatistics(paragraphs);
            var entity         = new TextPieceEntity
            {
                Id            = id,
                Paragraphs    = paragraphs,
                Statistics    = textStatistics,
                CreatedAtUtc  = DateTime.UtcNow,
                ModifiedAtUtc = DateTime.UtcNow
            };

            await _repository.SaveAsync(entity);

            return(EntityMapper.ToV2Response(entity));
        }