Esempio n. 1
0
        public HttpResponseMessage UserLogin([FromBody] tokenModel currentModel)
        {
            string token = "";

            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
            if (NeeoUtility.IsPhoneNumberInInternationalFormat(currentModel.uID))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
            }
            if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(currentModel.uID)))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
            }
            if (NeeoActivation.CheckUserAlreadyRegistered(currentModel.uID))
            {
                token = GenerateToken(currentModel.uID);
                return(Request.CreateResponse(HttpStatusCode.OK, token));
            }
            else
            {
                token = "-1";
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, token));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Call to the given number.
        /// </summary>
        /// <param name="phoneNumber">A string containing the phone number for sending SMS.</param>
        /// <param name="code">A string containing code.</param>
        public void Call(string phoneNumber, string code)
        {
            TwilioClient.Init(_twilioAccountSid, _twilioAuthToken);

            var to   = new PhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber));
            var from = new PhoneNumber(_twilioPhoneNumber);
            var call = Create(to, from,
                              url: new Uri(_twilioSsmlUrl.Replace("{{code}}", code)));

            LogManager.CurrentInstance.InfoLogger.LogInfo(
                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Twilio voice call - Phone # : \"" + phoneNumber[0] + "\"  is completed with Sid: " + call.Sid);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uName"></param>
        /// <param name="contacts"></param>
        public void SendInvitation(string uName, string contacts, string languageCode)
        {
            string invitationText;

            string[] delimeter = { "," };
            invitationText       = InvitationMessage.GetLocalizedMessage(languageCode);
            _invitationSenderKey = _invitationSenderKey ?? ConfigurationManager.AppSettings[NeeoConstants.InvitationSenderKey];
            string[]  contactsArray = contacts.Split(delimeter, StringSplitOptions.None);
            ulong     temp          = 0;
            DbManager dbManager     = new DbManager();
            string    profileName   = dbManager.GetUserProfileName(_userID);
            string    msgBody       = invitationText.Replace(_invitationSenderKey,
                                                             (NeeoUtility.IsNullOrEmpty(uName)
                    ? (NeeoUtility.IsNullOrEmpty(profileName)
                        ? "(" + NeeoUtility.FormatAsIntlPhoneNumber(_userID) + ")"
                        : (profileName + " (" + NeeoUtility.FormatAsIntlPhoneNumber(_userID) + ")"))
                    : (uName + " (" + NeeoUtility.FormatAsIntlPhoneNumber(_userID) + ")")));

            for (int i = 0; i < contactsArray.Length; i++)
            {
                if (ulong.TryParse(contactsArray[i], out temp))
                {
                    try
                    {
                        //SmsManager.SendThroughSecondaryApi(NeeoUtility.FormatAsIntlPhoneNumber(contactsArray[i]),msgBody.Replace("!", Environment.NewLine));
                        PowerfulPal.Sms.SmsManager.GetInstance().Twilio.SendSms(new[] { NeeoUtility.FormatAsIntlPhoneNumber(contactsArray[i]) }, msgBody.Replace("!", Environment.NewLine), languageCode != "en");
                    }
                    catch (ApplicationException appEx)
                    {
                        LogManager.CurrentInstance.ErrorLogger.LogError(
                            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + " ===> uid : " +
                            _userID + " ===> contact : " + contactsArray[i] + " is invalid.");
                    }
                }
                else
                {
                    LogManager.CurrentInstance.ErrorLogger.LogError(
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + " ===> uid : " +
                        _userID + " ===> contact : " + contactsArray[i] + " is invalid.");
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Sends activation SMS to the given number.
        /// </summary>
        /// <param name="phoneNumber">A string containing the phone number for sending SMS.</param>
        /// <param name="activationCode">A string containing the activation code.</param>
        /// <param name="isRegenerated">A bool if true specifying that the request is for sending regenerated activation code; otherwise false.</param>
        /// <remarks><paramref name="isRegenerated"/> is mainly used to switch between the sms sending APIs. For the first time ,send code to user with primary API i.e. Nexmo and send the regenerated code with the secondary API i.e. Tiwilio.</remarks>
        /// <returns>true if SMS is successfully sent; otherwise, false.</returns>
        public static void SendActivationCode(string phoneNumber, string activationCode, bool isRegenerated)
        {
            if (_activationCodeMask == null)
            {
                _activationCodeMask = ConfigurationManager.AppSettings[NeeoConstants.ActivationCodeMask].ToString();
            }

            if (_smsBody == null)
            {
                _smsBody = ConfigurationManager.AppSettings[NeeoConstants.ActivationSmsText].ToString();
                _smsBody = _smsBody.Replace(".", "." + Environment.NewLine);
            }

            if (!isRegenerated)
            {
                SendThroughPrimaryApi(NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber), _smsBody.Replace(_activationCodeMask, activationCode), true);
            }
            else
            {
                SendThroughSecondaryApi(NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber), _smsBody.Replace(_activationCodeMask, activationCode));
            }
        }
Esempio n. 5
0
        /*They will be deprecated in future.*/

        /// <summary>
        /// Sends activation code to the phone number provided in <paramref name="phoneNumber"/>.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="phoneNumber">A phone number on which activation code has to be sent.</param>
        /// <param name="devicePlatform">Platform of the user's device.</param>
        /// <param name="activationCode">A code that has to be sent on the give phone number.</param>
        /// <param name="isResend">A bool value indicating this is a resending code request if true,otherwise false (default value). </param>
        /// <param name="isRegenerated">A bool value indicating this is a regenerated code sending request if true,otherwise false (default value). </param>
        /// <returns>An integer if 0 = sms has not been sent, 1 = sms has been successfully sent or remaining minutes to unblock user.</returns>

        public int SendActivationCode(string phoneNumber, short devicePlatform, string activationCode, bool isResend, bool isRegenerated)
        {
            phoneNumber    = (phoneNumber != null) ? phoneNumber.Trim() : phoneNumber;
            activationCode = (activationCode != null) ? activationCode.Trim() : activationCode;
            int smsSendingResult = (int)SmsSendingStatus.SendingFailed;

            #region log user request and response

            /***********************************************
            *  To log user request and response
            ***********************************************/
            if (_logRequestResponse)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + " ===> " +
                    "Request ===> phoneNumber : " + phoneNumber + ", devicePlatform : " + devicePlatform +
                    ", activationCode : " + activationCode + ", isResend : " + isResend + ", isRegenerated : " +
                    isRegenerated);
            }

            #endregion

            //#region Verify User
            //var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
            //string keyFromClient = request.Headers["key"];
            //   if (NeeoUtility.AuthenticateUserRequest( phoneNumber, keyFromClient))
            //{
            //#endregion

            DevicePlatform userDevicePlatform = (DevicePlatform)devicePlatform;
            uint           tempActivationCode = 0;
            ulong          tempPhoneNumber    = 0;
            if (!NeeoUtility.IsNullOrEmpty(phoneNumber) && !NeeoUtility.IsNullOrEmpty(activationCode) && Enum.IsDefined(typeof(DevicePlatform), devicePlatform) && uint.TryParse(activationCode, out tempActivationCode) && ulong.TryParse(phoneNumber, out tempPhoneNumber))
            {
                try
                {
                    if (NeeoUtility.IsPhoneNumberInInternationalFormat(phoneNumber))
                    {
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                        return(smsSendingResult);
                    }
                    if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber)) && _numberValidityCheck)
                    {
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                        return(smsSendingResult);
                    }
                    smsSendingResult = NeeoActivation.SendActivationCodeToUnBlockedUser(phoneNumber, userDevicePlatform, activationCode, isResend, isRegenerated);
                }
                catch (ApplicationException appExp)
                {
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                }
                return(smsSendingResult);
            }
            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            return(smsSendingResult);

            //}
            //   else
            //   {
            //       NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);
            //       return smsSendingResult;
            //   }
        }
Esempio n. 6
0
        ///// <summary>
        ///// Sends activation code to the phone number provided in <paramref name="ph"/>. It is a wrapping method with short parameter name.
        ///// </summary>
        ///// <remarks>
        ///// </remarks>
        ///// <param name="ph">A phone number on which activation code has to be sent.</param>
        ///// <param name="dP">Platform of the user's device.</param>
        ///// <param name="actCode">A code that has to be sent on the give phone number.</param>
        ///// <returns>An integer if 0 = sms has not been sent, 1 = sms has been successfully sent or remaining minutes to unblock user.</returns>
        //public int SendCodeTest(string ph, short dP, string actCode)
        //{
        //    #region log user request and response

        //    /***********************************************
        //     To log user request and response
        //     ***********************************************/
        //    if (_logRequestResponse)
        //    {
        //        LogManager.CurrentInstance.InfoLogger.LogInfo(
        //            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + " ===> " +
        //            "Request ===> phoneNumber : " + ph + ", devicePlatform : " + dP +
        //            ", activationCode : " + actCode);
        //    }

        //    #endregion

        //    //return this.SendActivationCode(ph, dP, actCode, isRes, isReg);
        //    ph = (ph != null) ? ph.Trim() : ph;
        //    actCode = (actCode != null) ? actCode.Trim() : actCode;

        //    int smsSendingResult = (int)SmsSendingStatus.SendingFailed;
        //    DevicePlatform userDevicePlatform = (DevicePlatform)dP;
        //    uint tempActivationCode = 0;
        //    ulong tempPhoneNumber = 0;
        //    if (!NeeoUtility.IsNullOrEmpty(ph) && !NeeoUtility.IsNullOrEmpty(actCode) && Enum.IsDefined(typeof(DevicePlatform), dP))
        //    {
        //        try
        //        {
        //            if (NeeoUtility.IsPhoneNumberInInternationalFormat(ph))
        //            {
        //                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
        //                return smsSendingResult;
        //            }
        //            if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(ph)) && _numberValidityCheck)
        //            {
        //                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
        //                return smsSendingResult;
        //            }
        //            smsSendingResult = NeeoActivation.SendActivationCodeTest(ph, userDevicePlatform, actCode);
        //        }
        //        catch (ApplicationException appExp)
        //        {
        //            NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
        //        }

        //        return smsSendingResult;
        //    }
        //    NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
        //    return smsSendingResult;
        //}

        /// <summary>
        /// Registers and configures user account. It is a wrapping method with short parameter name.
        /// </summary>
        /// <param name="ph">A string containing phone number for registering account.</param>
        /// <param name="client">An object containing the client information.</param>
        /// <returns>true if the account is successfully registered on the server; otherwise, false.</returns>
        public bool RegisterAppUser(string ph, UserAgent client)

        {
            ph = (ph != null) ? ph.Trim() : ph;
            #region log user request and response

            /***********************************************
            *  To log user request and response
            ***********************************************/
            if (_logRequestResponse)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + " ===> " +
                    "Request ===> phoneNumber : " + ph + ", client : " + JsonConvert.SerializeObject(client));
            }

            #endregion

            //        #region Verify User
            //var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
            //string keyFromClient = request.Headers["key"];
            //   if (NeeoUtility.AuthenticateUserRequest( ph, keyFromClient))
            //{
            //#endregion

            if (client != null)
            {
                ulong tempPhoneNumber = 0;

                if (!NeeoUtility.IsNullOrEmpty(ph) && !NeeoUtility.IsNullOrEmpty(client.DVenID) && !NeeoUtility.IsNullOrEmpty(client.AppID) && Enum.IsDefined(typeof(DevicePlatform), client.DP) && Enum.IsDefined(typeof(PushNotificationSource), client.Pns) && ulong.TryParse(ph, out tempPhoneNumber) && !NeeoUtility.IsNullOrEmpty(client.AppVer) && !NeeoUtility.IsNullOrEmpty(client.OsVer) && !NeeoUtility.IsNullOrEmpty(client.DM))
                {
                    try
                    {
                        if (NeeoUtility.IsPhoneNumberInInternationalFormat(ph))
                        {
                            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                            return(false);
                        }
                        if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(ph)) && _numberValidityCheck)
                        {
                            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                            return(false);
                        }
                        if (NeeoActivation.SetupUserAccount(ph, client.AppID, client.AppVer, new DeviceInfo()
                        {
                            DeviceModel = client.DM, DevicePlatform = (DevicePlatform)client.DP, DeviceVenderID = client.DVenID, DeviceToken = client.DToken?.Trim(), PushNotificationSource = (PushNotificationSource)client.Pns, OsVersion = client.OsVer, DeviceTokenVoIP = client.DTokenVoIP?.Trim()
                        }))
                        {
                            return(true);
                        }
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.TransactionFailure);
                        return(false);
                    }
                    catch (ApplicationException appExp)
                    {
                        NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                        return(false);
                    }
                }
            }
            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            return(false);

            //}
            //   else
            //   {
            //       NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);

            //       return false;
            //   }
        }
Esempio n. 7
0
        /// <summary>
        /// Sends activation code to the phone number provided in <paramref name="ph"/>. It is a wrapping method with short parameter name.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ph">A phone number on which activation code has to be sent.</param>
        /// <param name="dP">Platform of the user's device.</param>
        /// <param name="actCode">A code that has to be sent on the give phone number.</param>
        /// <param name="isRes">A bool value indicating this is a resending code request if true,otherwise false (default value). </param>
        /// <param name="isReg">A bool value indicating this is a regenerated code sending request if true,otherwise false (default value). </param>
        /// <param name="appKey">A string containing the appKey(For Android).</param>
        /// <returns>An integer if 0 = sms has not been sent, 1 = sms has been successfully sent or remaining minutes to unblock user.</returns>
        public int SendActCode(string ph, short dP, string actCode, bool isRes, bool isReg, string appKey, short sType)
        {
            #region log user request and response

            /***********************************************
            *  To log user request and response
            ***********************************************/
            if (_logRequestResponse)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + " ===> " +
                    "Request ===> phoneNumber : " + ph + ", devicePlatform : " + dP +
                    ", activationCode : " + actCode + ", isResend : " + isRes + ", isRegenerated : " + isReg + ", appKey : " + appKey + ", serviceType: " + sType);
            }

            #endregion

            //return this.SendActivationCode(ph, dP, actCode, isRes, isReg);
            ph      = (ph != null) ? ph.Trim() : ph;
            actCode = (actCode != null) ? actCode.Trim() : actCode;
            appKey  = appKey?.Trim();

            int                codeSendingResult  = (int)SmsSendingStatus.SendingFailed;
            DevicePlatform     userDevicePlatform = (DevicePlatform)dP;
            CodeSendingService codeSendingService = (CodeSendingService)sType;
            uint               tempActivationCode = 0;
            ulong              tempPhoneNumber    = 0;
            if (!NeeoUtility.IsNullOrEmpty(ph) && !NeeoUtility.IsNullOrEmpty(actCode) && Enum.IsDefined(typeof(DevicePlatform), dP) && Enum.IsDefined(typeof(CodeSendingService), sType) && uint.TryParse(actCode, out tempActivationCode) && ulong.TryParse(ph, out tempPhoneNumber))
            {
                try
                {
                    if (NeeoUtility.IsPhoneNumberInInternationalFormat(ph))
                    {
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                        return(codeSendingResult);
                    }
                    if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(ph)) && _numberValidityCheck)
                    {
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                        return(codeSendingResult);
                    }

                    if (codeSendingService == CodeSendingService.Call)
                    {
                        codeSendingResult = NeeoActivation.CallForActivationCode(ph, userDevicePlatform, actCode);
                    }
                    else
                    {
                        codeSendingResult = NeeoActivation.SendActivationCode(ph, userDevicePlatform, actCode, appKey);
                    }
                }
                catch (ApplicationException appExp)
                {
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                }

                return(codeSendingResult);
            }

            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            return(codeSendingResult);
        }
Esempio n. 8
0
        /// <summary>
        /// Sends messages to the users who are not blocked.
        /// </summary>
        /// <remarks>It manipulates the user requests whether it is resending activation code request or not, block or unblock the user based on maximum allowed request in 24 hrs and then sends sms to the users who are not blocked.</remarks>
        /// <param name="phoneNumber">A string containing the user's phone number.</param>
        /// <param name="devicePlatform">An enum specifying the device platform.</param>
        /// <param name="activationCode">A string containing activation code to be sent.</param>
        /// <param name="isResend">A bool if true specifying that the request is for resending activation code; otherwise false.</param>
        /// <param name="isRegenerated">A bool if true specifying that the request is for sending regenerated activation code; otherwise false.</param>
        /// <returns>An integer if 0 = sms has not been sent, -1 = sms has been successfully sent or number of remaining minutes to unblock user = user is blocked based on blocking policy. </returns>
        public static int SendActivationCodeToUnBlockedUser(string phoneNumber, DevicePlatform devicePlatform, string activationCode, bool isResend, bool isRegenerated)
        {
            int smsSendingResult = (int)SmsSendingStatus.SendingFailed;

            if (devicePlatform == DevicePlatform.iOS || devicePlatform == DevicePlatform.Android)
            {
                if (isResend)
                {
                    //SmsManager.SendActivationCode(phoneNumber, activationCode, isRegenerated);
                    PowerfulPal.Sms.SmsManager.GetInstance().Twilio.SendSms(new[] { NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber) }, NeeoUtility.GetActivationMessage(activationCode));
                    smsSendingResult = (int)SmsSendingStatus.Sent;
                    return(smsSendingResult);
                }
                else
                {
                    DbManager dbManager = new DbManager();
                    if (dbManager.StartTransaction())
                    {
                        try
                        {
                            int userBlockedState = dbManager.GetUserBlockedState(phoneNumber);
                            switch ((UserState)userBlockedState)
                            {
                            case UserState.NotBlocked:
                                PowerfulPal.Sms.SmsManager.GetInstance().SendSms(new[] { NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber) }, NeeoUtility.GetActivationMessage(activationCode));
                                smsSendingResult = (int)SmsSendingStatus.Sent;
                                break;

                            default:
                                smsSendingResult = userBlockedState;
                                break;
                            }

                            dbManager.CommitTransaction();
                            return(smsSendingResult);
                        }
                        catch (ApplicationException appExp)
                        {
                            dbManager.RollbackTransaction();
                            throw;
                        }
                        catch (Exception exp)
                        {
                            dbManager.RollbackTransaction();
                            LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp);
                            throw new ApplicationException(CustomHttpStatusCode.UnknownError.ToString("D"));
                        }
                    }
                    else
                    {
                        throw new ApplicationException(CustomHttpStatusCode.TransactionFailure.ToString("D"));
                        return(smsSendingResult);
                    }
                }
            }
            else
            {
                // handling for secondary devices.
                return(smsSendingResult);
            }
        }
Esempio n. 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="devicePlatform"></param>
        /// <param name="activationCode"></param>
        /// <returns></returns>
        public static int SendActivationCodeTest(string phoneNumber, DevicePlatform devicePlatform, string activationCode)
        {
            int    smsSendingResult = (int)SmsSendingStatus.SendingFailed;
            string smsSendingSource = ConfigurationManager.AppSettings[NeeoConstants.SmsSendingSource] ?? "default";

            if (Enum.IsDefined(typeof(DevicePlatform), devicePlatform))
            {
                var dbManager = new DbManager();
                if (dbManager.StartTransaction())
                {
                    try
                    {
                        var userAttemptsDetails = dbManager.GetUserAttemptsCount(phoneNumber, activationCode);
                        switch ((UserState)userAttemptsDetails["blockedState"])
                        {
                        case UserState.NotBlocked:
                            if (smsSendingSource.Trim() == "primary")
                            {
                                PowerfulPal.Sms.SmsManager.GetInstance().SendSms(new[] { NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber) }, activationCode);
                                smsSendingResult = (int)SmsSendingStatus.Sent;
                            }
                            else if (smsSendingSource.Trim() == "secondary")
                            {
                                PowerfulPal.Sms.SmsManager.GetInstance().Twilio.SendSms(new[] { NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber) }, activationCode);
                                smsSendingResult = (int)SmsSendingStatus.Sent;
                            }
                            else if (userAttemptsDetails["attemptsCount"] % 2 == 0)
                            {
                                PowerfulPal.Sms.SmsManager.GetInstance().Twilio.SendSms(new[] { NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber) }, activationCode);
                                smsSendingResult = (int)SmsSendingStatus.Sent;
                            }
                            else
                            {
                                PowerfulPal.Sms.SmsManager.GetInstance().SendSms(new[] { NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber) }, activationCode);
                                smsSendingResult = (int)SmsSendingStatus.Sent;
                            }
                            break;

                        default:
                            smsSendingResult = userAttemptsDetails["blockedState"];
                            break;
                        }

                        dbManager.CommitTransaction();
                        return(smsSendingResult);
                    }
                    catch (ApplicationException appExp)
                    {
                        dbManager.RollbackTransaction();
                        throw;
                    }
                    catch (Exception exp)
                    {
                        dbManager.RollbackTransaction();
                        LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exp.Message, exp);
                        throw new ApplicationException(CustomHttpStatusCode.UnknownError.ToString("D"));
                    }
                }
                else
                {
                    throw new ApplicationException(CustomHttpStatusCode.TransactionFailure.ToString("D"));
                    return(smsSendingResult);
                }
            }
            else
            {
                // handling for secondary devices.
                return(smsSendingResult);
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Sends SMS to the given number.
 /// </summary>
 /// <param name="phoneNumber">A string containing the phone number for sending SMS.</param>
 /// <param name="msgBody">A string containing message body text.</param>
 /// <returns>true if SMS is successfully sent; otherwise, false.</returns>
 public static void SendSms(string phoneNumber, string msgBody)
 {
     SendThroughSecondaryApi(NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber), msgBody);
 }