public async Task <EmailOrSmsGetResponse> GetDetail(EmailOrSmsGetRequest request) { EmailOrSmsGetResponse response = new EmailOrSmsGetResponse(); try { if (!string.IsNullOrEmpty(request.Id)) { var emailSms = await _emailSmsService.GetFromDb(request.Id); if (emailSms == null) { response.SetFail(BaseResponse.ErrorCodeEnum.EmailNotFound); return(response); } response.EmailSms = emailSms.ToModel(); foreach (var messageType in response.MessageTypes) { messageType.Checked = response.EmailSms.MessageType.HasFlag((EnumDefine.EmailOrSmsMessageTypeEnum)messageType.Id); } } } catch (Exception e) { response.SetFail(e); _logger.LogError(e, e.Message, request); } return(response); }
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); } }