protected virtual SmsNotifyResponse NotifySms(SmsNotifyRequest request)
        {
            var result = new SmsNotifyResponse();

            if (request != null)
            {
                BackgroundJob.Enqueue(() => NotifyBySms(request));
                result.Succeeded();
            }
            else
            {
                result.Status = "NoRequest";
            }

            return(result);
        }
        public ActionResult Send(NotifyType notifyType)
        {
            var result  = new ServiceResponse <object>();
            var request = null as NotifyRequest;

            switch (notifyType)
            {
            case NotifyType.Email:
                request = new EmailNotifyRequest
                {
                    Body    = Request.Form["Body"],
                    Email   = Request.Form["To"],
                    Subject = Request.Form["Subject"],
                    IsHtml  = SafeClrConvert.ToBoolean(Request.Form["IsHtml"])
                };
                break;

            case NotifyType.SMS:
                request = new SmsNotifyRequest
                {
                    Message  = Request.Form["Message"],
                    MobileNo = Request.Form["targetNumber"]
                };
                break;

            default:
                result.Status  = "InvalidOrUnsupportedNotifyType";
                result.Message = "Specified notify type is not supported or valid";
                break;
            }

            if (request != null)
            {
                try
                {
                    result.Data    = notificationService.Notify(notifyType, request);
                    result.Success = true;
                }
                catch (Exception e)
                {
                    result.Exception = e;
                }
            }

            return(Content(JsonConvert.SerializeObject(result), "application/javascript"));
        }
Example #3
0
        public override async Task RunAsync(ApiClientCustomerRegisterContext context)
        {
            var store = this.Store as ApiClientCustomerStrategyStore;
            var ctx   = await store.Enrol.InvokeAsync(new ApiClientCustomerEnrolRequest
            {
                AppId            = context.Request.CallContext.App.AppId,
                ApiClientId      = context.Request.CallContext.Client?.ApiClientId,
                IP               = context.Request.CallContext.ClientIP,
                UserName         = context.Request.CallContext.HttpContext.User.Identity.Name,
                Role             = context.Request.CallContext.HttpContext.User.Identity.GetRole(),
                Email            = context.Request.Email,
                MobileNo         = context.Request.MobileNo,
                ActivationMethod = context.Request.ActivationMethod,
                HardwareCode     = context.Request.HardwareCode,
                SerialNo         = context.Request.SerialNo,
                CustomerType     = context.Request.CustomerType
            });

            if (ctx.Response.Success)
            {
                context.Response.Succeeded();

                var activationCode = ctx.Response.ActivationCode;

                switch (context.Request.ActivationMethod.ToLower())
                {
                case "sms":
                    var smsNotifyRequest = new SmsNotifyRequest {
                        Message = activationCode, MobileNo = context.Request.MobileNo
                    };
                    await _notification.NotifyAsync(NotifyType.SMS, smsNotifyRequest);

                    break;

                case "email":
                    var emailNotifyRequest = new EmailNotifyRequest {
                        Email = context.Request.Email, Subject = "Activation Code", Body = string.Format("Your activation code is {0}", activationCode)
                    };
                    await _notification.NotifyAsync(NotifyType.Email, emailNotifyRequest);

                    break;

                case "mixed":
                    var index = activationCode.Length / 2;
                    var part1 = activationCode.Substring(0, index);
                    var part2 = activationCode.Substring(index);

                    smsNotifyRequest = new SmsNotifyRequest {
                        Message = part1, MobileNo = context.Request.MobileNo
                    };
                    emailNotifyRequest = new EmailNotifyRequest {
                        Email = context.Request.Email, Subject = "Activation Code", Body = string.Format("The email-part of your activation code is {0}", part2)
                    };

                    await _notification.NotifyAsync(NotifyType.SMS, smsNotifyRequest);

                    await _notification.NotifyAsync(NotifyType.Email, emailNotifyRequest);

                    break;
                }
            }
            else
            {
                context.Response.SetStatus(ctx.Response.Status.ToString());
            }
        }
 protected virtual Task <SmsNotifyResponse> NotifySmsAsync(SmsNotifyRequest request)
 {
     return(Task.FromResult(NotifySms(request)));
 }
 public static void NotifyBySms(SmsNotifyRequest sms)
 {
     SMS.Send(sms.MobileNo, sms.Message);
 }