public ActionResult Number(Reservation model)
        {
            _log.InfoFormat("New request number: {0} attempting entry.", model.Number);


            if (!NumberValidator.IsPhoneNumber(model.Number))
            {
                return(View());
            }

            if (_twilioRepository.MaxRequestsNotReached(model.Number) &&
                _personRepository.CheckPhoneNumberExists(model.Number))
            {
                TwilioMessage message = new TwilioMessage()
                {
                    To      = model.Number,
                    Message = _codeGenerator.GenerateCode()
                };

                //Send Message to Phone Number
                _twilioMessageProvider.SendMessage(message);

                //Create the database object
                TwilioMessaging messageDB = new TwilioMessaging()
                {
                    Code        = _codeGenerator.HashCode(message.Message),
                    Date        = DateTime.Now,
                    PhoneNumber = model.Number
                };

                //Log code
                _twilioRepository.AddRequest(messageDB);
            }
            return(View());
        }
Esempio n. 2
0
        /// <summary>
        /// Add twilio message to database
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool AddRequest(TwilioMessaging message)
        {
            bool success = false;

            //Sanitize phone number
            string numbers = new string(message.PhoneNumber.Where(Char.IsDigit).ToArray());

            try
            {
                if (NumberValidator.IsPhoneNumber(message.PhoneNumber))
                {
                    this.Insert(message);
                }
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Error entering AddRequest data into database {0}", ex.Message);
            }

            return(success);
        }