public async Task <ICommandResult> Handle(EmailSmsSendCommand mesage) { try { if (string.IsNullOrEmpty(mesage.Id)) { throw new MessageException(ResourceKey.EmailSms_EmailSmsSendCommand_IsNotNullOrEmpty); } REmailSms emailSms = await _emailSmsService.GetFromDb(mesage.Id); if (emailSms == null) { throw new MessageException(ResourceKey.EmailSms_NotFound); } EmailSms emailOrSms = new EmailSms(emailSms); Ref <string> response = new Ref <string>(); bool isOk = false; if (emailOrSms.CheckMessageType(EnumDefine.EmailOrSmsMessageTypeEnum.Email)) { isOk = await _sendMailClient.Send(ConfigSettingEnum.AwsSenderAddress.GetConfig(), emailOrSms.Email, emailOrSms.Title, emailOrSms.Content, response); } if (emailOrSms.CheckMessageType(EnumDefine.EmailOrSmsMessageTypeEnum.Sms)) { //await _sendMailClient.Send(ConfigSettingEnum.AwsSenderAddress.GetConfig(), emailOrSms.Email, emailOrSms.Title, emailOrSms.Content); } if (isOk) { emailOrSms.SetSendSuccess(); } else { emailOrSms.SetSendFail(); } await _emailSmsService.ChangeToSendSuccess(emailOrSms.Id, emailOrSms.SendDate.GetValueOrDefault(), emailOrSms.Status, response.Value); ICommandResult result = new CommandResult() { Message = "", ObjectId = emailOrSms.Id, Status = CommandResult.StatusEnum.Sucess }; return(result); } catch (MessageException e) { e.Data["Param"] = mesage; ICommandResult result = new CommandResult() { Message = e.Message, Status = CommandResult.StatusEnum.Fail, ResourceName = e.ResourceName }; return(result); } catch (Exception e) { e.Data["Param"] = mesage; ICommandResult result = new CommandResult() { Message = e.Message, Status = CommandResult.StatusEnum.Fail }; return(result); } }
public async Task SendCommand(EmailSmsSendCommand command) { await _commandService.Send(command, false); }