public static LeadEntry ManageLeadFromAction(ActionModel model) { CCSubmitDirect db = model.Database; if (db == null) { db = CCSubmitDirect.Instance; } int? leadid = db.LoadInt("SELECT leadID FROM [].tm_lead_action WHERE actionid=" + model.ActionID); LeadEntry leadEntry = null; if (leadid.HasValue) { // this action has valid lead, so we update values leadEntry = new LeadEntry(leadid.Value, db); leadEntry.CheckValue("first_name", model.FirstName); leadEntry.CheckValue("last_name", model.LastName); leadEntry.CheckValue("msisdn", model.Msisdn); leadEntry.CheckValue("email", model.Email); leadEntry.CheckValue("address", model.Address); leadEntry.CheckValue("zip", model.Zip); leadEntry.CheckValue("country", model.Country); leadEntry.CheckValue("city", model.City); } else { // this action does not have valid lead, so we need to create/find new one // we try to find it by email, msisdn leadid = LeadManager.GetLeadID(model.Msisdn, model.Email, db); if (leadid.HasValue) { // if we find it, we try to update values leadEntry = new LeadEntry(leadid.Value, db); leadEntry.CheckValue("first_name", model.FirstName); leadEntry.CheckValue("last_name", model.LastName); leadEntry.CheckValue("address", model.Address); leadEntry.CheckValue("email", model.Email); leadEntry.CheckValue("zip", model.Zip); leadEntry.CheckValue("country", model.Country); leadEntry.CheckValue("city", model.City); leadEntry.CheckValue("msisdn", model.Msisdn); leadEntry.UpdateSql += "actions_count=actions_count+1,"; } else { // if not, we create new one leadid = CreateLead(model.Msisdn, model.Email, model.FirstName, model.LastName, model.Country, model.Address, model.City, model.Zip, model.device_model, model.carrier, model.device_mf, model.device_os, 1); leadEntry = new LeadEntry(leadid.Value, db); } db.Transactional.Execute("UPDATE [].tm_lead_action SET leadid={0} WHERE actionid={1}", leadid.Value, model.ActionID); } leadEntry.FinishUpdateSql(); return(leadEntry); }
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); }