public async Task <AddEventResponse> AddEventAsync(EventDTO eventDTO) { var blobs = eventDTO.ImageByteArrayList.Select(bl => Convert.FromBase64String(Regex.Match(bl, @"data:image/(?<type>.+?),(?<data>.+)").Groups["data"].Value)).ToList(); var @event = _mapper.Map <EventDTO, Event>(eventDTO); await _contentProvider.UploadBlobs(@event, blobs); return(await _eventRepository.AddEventAsync(@event)); }
async Task IEventPublisher.PublishAsync <T>( T @event, Guid relatedEntityId, CancellationToken cancellationToken) { await _eventRepository.AddEventAsync(@event, relatedEntityId, cancellationToken); var handlers = _handlersFactory(typeof(T)).Cast <IEventHandler <T> >(); foreach (var handler in handlers) { await handler.HandleAsync(@event, cancellationToken); } }
public async Task <Guid> RunAsync(Guid userId, decimal initialDeposit) { User user = _dbRepository.Get <User>(userId); OpenAccountResult result = user.OpenAccount(initialDeposit); _dbRepository.Insert(result.Account); _dbRepository.Persist(); await _eventRepository.AddEventAsync(nameof(Account), result.Account.Id, result.Movement.Amount >= 0?EventType.Deposit : EventType.Withdraw, result.Movement); return(result.Account.Id); }
static async Task SeedData() { Guid accountId = Guid.NewGuid(); IEventRepository eventRepository = _serviceProvider.GetService <IEventRepository>(); Console.Clear(); for (int i = 0; i < ITEMS_TO_ADD; i++) { double d = (double)((((decimal)i + 1) / (decimal)ITEMS_TO_ADD) * 100); Console.SetCursorPosition(0, 0); Console.WriteLine($"Inserted {i + 1} of {ITEMS_TO_ADD} --> {Math.Round(d, 2)}% "); Movement movement = Movement.Create(accountId, GetRandomAmount(), $"Seed Movement {i}"); await eventRepository.AddEventAsync <Movement>(nameof(Account), accountId, EventType.GetByAmount(movement.Amount), movement); } }
public async Task <IActionResult> Post([FromBody] EventInsertDto eventInsertDto) { if (ModelState.IsValid) { try { var evt = _mapper.Map <Event>(eventInsertDto); if (evt != null) { await _eventRepository.AddEventAsync(evt); return(Ok()); } } catch (Exception e) { _logger.LogError($"An error occured while adding event {eventInsertDto} to database: {e}"); return(StatusCode(StatusCodes.Status500InternalServerError)); } } return(BadRequest($"An error occured while parsing request with parameters {eventInsertDto}")); }
public async Task <ActionResult <BasketLineDto> > Post(Guid basketId, [FromBody] CreateBasketLineModel basketLineForCreation) { if (!await _basketRepository.BasketExistsAsync(basketId)) { return(NotFound()); } if (!await _eventRepository.EventExistsAsync(basketLineForCreation.EventId)) { var eventFromCatalog = await _eventCatalogService.GetEventAsync(basketLineForCreation.EventId); await _eventRepository.AddEventAsync(eventFromCatalog); } var basket = new BasketLine { Price = basketLineForCreation.Price, TicketAmount = basketLineForCreation.TicketAmount, EventId = basketLineForCreation.EventId }; var processedLine = await _basketLineRepository.AddAsync(basketId, basket); return(Ok(processedLine)); }
public async Task <Event> AddEventAsync(Project projectInfo) { return(await _eventRepository.AddEventAsync(projectInfo)); }