public async Task <IActionResult> Create([FromBody] CreateMemoRequestV1 memo) { try { var response = await _facade.Create(memo); return(CreatedAtAction(nameof(GetById), new { id = response.Id }, response)); } catch (Exception exception) { #if DEBUG return(StatusCode(500, exception.ToString())); #else var errorId = _newIdGenerator.Generate(); return(StatusCode(500, $"Failed to process request. Error code {errorId}")); #endif } }
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)); }