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); var email = new Email { To = "*****@*****.**", Subject = $"A new event was created: {request}", Body = $"A new event was created: {request}" }; try { await emailService.SendEmail(email); } catch (Exception) { throw; } return(@event.EventId); }
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); }
public async Task <Guid> Handle(CreateEventCommand request, CancellationToken cancellationToken) { var validator = new CreateEventCommandValidator(_eventRepository); var validationResult = await validator.ValidateAsync(request); if (validationResult.Errors.Any()) { throw new ValidationException(validationResult); } var @event = _mapper.Map <Event>(request); @event = await _eventRepository.AddAsync(@event); var email = new Email { To = "*****@*****.**", Subject = "Event Notification", Body = $"{request} was created" }; try { await _emailService.SendEmail(email); } catch (Exception) { // app shouldn't stop } return(@event.EventId); }
public async Task <Guid> Handle(CreateEventCommand request, CancellationToken cancellationToken) { var validator = new CreateEventCommandValidator(_eventRepository); var validatorResult = await validator.ValidateAsync(request); if (validatorResult.Errors.Count > 0) { throw new Exceptions.ValidationExecption(validatorResult); } var @event = _mapper.Map <Event>(request); @event = await _eventRepository.AddAsync(@event); 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) { } return(@event.EventId); }
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); var email = new Email() { To = "*****@*****.**", Subject = "A new event was created!", Body = $"A new event was created: {request}" }; try { await _emailService.SendEmailAsync(email); } catch (Exception ex) { //this should't stop the API from doind else so this can be logged } return(@event.EventId); }
public async Task <Guid> Handle(CreateEventCommand request, CancellationToken cancellationToken) { var validator = new CreateEventCommandValidator(eventRepository); var validatorResult = await validator.ValidateAsync(request); if (validatorResult.Errors.Count > 0) { throw new Exceptions.ValidationException(validatorResult); } var @event = mapper.Map <Event>(request); @event = await eventRepository.AddAsync(@event); return(@event.EventId); }