Exemplo n.º 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 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);
        }
Exemplo n.º 2
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);

            return(@event.EventId);
        }
Exemplo n.º 3
0
        public async Task <Guid> Handle(CreateEventCommand request, CancellationToken cancellationToken)
        {
            CreateEventCommandValidator 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); //request'ten Event'a gitmek istiyorum.

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

            return(@event.EventId); //yeni oluşturduğum olayın Guid'ini geri döndürüyorum.
        }
Exemplo n.º 4
0
        public async Task <Guid> Handle(CreateEventCommand request, CancellationToken cancellationToken)
        {
            var validator      = new CreateEventCommandValidator(_eventRepository);
            var validateResult = await validator.ValidateAsync(request);

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

            var email = new Email();

            try
            {
                await _emailService.SendEmail(email);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(Guid.Empty);
        }