public async Task <Dtos.V2.TextPieceResponceV2> Sort(string id, Dtos.V2.SortOption?sort) { var entity = await _repository.Get(id); if (entity == null) { return(null); } var paragraphs = DoSort(sort, entity.Paragraphs.Select(s => s.ParagraphText).ToArray()); entity.Paragraphs = paragraphs.Select(s => new TextParagraphEntity { ParagraphText = s }).ToList(); await _repository.SaveAsync(entity); var response = EntityMapper.ToV2Response(entity); return(response); }
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)); }