public static EmailOrSmsViewModel ToModel(this REmailSms emailSms)
 {
     if (emailSms == null)
     {
         return(null);
     }
     return(new EmailOrSmsViewModel()
     {
         NumericalOrder = emailSms.NumericalOrder,
         Id = emailSms.Id,
         Type = emailSms.Type,
         TypeName = emailSms.Type.ToString(),
         MessageType = emailSms.MessageType,
         MessageTypeName = emailSms.MessageType.ToString(),
         PhoneNumber = emailSms.PhoneNumber,
         Email = emailSms.Email,
         Content = emailSms.Content,
         Model = emailSms.Model,
         Template = emailSms.Template,
         Status = emailSms.Status,
         StatusName = emailSms.Status.ToString(),
         Title = emailSms.Title,
         CreatedUid = emailSms.CreatedUid,
         UpdatedUid = emailSms.UpdatedUid,
         CreatedDateUtc = emailSms.CreatedDateUtc,
         UpdatedDateUtc = emailSms.UpdatedDateUtc,
         SendDate = emailSms.SendDate,
         VerifyId = emailSms.VerifyId
     });
 }
예제 #2
0
        public async Task <REmailSms> GetFromDb(string id)
        {
            REmailSms emailSms = await _emailSmsRepository.Get(id);

            if (!string.IsNullOrEmpty(emailSms.VerifyId))
            {
                emailSms.Verify = await GetVerifyFromDb(emailSms.VerifyId);
            }
            return(emailSms);
        }
예제 #3
0
 public EmailSms(REmailSms emailSms)
 {
     Id          = emailSms.Id;
     Type        = emailSms.Type;
     MessageType = emailSms.MessageType;
     PhoneNumber = emailSms.PhoneNumber;
     Email       = emailSms.Email;
     Title       = emailSms.Title;
     Content     = emailSms.Content;
     Model       = emailSms.Model;
     Template    = emailSms.Template;
     Status      = emailSms.Status;
     VerifyId    = emailSms.VerifyId;
     SendDate    = emailSms.SendDate;
 }
        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);
            }
        }