public async Task <EmailViewModel> Post(Guid contactId, [FromBody] EmailViewModel model) { _logger.LogInformation($"add.email contact: {contactId}"); AssertValidIds(contactId); var data = _mapper.Map <Email>(model); var saved = await _repository.CreateAsync(contactId, data); _logger.LogInformation($"added.email contact: {contactId} record: {saved.Id}"); return(_mapper.Map <EmailViewModel>(saved)); }
public override async Task <Guid> Handle(SendMailCommand request, CancellationToken cancellationToken) { if (!this.CommandIsValid(request)) { return(Guid.Empty); } try { var project = _projectRepository.GetByApiKey(request.ProjectApiKey); if (project == null) { _validationService.AddErrors("01", "Projeto nao encontrado para a APIKEY informado"); return(Guid.Empty); } var template = await _templateRepository.GetByIDAsync(request.TemplateID); if (template == null) { _validationService.AddErrors("02", "Informe um template para o e-mail"); return(Guid.Empty); } string body = template.MailTemplate; foreach (var key in request.KeyValues) { body = body.Replace(key.Key, key.Value); } var email = new Email(new EmailVO(request.To), new EmailVO(template.MailFrom), body, project, template.Subject); await _emailRepository.CreateAsync(email); await _uow.CommitAsync(); await this.SendMail(email); } catch (DomainException dx) { _validationService.AddErrors("EX", dx.Message); } return(Guid.Empty); }