コード例 #1
0
        public async Task <IActionResult> Post([FromBody] CreateEvent command)
        {
            command.EventId = Guid.NewGuid();
            await _eventService.CreateAsync(command.EventId, command.Name, command.Description, command.StartDate, command.EndDate);

            await _eventService.AddTicketAsync(command.EventId, command.Tickets, command.Price);

            return(Created($"/events/{command.EventId}", null));
        }
コード例 #2
0
 private void SeedEvents(IList <Task> tasks, int numberOfEvents, int numberOfTicketsInEvent)
 {
     for (int i = 0; i < numberOfEvents; i++)
     {
         Guid     eventId          = Guid.NewGuid();
         string   eventName        = $"Event {i}";
         string   eventDescription = $"{eventName} description.";
         DateTime startDate        = DateTime.UtcNow.AddHours(3);
         tasks.Add(_eventService.CreateAsync(
                       eventId, eventName, eventDescription,
                       startDate, startDate.AddHours(2)
                       )
                   );
         tasks.Add(_eventService.AddTicketAsync(eventId, numberOfTicketsInEvent, 100));
     }
 }
コード例 #3
0
        public async Task <IActionResult> Post([FromBody]
                                               CreateEventCommand createEventCommand)
        {
            try {
                Guid eventId = Guid.NewGuid();
                await _eventService.CreateAsync(
                    eventId, createEventCommand.Name, createEventCommand.Description,
                    createEventCommand.StartDate, createEventCommand.EndDate
                    );

                await _eventService.AddTicketAsync(
                    eventId, createEventCommand.TicketsCount, createEventCommand.Price
                    );

                return(Created($"/event/{eventId}", null));
            } catch (Exception e)
                when(e is EventAlreadyExistsException || e is EventNotFoundException)
                {
                    return(NotFound());
                }
        }
コード例 #4
0
        public async Task SeedAsync()
        {
            Logger.Info("Inicjalizacja danych...");
            var tasks = new List <Task>();

            tasks.Add(_userService.RegisterAsync(Guid.NewGuid(), "*****@*****.**", "default", "secret"));
            tasks.Add(_userService.RegisterAsync(Guid.NewGuid(), "*****@*****.**", "default", "secret", "admin"));
            Logger.Info("Utworzeni: user, admin");
            for (var i = 0; i < 11; i++)
            {
                var eventId     = Guid.NewGuid();
                var name        = $"Wydarzenie {i}";
                var description = $"{name} opis.";
                var startDate   = DateTime.UtcNow.AddHours(3);
                var endDate     = startDate.AddHours(2);
                tasks.Add(_eventService.CreateAsync(eventId, name, description, startDate, endDate));
                tasks.Add(_eventService.AddTicketAsync(eventId, 1000, 100));
                Logger.Info($"Utworzono: {name}");
            }
            await Task.WhenAll(tasks);

            Logger.Info("Zainicjalzowano dane wstepne.");
        }
コード例 #5
0
        public async Task SeedAsync()
        {
            logger.Info("Initializing data");
            var tasks = new List <Task>();

            tasks.Add(_userService.RegisterAsync(Guid.NewGuid(), "*****@*****.**", "deafultuser", "secret"));
            tasks.Add(_userService.RegisterAsync(Guid.NewGuid(), "*****@*****.**", "admin", "secret", "admin"));
            logger.Info("Created users");

            for (int i = 0; i < 10; i++)
            {
                var eventId     = Guid.NewGuid();
                var name        = $"Event {i}";
                var description = name;
                var startDate   = DateTime.UtcNow.AddHours(i);
                var endDate     = startDate.AddHours(3);

                tasks.Add(_eventSerice.CreateAync(eventId, name, description, startDate, endDate));
                tasks.Add(_eventSerice.AddTicketAsync(eventId, 100, 100));
            }

            await Task.WhenAll(tasks);
        }
コード例 #6
0
 public async Task Handle(AddEventCommand notification, CancellationToken cancellationToken)
 {
     await _eventService.CreateAync(notification.Command.EventId, notification.Command.Name, notification.Command.Description, notification.Command.StartDate, notification.Command.EndDate);
     await _eventService.AddTicketAsync(notification.Command.EventId, notification.Command.Tikets, notification.Command.Price);
 }