Exemple #1
0
        public ActionResult CreateUser(ControllerCreateUserModel input)
        {
            CCSubmitDirect db = CCSubmitDirect.Instance;

            if (string.IsNullOrEmpty(input.email))
            {
                return(this.Error("no_email"));
            }

            if (CCSubmitCacheManager.CheckIfEmailBlacklist(input.email))
            {
                return(this.Error("email_blacklist"));
            }

            // Legacy update
            (new LegacyCreateUser(db, this.Request, input)).Run();
            int?actionID = ActionManager.ExecuteAction(new ActionModel()
            {
                Database = db,
                ActionID = input.LeadActionID,
                AffID    = input.affid,
                PubID    = input.pubid,

                PrelanderType = input.type,
                prelander     = input.prelander,
                LanderName    = input.landerName,
                LanderUrl     = Request.UrlReferrer != null ? Request.UrlReferrer.AbsolutePath : string.Empty,
                Service       = input.Service,
                Event         = ActionModelEvent.InputEmail,
                ClickID       = input.lxid,
                ipAddress     = Request.UserHostAddress,

                Email = input.email
            });

            db.Transactional.Run();
            if (!actionID.HasValue)
            {
                return(this.Error("aid error"));
            }

            return(this.Success("success", actionID.Value));
        }
        public static int?Create(ActionModel input)
        {
            CCSubmitDirect db = input.Database;

            // check prelander type
            int?prelandertypeid = CCSubmitCacheManager.GetPrelanderTypeID(input.PrelanderType);

            if (!prelandertypeid.HasValue)
            {
                return(null);
            }

            // check prelander
            int?prelanderid = CCSubmitCacheManager.GetPrelanderID(input.prelander, prelandertypeid.Value);

            if (!prelanderid.HasValue)
            {
                return(null);
            }

            // get lead id
            int?leadid = null;

            if (!string.IsNullOrEmpty(input.Msisdn) || !string.IsNullOrEmpty(input.Email))
            {
                leadid = LeadManager.GetLeadID(input.Msisdn, input.Email, db);
                if (!leadid.HasValue)
                {
                    leadid = LeadManager.CreateLead(input.Msisdn, input.Email, input.FirstName, input.LastName, input.Country, input.Address, input.City, input.Zip, input.device_model, input.carrier, input.device_mf, input.device_os, 1, db);
                }
                else
                {
                    db.Transactional.Execute("UPDATE [].tm_lead SET actions_count=actions_count+1 WHERE leadid={0};", leadid.Value);
                }
            }

            int?actionid = db.Execute("INSERT INTO [].tm_lead_action (leadid, prelandertypeid, prelanderid, host, request, referrer, ip, updated)",
                                      leadid, prelandertypeid.Value, prelanderid.Value, input.host, input.request, input.referrer, input.ipAddress, DirectTime.Now);

            return(actionid);
        }
        public static int?ExecuteActionImplementation(ActionModel model)
        {
            if (model.ActionID == -1)
            {
                int?actionID = Create(model);
                if (!actionID.HasValue)
                {
                    return(null);
                }

                model.ActionID = actionID.Value;
            }

            DirectContainer dc        = model.Database.LoadContainer("SELECT * FROM [].tm_lead_action WHERE actionid=" + model.ActionID);
            LeadEntry       leadEntry = LeadManager.ManageLeadFromAction(model);

            if ((model.Event == ActionModelEvent.Redirection || model.Event == ActionModelEvent.InputEmail) && !dc.GetBoolean("input_redirect"))
            {
                ActionManager.Update(model, "input_redirect", "1", dc);
            }
            if (model.Event == ActionModelEvent.Create)
            {
                ActionManager.Update(model, "input_redirect", "1", dc);
            }
            if ((model.Event == ActionModelEvent.InputEmail && !dc.GetBoolean("input_email")) || (dc.GetBoolean("input_email") == false && !string.IsNullOrEmpty(leadEntry.Container.GetString("email"))))
            {
                ActionManager.Update(model, "input_email", "1", dc);
            }
            if ((model.Event == ActionModelEvent.InputContact && !dc.GetBoolean("input_contact")) || (dc.GetBoolean("input_contact") == false && !string.IsNullOrEmpty(leadEntry.Container.GetString("first_name")) && !string.IsNullOrEmpty(leadEntry.Container.GetString("last_name"))))
            {
                ActionManager.Update(model, "input_contact", "1", dc);
            }
            if (model.Event == ActionModelEvent.Subscribe)
            {
                ActionManager.Update(model, "has_subscription", "1", dc);
            }
            if (model.Event == ActionModelEvent.Chargeback)
            {
                ActionManager.Update(model, "has_chargeback", "1", dc);
            }
            if (model.Event == ActionModelEvent.Refund)
            {
                ActionManager.Update(model, "has_refund", "1", dc);
            }
            if (model.Event == ActionModelEvent.Charge)
            {
                ActionManager.Update(model, "times_charged", "++", dc);
            }
            if (model.Event == ActionModelEvent.Upsell)
            {
                ActionManager.Update(model, "times_upsell", "++", dc);
            }
            if (model.Event == ActionModelEvent.EndFlow)
            {
                ActionManager.Update(model, "provider_redirection", model.ProviderRedirection, dc);
                ActionManager.Update(model, "has_redirectedToProvider", "1", dc);
            }

            if (model.Service != ActionService.Default && (!dc.GetInt("serviceid").HasValue || (int)model.Service != dc.GetInt("serviceid").Value))
            {
                ActionManager.Update(model, "serviceid", ((int)model.Service).ToString(), dc);
            }
            if (!string.IsNullOrEmpty(model.ClickID) && !dc.GetString("clickid").Equals(model.ClickID))
            {
                ActionManager.Update(model, "clickid", model.ClickID, dc);
            }
            if (model.AffID.HasValue && (!dc.GetInt("affid").HasValue || (dc.GetInt("affid").HasValue&& model.AffID.Value != dc.GetInt("affid").Value)))
            {
                ActionManager.Update(model, "affid", model.AffID.ToString(), dc);
            }
            if (!string.IsNullOrEmpty(model.PubID) && !dc.GetString("pubid").Equals(model.PubID))
            {
                ActionManager.Update(model, "pubid", model.PubID, dc, true);
            }
            if (!string.IsNullOrEmpty(model.LanderUrl) && (string.IsNullOrEmpty(dc.GetString("lander_url")) || !dc.GetString("lander_url").Equals(model.LanderUrl)))
            {
                ActionManager.Update(model, "lander_url", model.LanderUrl, dc, true);
            }

            int?landerID = CCSubmitCacheManager.GetLanderID(model.LanderName, model.Database);

            if (landerID.HasValue && dc.GetInt("landerid").HasValue&& dc.GetInt("landerid").Value != landerID.Value)
            {
                ActionManager.Update(model, "landerid", landerID.Value.ToString(), dc);
            }

            model.SQLUpdateQuery = "UPDATE [].tm_lead_action SET " + model.SQLUpdateQuery + " updated=CURRENT_TIMESTAMP WHERE actionid=" + model.ActionID + ";";
            model.Database.Transactional.Execute(model.SQLUpdateQuery);
            model.Database.Transactional.Run();

            return(model.ActionID);
        }