public async Task HandleAsync(CreateEntry command)
        {
            _logger.LogInformation($"Creating entry: '{command.Id}' for user: '******'.");
            try
            {
                await _entryService.AddAsync(command.Id, command.UserId,
                                             command.Currency, command.Timeframe, command.Indicators,
                                             command.Name, command.Description, command.CreatedAt);

                await _busClient.PublishAsync(new EntryCreated(command.Id, command.UserId,
                                                               command.Currency, command.Timeframe, command.Indicators,
                                                               command.Name, command.Description, command.CreatedAt));

                _logger.LogInformation($"Entry: '{command.Id}' was created for user: '******'.");

                return;
            }
            catch (EntrioException ex)
            {
                _logger.LogError(ex, ex.Message);
                await _busClient.PublishAsync(new CreateEntryRejected(command.Id,
                                                                      ex.Message, ex.Code));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                await _busClient.PublishAsync(new CreateEntryRejected(command.Id,
                                                                      ex.Message, "error"));
            }
        }
示例#2
0
        public async Task <ActionResult <EntryDto> > AddEntry(AddEntry entry)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (userId is null)
            {
                return(BadRequest(new ErrorDto("No user data!")));
            }

            return(await _entryService.AddAsync(entry.Text, userId));
        }
示例#3
0
 public async Task AddAsync(EntryViewModel model)
 {
     await _entryService.AddAsync(_mapper.Map <Entry>(model));
 }