Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            string             reply_str      = "";
            var                db             = new EchoContext();
            SmsRegistrationLog sms_log        = new SmsRegistrationLog();
            string             sms_log_result = "";

            try
            {
                string keyword   = context.Request.Form["keyword"] == null ? string.Empty : context.Request.Form["keyword"];
                string content   = context.Request.Form["content"] == null ? string.Empty : context.Request.Form["content"];
                string mobile_no = context.Request.Form["mobile_no"] == null ? string.Empty : context.Request.Form["mobile_no"];
                //string msg = context.Request.Form["msg"] == null ? string.Empty : context.Request.Form["msg"];


                sms_log.Mobile_Number = mobile_no;
                sms_log.RQ_Msg        = "-";
                sms_log.RQ_Keyword    = keyword;
                sms_log.RQ_Content    = content;


                int  result = CustomValidate.ValidateNumber(mobile_no);
                bool flag   = true;

                if (result != 1 && result != 4)
                {
                    flag = false;
                    if (result == 2 || result == 3 || result == 5)
                    {
                        reply_str      = System.Configuration.ConfigurationManager.AppSettings["EXIST_NUMBER"];
                        sms_log_result = "Existing number";
                    }

                    if (result == 6)
                    {
                        reply_str      = System.Configuration.ConfigurationManager.AppSettings["NO_ACCTACTIVATION"];
                        sms_log_result = "Maintenance Period";
                    }
                }

                if (flag)
                {
                    if (IsValid(keyword, content))
                    {
                        string[] content_arrs = content.Split(' ');
                        string   gender       = content_arrs[0];
                        string   dob          = content_arrs[1];
                        string[] result_sp    = new string[2];

                        byte day   = Convert.ToByte(dob.Substring(0, 2));
                        byte month = Convert.ToByte(dob.Substring(2, 2));
                        int  year  = Convert.ToInt16(dob.Substring(4, 4));

                        year = year - 543;
                        #region transaction
                        var transactionOptions = new TransactionOptions();
                        transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
                        transactionOptions.Timeout        = TransactionManager.MaximumTimeout;
                        Account  account   = new Account();
                        DateTime timestamp = DateTime.Now;
                        using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
                        {
                            var db_transaction = new EchoContext();

                            account.Gender_Cd           = gender.ToUpper();
                            account.Day_Of_Birth        = day;
                            account.Month_Of_Birth      = month;
                            account.Year_Of_Birth       = year;
                            account.Channel_Cd          = "SMS";
                            account.Created_By          = System.Configuration.ConfigurationManager.AppSettings["CREATED_BY_SMS"];
                            account.Updated_By          = System.Configuration.ConfigurationManager.AppSettings["CREATED_BY_SMS"];
                            account.First_Mobile_Number = mobile_no;
                            account.Created_Dttm        = timestamp;
                            account.Updated_Dttm        = timestamp;
                            account.Registration_Dttm   = timestamp;

                            var   today = DateTime.Now.Date;
                            Quota q     = db_transaction.Quotas.Where(x => x.Quota_Type_Cd.Equals("B")).Where(x => x.Quota_Cd.Equals("Q0001")).SingleOrDefault();

                            #region account quota used cur
                            AccountQuotaUsedCur aquc = new AccountQuotaUsedCur();
                            aquc.Date                = today.Date;
                            aquc.Account             = account;
                            aquc.Quota_Freq_Used_Val = 0;
                            aquc.Quota_Avail_Flag    = true;
                            aquc.Quota_Dur_Val       = Convert.ToByte(q.Quota_Dur_Val);
                            aquc.Quota_Freq_Val      = Convert.ToByte(q.Quota_Freq_Val);
                            db_transaction.AccountQuotaUsedCurs.Add(aquc);
                            #endregion

                            #region account mobile
                            AccountMobile am = new AccountMobile();
                            am.Account       = account;
                            am.Mobile_Number = mobile_no;
                            am.Primary_Flag  = true;
                            am.Status_Cd     = "AC";
                            am.Updated_By    = System.Configuration.ConfigurationManager.AppSettings["CREATED_BY_SMS"];
                            am.Created_By    = System.Configuration.ConfigurationManager.AppSettings["CREATED_BY_SMS"];
                            db_transaction.AccountMobiles.Add(am);
                            #endregion

                            #region account interest
                            AccountInterest ai = new AccountInterest();
                            ai.Account = account;
                            db_transaction.AccountInterests.Add(ai);
                            #endregion

                            #region account quota
                            AccountQuota aq = new AccountQuota();
                            aq.Account  = account;
                            aq.Quota_Cd = q.Quota_Cd;
                            db_transaction.AccountQuotas.Add(aq);
                            #endregion

                            #region update account activation and set status_cd
                            SqlParameter output = new SqlParameter("acstatus", SqlDbType.Int);
                            output.Direction = ParameterDirection.Output;

                            SqlParameter date = new SqlParameter("today", SqlDbType.Date);
                            date.Value = DateTime.Now;

                            SqlParameter no_acct_total = new SqlParameter("no_acct_limit_total", SqlDbType.Int);

                            int no_acct_limit_total         = 0;
                            AdminConfiguration admin_config = db_transaction.AdminConfigurations.SingleOrDefault();

                            if (admin_config != null)
                            {
                                no_acct_limit_total = admin_config.No_Activation_Limit_Total;
                            }

                            no_acct_total.Value = no_acct_limit_total;
                            string sql_string =
                                "declare @tbt table (acstatus int)" +
                                "UPDATE Account_Activation " +
                                "SET No_Activation = CASE WHEN (No_Activation + 1 > No_Max_Activation or (No_Activation_Acc + 1 > @no_acct_limit_total)) THEN No_Activation ELSE No_Activation + 1 END, " +
                                "No_Activation_Acc = CASE WHEN (No_Activation + 1 > No_Max_Activation or (No_Activation_Acc + 1 > @no_acct_limit_total)) THEN No_Activation_Acc ELSE No_Activation_Acc + 1 END, " +
                                "No_Activation_Pending = CASE WHEN (No_Activation + 1 > No_Max_Activation or (No_Activation_Acc + 1 > @no_acct_limit_total)) THEN No_Activation_Pending + 1 ELSE No_Activation_Pending END, " +
                                "Updated_By = 'WEBSITE', " +
                                "Updated_Dttm = GETDATE() " +
                                "OUTPUT CASE WHEN (deleted.No_Activation + 1 > deleted.No_Max_Activation or deleted.No_Activation_Acc + 1 > @no_acct_limit_total) THEN 1 ELSE 0 END " +
                                " into @tbt " +
                                "WHERE [Date] = @today " +
                                "select @acstatus = acstatus from @tbt";

                            db_transaction.Database.ExecuteSqlCommand(sql_string, no_acct_total, date, output);

                            int sql_result = Convert.ToInt16(output.Value);

                            if (sql_result == 0)
                            {
                                account.Status_Cd       = FreebieStatus.AccountActivated();
                                account.Activation_Dttm = timestamp;
                                reply_str      = System.Configuration.ConfigurationManager.AppSettings["ACD"];
                                sms_log_result = "Register success";
                                string q_str = (Convert.ToByte(q.Quota_Freq_Val) * Convert.ToByte(q.Quota_Dur_Val) * 30).ToString();
                                reply_str = reply_str.Replace("{count}", q.Quota_Freq_Val.ToString());
                                reply_str = reply_str.Replace("{mins}", q.Quota_Dur_Val.ToString());
                                reply_str = reply_str.Replace("{num}", q_str);
                            }
                            else
                            {
                                account.Status_Cd = FreebieStatus.AccountPending();
                                reply_str         = System.Configuration.ConfigurationManager.AppSettings["AP"];
                                sms_log_result    = "Register Pending";
                            }

                            #endregion


                            account.First_Quota_Cd       = q.Quota_Cd;
                            account.First_Quota_Dur_Val  = q.Quota_Dur_Val;
                            account.First_Quota_Freq_Val = q.Quota_Freq_Val;
                            account.Dummy_Flag           = "0";

                            db_transaction.Accounts.Add(account);
                            db_transaction.SaveChanges();
                            scope.Complete();
                        }
                        #endregion
                        #region call_sp
                        result_sp = CallSP.SP_Insert_Interact_Profile(account.Account_Id);
                        if (!result_sp[0].Equals("0"))
                        {
                            using (var new_db = new EchoContext())
                            {
                                SqlParameter date = new SqlParameter("today", SqlDbType.Date);
                                date.Value = DateTime.Now;
                                Account remove_ac = new_db.Accounts.SingleOrDefault(x => x.Account_Id == account.Account_Id);
                                if (remove_ac != null)
                                {
                                    if (remove_ac.Status_Cd.Equals(FreebieStatus.AccountActivated()))
                                    {
                                        string sql_string =
                                            "UPDATE Account_Activation " +
                                            "SET No_Activation = CASE WHEN (No_Activation - 1 < 0 ) THEN 0 ELSE No_Activation - 1 END, " +
                                            "No_Activation_Acc = CASE WHEN (No_Activation_Acc - 1 < 0 ) THEN 0 ELSE No_Activation_Acc - 1 END, " +
                                            "Updated_By = 'WEBSITE', " +
                                            "Updated_Dttm = GETDATE() " +
                                            "WHERE [Date] = @today ";

                                        new_db.Database.ExecuteSqlCommand(sql_string, date);
                                    }
                                    else
                                    {
                                        if (remove_ac.Status_Cd.Equals(FreebieStatus.AccountPending()))
                                        {
                                            string sql_string =
                                                "UPDATE Account_Activation " +
                                                "SET No_Activation_Pending = CASE WHEN (No_Activation_Pending - 1 < 0 ) THEN 0 ELSE No_Activation_Pending - 1 END, " +
                                                "Updated_By = 'WEBSITE', " +
                                                "Updated_Dttm = GETDATE() " +
                                                "WHERE [Date] = @today ";

                                            new_db.Database.ExecuteSqlCommand(sql_string, date);
                                        }
                                    }
                                    AccountQuotaUsedCur remove_aquc = new_db.AccountQuotaUsedCurs.SingleOrDefault(x => x.Account_Id == account.Account_Id);
                                    if (remove_aquc != null)
                                    {
                                        new_db.AccountQuotaUsedCurs.Remove(remove_aquc);
                                    }
                                    new_db.Accounts.Remove(remove_ac);
                                    new_db.SaveChanges();
                                }
                            }
                            reply_str = System.Configuration.ConfigurationManager.AppSettings["NO_ACCTACTIVATION"];
                        }
                        else
                        {
                            FreebieEvent.AccountCreateEvent(account, account.First_Mobile_Number, Permission.f_cust_regis_page_id);
                        }
                        #endregion
                    }
                    else
                    {
                        reply_str      = System.Configuration.ConfigurationManager.AppSettings["WRONG_FORMAT"];
                        sms_log_result = "Wrong input Format";
                    }
                }
            }
            catch (Exception err)
            {
                reply_str      = System.Configuration.ConfigurationManager.AppSettings["NO_ACCTACTIVATION"];
                sms_log_result = "System Error";
                FreebieEvent.AddCustomError(err.Message, Permission.f_cust_regis_page_id);
            }

            Encoding encoding = Encoding.GetEncoding("tis-620");
            string   xml_str  = GetReplyXML(reply_str, encoding);

            sms_log.Result = sms_log_result;
            db.SmsRegistrationLogs.Add(sms_log);
            db.SaveChanges();

            context.Response.ContentType     = "text/xml";
            context.Response.ContentEncoding = encoding;
            context.Response.Write(xml_str);
        }
Пример #2
0
        private static string fire(string phone_number, string msg, object log)
        {
            string result = string.Empty;

            System.Type type_of = log.GetType();                                       //ORIGIN

            System.Configuration.ConfigurationManager.AppSettings["SEND_SMS"] = "YES"; //dummy data for DEBUG

            if (System.Configuration.ConfigurationManager.AppSettings["SEND_SMS"].Equals("YES"))
            {
                string postData = "ACCOUNT=" + System.Configuration.ConfigurationManager.AppSettings["MOBILE_ACCOUNT"];
                postData += "&PASSWORD="******"MOBILE_PWD"];
                postData += "&MOBILE=" + phone_number;

                postData += "&MESSAGE=" + msg;

                postData += "&LANGUAGE=" + System.Configuration.ConfigurationManager.AppSettings["MESSAGE_LANGUAGE"];
                postData += "&SENDER=" + System.Configuration.ConfigurationManager.AppSettings["SENDER_NAME"];
                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                Encoding iso  = Encoding.GetEncoding("ISO-8859-11");
                Encoding utf8 = Encoding.UTF8;
                byte[]   data = encoding.GetBytes(postData);
                data = Encoding.Convert(utf8, iso, data);

                DateTime start_res = DateTime.Now;

                //result = "System.Configuration.ConfigurationManager.AppSettings['SEND_SMS'].Equals('Yes')"; //DEBUG

                try
                {
                    HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(System.Configuration.ConfigurationManager.AppSettings["SMS_GATEWAY"]);
                    httpRequest.Method        = "POST";
                    httpRequest.Host          = System.Configuration.ConfigurationManager.AppSettings["SMS_HOST"]; //"203.146.102.26";
                    httpRequest.ContentType   = "application/x-www-form-urlencoded";
                    httpRequest.ContentLength = data.Length;
                    MemoryStream Memstream = new MemoryStream(data);
                    Stream       stream    = httpRequest.GetRequestStream();
                    Memstream.WriteTo(stream);
                    stream.Close();

                    Callback(httpRequest, (response) =>
                    {
                        var res_stream      = new StreamReader(response.GetResponseStream());
                        DateTime end_res    = DateTime.Now;
                        int index           = 0;
                        string[] result_rsp = new string[] { "", "", "", "" };
                        string rsp_str      = "";
                        while (res_stream.Peek() >= 0)
                        {
                            result_rsp[index] = res_stream.ReadLine();
                            index++;
                        }
                        foreach (var txt in result_rsp)
                        {
                            rsp_str += txt + " ";
                        }

                        //saving
                        using (var db = new EchoContext())
                        {
                            if (type_of == typeof(OtpLog))
                            {
                                OtpLog logger        = new OtpLog();
                                logger.Mobile_Number = phone_number;
                                logger.Request_At    = start_res;
                                logger.Response_At   = end_res;
                                logger.Response_Text = rsp_str;
                                db.OtpLogs.Add(logger);
                                db.SaveChanges();
                            }
                            else
                            {
                                if (type_of == typeof(ActivationSmsLog))
                                {
                                    ActivationSmsLog logger = new ActivationSmsLog();
                                    logger.Mobile_Number    = phone_number;
                                    logger.Request_At       = start_res;
                                    logger.Response_At      = end_res;
                                    logger.Response_Text    = rsp_str;
                                    db.ActivationSmsLogs.Add(logger);
                                    db.SaveChanges();
                                }
                            }
                        }
                        res_stream.Close();
                    });
                }
                catch (WebException wex)
                {
                    using (var db = new EchoContext())
                    {
                        if (type_of == typeof(OtpLog))
                        {
                            OtpLog logger = new OtpLog();
                            logger.Mobile_Number = phone_number;
                            logger.Request_At    = start_res;
                            logger.Response_At   = DateTime.Now;
                            logger.Response_Text = wex.Message;
                            db.OtpLogs.Add(logger);
                            db.SaveChanges();
                        }
                        else
                        {
                            if (type_of == typeof(ActivationSmsLog))
                            {
                                ActivationSmsLog logger = new ActivationSmsLog();
                                logger.Mobile_Number = phone_number;
                                logger.Request_At    = start_res;
                                logger.Response_At   = DateTime.Now;
                                logger.Response_Text = wex.Message;
                                db.ActivationSmsLogs.Add(logger);
                                db.SaveChanges();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    FreebieEvent.AddError(ex, 0);
                }
            }
            else
            {
                result = ".AppSettings['SEND_SMS'].Equals('NO')"; //DEBUG
            }

            return(result);//ORIGIN
        }