//private static EchoContext db = new EchoContext();

        public static void AfterCreateAccount(Account ac, string[] interests)
        {
            using (var db = new EchoContext())
            {
                ac.Created_By   = ac.Account_No;
                ac.Updated_By   = ac.Account_No;
                ac.Created_Dttm = DateTime.Now;
                ac.Updated_Dttm = DateTime.Now;

                //db.Entry(ac).State = EntityState.Modified;

                AccountMobile am = new AccountMobile();
                am.Mobile_Number = ac.First_Mobile_Number;
                am.Account_Id    = ac.Account_Id;
                am.Status_Cd     = FreebieStatus.MobileActive();
                am.Primary_Flag  = true;
                am.Created_By    = ac.Account_No;
                am.Updated_By    = ac.Account_No;
                db.AccountMobiles.Add(am);

                AccountInterest aci = new AccountInterest();
                aci.Account_Id             = ac.Account_Id;
                aci.I01_Food_Dining        = interests.Contains("I01");
                aci.I02_Night_Life         = interests.Contains("I02");
                aci.I03_Entertainment      = interests.Contains("I03");
                aci.I04_Music_Movie        = interests.Contains("I04");
                aci.I05_Sports_Fitness     = interests.Contains("I05");
                aci.I06_Shopping_Fashion   = interests.Contains("I06");
                aci.I07_Health_Beauty      = interests.Contains("I07");
                aci.I08_Travel             = interests.Contains("I08");
                aci.I09_Pets               = interests.Contains("I09");
                aci.I10_Kids_Children      = interests.Contains("I10");
                aci.I11_Home_Living        = interests.Contains("I11");
                aci.I12_Finance_Investment = interests.Contains("I12");
                aci.I13_Technology_Gadget  = interests.Contains("I13");
                aci.I14_Auto               = interests.Contains("I14");
                aci.Created_By             = ac.Account_No;
                aci.Updated_By             = ac.Account_No;
                db.AccountInterests.Add(aci);

                db.SaveChanges();
            }
        }
Beispiel #2
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);
        }
        public static int ValidateNumber(string number)
        {
            // return values
            // 0 required input or incorrent number format
            // 1 pass
            // 2 reserved for non-AIS validation
            // 3 number exists  not allow to register
            // 4 number exists inactive, re use
            // 5 number exists active, but allow user to enter username and password
            // 6 registeration disabled

            if (is_service_disabled())
            {
                return(6);
            }

            // Validate Format
            if (string.IsNullOrEmpty(number))
            {
                return(0);
            }
            string prefix_config = System.Configuration.ConfigurationManager.AppSettings["MOBILE_PREFIX"];

            prefix_config = prefix_config.Trim();
            string[] prefixes     = prefix_config.Split(',');
            string   allow_prefix = "";

            foreach (var pf in prefixes)
            {
                string p = pf.Replace("0", "");
                allow_prefix += p;
            }
            string phoneRegExp = "";

            phoneRegExp = "^0[" + allow_prefix + @"]\d{8}$";

            if (!System.Text.RegularExpressions.Regex.IsMatch(number, phoneRegExp) || number.Length != 10)
            {
                return(0);
            }

            string delete_status = FreebieStatus.MobileDeleted();

            using (var val_db = new EchoContext())
            {
                AccountMobile check_mobile = val_db.AccountMobiles.Where(x => x.Mobile_Number.Equals(number)).Where(x => !x.Status_Cd.Equals(delete_status)).SingleOrDefault();
                // not ais return 2
                // Validate Existance
                if (check_mobile != null)
                {
                    if (check_mobile.Status_Cd.Trim().Equals("AC") || check_mobile.Status_Cd.Trim().Equals("ACD"))
                    {
                        Account account = check_mobile.Account;

                        if (account.Status_Cd.ToString().Trim().Equals(FreebieStatus.AccountPTUU()) || account.Status_Cd.ToString().Trim().Equals(FreebieStatus.AccountPTU()))
                        {
                            return(7);
                        }

                        if (string.IsNullOrWhiteSpace(account.User_Name))
                        {
                            return(5);
                        }


                        return(3);
                    }
                    else
                    {
                        if (check_mobile.Status_Cd.Trim().Equals("IA"))
                        {
                            return(4);
                        }
                        return(3);
                    }
                }
                else
                {
                    return(1);
                }
            }
        }