Example #1
0
        public async Task <Guid> Handle(CreateEventCommand request, CancellationToken cancellationToken)
        {
            var validator        = new CreateEventCommandValidator(_eventRepository);
            var validationResult = await validator.ValidateAsync(request);

            if (validationResult.Errors.Count > 0)
            {
                throw new Exceptions.ValidationException(validationResult);
            }

            var @event = _mapper.Map <Event>(request);

            @event = await _eventRepository.AddAsync(@event);

            //Sending email notification to admin address
            var email = new Email()
            {
                To = "*****@*****.**", Body = $"A new event was created: {request}", Subject = "A new event was created"
            };

            try
            {
                await _emailService.SendEmail(email);
            }
            catch (Exception ex)
            {
                //this shouldn't stop the API from doing else so this can be logged
                //_logger.LogError($"Mailing about event {@event.EventId} failed due to an error with the mail service: {ex.Message}");
            }

            return(@event.EventId);
        }
Example #2
0
        public async Task <Guid> Handle(CreateEventCommand request, CancellationToken cancellationToken)
        {
            var validator        = new CreateEventCommandValidator();
            var validationResult = await validator.ValidateAsync(request);

            if (validationResult.Errors.Count > 0)
            {
                throw new Exceptions.ValidationException(validationResult);
            }

            var @event = _mapper.Map <Event>(request);

            @event = await _eventRepository.AddAsync(@event);

            return(@event.EventId);
        }