Ejemplo n.º 1
0
        public IActionResult SendSMS(SMSPublicModel model)
        {
            model.FormBehavior = new FormBehavior();
            CaptchaResponse response = ValidateCaptcha(HttpContext.Request.Form["g-recaptcha-response"]);

            if (!response.Success)
            {
                ModelState.AddModelError(string.Empty, "Please click captcha for security purposes.");
            }
            else if (ModelState.IsValid)
            {
                try
                {
                    var sms = new SMSModel
                    {
                        MobileNumber = model.MobileNumber,
                        MessageBody  = $"From: {model.SenderName}\n{model.MessageBody}\n\nDon't reply to this number."
                    };
                    var record = _mapper.Map <SMSModel, ShortMessageService>(sms);
                    record.SMSStatus = Enums.SMSStatus.Queue;
                    _smsService.NewSMS(record, true);
                    model.FormBehavior.Notification = new Notification
                    {
                        IsError = false,
                        Message = "Message successfully queued.",
                        Title   = "SMS"
                    };
                    model.MobileNumber = string.Empty;
                    model.MessageBody  = string.Empty;
                    model.SenderName   = string.Empty;
                    ModelState.Clear();
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("mobile number"))
                    {
                        ModelState.AddModelError(string.Empty, "Invalid format of mobile number.");
                    }
                    else if (ex.Message.Contains("unicode"))
                    {
                        ModelState.AddModelError(string.Empty, "Message body should not contain unicode characters (ex. emojis)");
                    }
                    else
                    {
                        model.FormBehavior.Notification = new Notification
                        {
                            IsError = true,
                            Message = ex.Message,
                            Title   = "SMS"
                        };
                    }
                }
            }
            return(PartialView("_SendSMS", model));
        }
Ejemplo n.º 2
0
        public IActionResult SendSMS()
        {
            SMSPublicModel model = new SMSPublicModel
            {
                FormType      = Global.FormType.Create,
                UserHandler   = _userHandler,
                IsRecordOwner = true
            };

            return(View(model));
        }