コード例 #1
0
 public async Task SaveAsync(TextPieceEntity entity)
 {
     using (var context = new DynamoDBContext(_dynamoDbClient))
     {
         await context.SaveAsync(entity);
     }
 }
コード例 #2
0
        public static TextStatisticsResponce ToStatisticsResponse(TextPieceEntity entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var result = new TextStatisticsResponce
            {
                Id              = entity.Id,
                AmountOfSpaces  = entity.Statistics.AmountOfSpaces,
                AmountOfWords   = entity.Statistics.AmountOfWords,
                AmountOfHyphens = entity.Statistics.AmountOfHyphens
            };

            return(result);
        }
コード例 #3
0
        public static TextPieceResponceV1 ToV1Response(TextPieceEntity entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var result = new TextPieceResponceV1
            {
                Id = entity.Id,

                CreatedAtUtc = entity.CreatedAtUtc.ToUniversalTime(),
                CreatedBy    = entity.CreatedBy,

                ModifiedAtUtc = entity.ModifiedAtUtc.ToUniversalTime(),
                ModifiedBy    = entity.ModifiedBy,

                TextFragment = string.Join(System.Environment.NewLine, entity.Paragraphs.Select(s => s.ParagraphText))
            };

            return(result);
        }
コード例 #4
0
        public static TextPieceResponceV2 ToV2Response(TextPieceEntity entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var result = new TextPieceResponceV2
            {
                Id = entity.Id,

                CreatedAtUtc = entity.CreatedAtUtc.ToUniversalTime(),
                CreatedBy    = entity.CreatedBy,

                ModifiedAtUtc = entity.ModifiedAtUtc.ToUniversalTime(),
                ModifiedBy    = entity.ModifiedBy,

                Paragraphs = entity.Paragraphs.Select(s => s.ParagraphText).ToArray()
            };

            return(result);
        }
コード例 #5
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));
        }
コード例 #6
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));
        }
コード例 #7
0
 public Task SaveAsync(TextPieceEntity entity)
 {
     _items[entity.Id] = entity;
     return(Task.CompletedTask);
 }