Beispiel #1
0
        public int ImportCampaignAccountRecepients(string ticket, TransitCampaignAccountRecepient[] recepients)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session             = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec   = new ManagedSecurityContext(session, ticket);
                ITransaction           trans = session.BeginTransaction();

                int count = 0;

                try
                {
                    foreach (TransitCampaignAccountRecepient recepient in recepients)
                    {
                        CampaignAccountRecepient existing = (CampaignAccountRecepient)session.CreateCriteria(typeof(CampaignAccountRecepient))
                                                            .Add(Expression.Eq("Account.Id", recepient.AccountId))
                                                            .Add(Expression.Eq("Campaign.Id", recepient.CampaignId))
                                                            .UniqueResult();

                        if (existing != null)
                        {
                            continue;
                        }

                        ManagedCampaignAccountRecepient newrecepient = new ManagedCampaignAccountRecepient(session);
                        newrecepient.CreateOrUpdate(recepient, sec);
                        count++;
                    }

                    trans.Commit();
                    SnCore.Data.Hibernate.Session.Flush();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }

                return(count);
            }
        }
Beispiel #2
0
        public int ImportCampaignAccountPropertyValues(string ticket, int campaign_id, int pid, string value, bool unset)
        {
            int userid = ManagedAccount.GetAccountIdFromTicket(ticket);

            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session           = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);

                ITransaction trans = session.BeginTransaction();

                int count = 0;

                try
                {
                    StringBuilder squery = new StringBuilder();
                    squery.Append(
                        "SELECT {Account.*} FROM {Account} WHERE Account_Id IN (" +
                        " SELECT Account.Account_Id FROM Account INNER JOIN AccountPropertyValue" +
                        " ON Account.Account_Id = AccountPropertyValue.Account_Id" +
                        " WHERE AccountPropertyValue.AccountProperty_Id = " + pid.ToString() +
                        " AND AccountPropertyValue.Value LIKE '" + Renderer.SqlEncode(value) + "')");

                    if (unset)
                    {
                        squery.AppendFormat(
                            " OR Account_Id NOT IN (" +
                            " SELECT Account.Account_Id FROM Account INNER JOIN AccountPropertyValue" +
                            " ON Account.Account_Id = AccountPropertyValue.Account_Id" +
                            " AND AccountPropertyValue.AccountProperty_Id = {0}" +
                            ")", pid);
                    }

                    ISQLQuery query = session.CreateSQLQuery(squery.ToString())
                                      .AddEntity("Account", typeof(Account));

                    IList <Account> list = query.List <Account>();

                    foreach (Account account in list)
                    {
                        ManagedAccount ma = new ManagedAccount(session, account);

                        if (!ma.HasVerifiedEmail(sec))
                        {
                            continue;
                        }

                        CampaignAccountRecepient existing = (CampaignAccountRecepient)session.CreateCriteria(typeof(CampaignAccountRecepient))
                                                            .Add(Expression.Eq("Account.Id", ma.Id))
                                                            .Add(Expression.Eq("Campaign.Id", campaign_id))
                                                            .UniqueResult();

                        if (existing != null)
                        {
                            continue;
                        }

                        ManagedCampaignAccountRecepient newrecepient        = new ManagedCampaignAccountRecepient(session);
                        TransitCampaignAccountRecepient newtransitrecepient = new TransitCampaignAccountRecepient();
                        newtransitrecepient.AccountId  = ma.Id;
                        newtransitrecepient.CampaignId = campaign_id;
                        newtransitrecepient.Created    = newtransitrecepient.Modified = DateTime.UtcNow;
                        newtransitrecepient.Sent       = false;
                        newrecepient.CreateOrUpdate(newtransitrecepient, sec);
                        count++;
                    }

                    trans.Commit();
                    SnCore.Data.Hibernate.Session.Flush();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }

                return(count);
            }
        }
Beispiel #3
0
        public int ImportCampaignAccountLocation(string ticket, int campaign_id, string country, string state, string city)
        {
            int userid = ManagedAccount.GetAccountIdFromTicket(ticket);

            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session           = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);

                ITransaction trans = session.BeginTransaction();

                AccountActivityQueryOptions options = new AccountActivityQueryOptions();
                options.City         = city;
                options.Country      = country;
                options.State        = state;
                options.PicturesOnly = false;
                options.BloggersOnly = false;

                int count = 0;

                try
                {
                    IQuery query = session.CreateQuery(options.CreateQuery());
                    IEnumerator <Account> enumerator = query.Enumerable <Account>().GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        ManagedAccount ma = new ManagedAccount(session, enumerator.Current);

                        if (!ma.HasVerifiedEmail(sec))
                        {
                            continue;
                        }

                        CampaignAccountRecepient existing = session.CreateCriteria(typeof(CampaignAccountRecepient))
                                                            .Add(Expression.Eq("Account.Id", ma.Id))
                                                            .Add(Expression.Eq("Campaign.Id", campaign_id))
                                                            .UniqueResult <CampaignAccountRecepient>();

                        if (existing != null)
                        {
                            continue;
                        }

                        ManagedCampaignAccountRecepient newrecepient        = new ManagedCampaignAccountRecepient(session);
                        TransitCampaignAccountRecepient newtransitrecepient = new TransitCampaignAccountRecepient();
                        newtransitrecepient.AccountId  = ma.Id;
                        newtransitrecepient.CampaignId = campaign_id;
                        newtransitrecepient.Created    = newtransitrecepient.Modified = DateTime.UtcNow;
                        newtransitrecepient.Sent       = false;
                        newrecepient.CreateOrUpdate(newtransitrecepient, sec);
                        count++;
                    }

                    trans.Commit();
                    SnCore.Data.Hibernate.Session.Flush();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }

                return(count);
            }
        }
Beispiel #4
0
        public int ImportCampaignAccountEmails(string ticket, int campaign_id, bool verified_emails, bool unverified_emails)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session             = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec   = new ManagedSecurityContext(session, ticket);
                ITransaction           trans = session.BeginTransaction();

                int count = 0;

                try
                {
                    ICriteria c    = session.CreateCriteria(typeof(Account));
                    IList     list = c.List();

                    foreach (Account account in list)
                    {
                        ManagedAccount ma = new ManagedAccount(session, account);

                        if (ma.HasVerifiedEmail(sec))
                        {
                            if (!verified_emails)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (!unverified_emails)
                            {
                                continue;
                            }
                        }

                        CampaignAccountRecepient existing = (CampaignAccountRecepient)session.CreateCriteria(typeof(CampaignAccountRecepient))
                                                            .Add(Expression.Eq("Account.Id", ma.Id))
                                                            .Add(Expression.Eq("Campaign.Id", campaign_id))
                                                            .UniqueResult();

                        if (existing != null)
                        {
                            continue;
                        }

                        ManagedCampaignAccountRecepient newrecepient        = new ManagedCampaignAccountRecepient(session);
                        TransitCampaignAccountRecepient newtransitrecepient = new TransitCampaignAccountRecepient();
                        newtransitrecepient.AccountId  = ma.Id;
                        newtransitrecepient.CampaignId = campaign_id;
                        newtransitrecepient.Created    = newtransitrecepient.Modified = DateTime.UtcNow;
                        newtransitrecepient.Sent       = false;
                        newrecepient.CreateOrUpdate(newtransitrecepient, sec);
                        count++;
                    }

                    trans.Commit();
                    SnCore.Data.Hibernate.Session.Flush();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }

                return(count);
            }
        }
Beispiel #5
0
        public int ImportCampaignAccountPropertyValues(string ticket, int campaign_id, int pid, string value, bool unset)
        {
            int userid = ManagedAccount.GetAccountIdFromTicket(ticket);
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);

                ITransaction trans = session.BeginTransaction();

                int count = 0;

                try
                {
                    StringBuilder squery = new StringBuilder();
                    squery.Append(
                        "SELECT {Account.*} FROM {Account} WHERE Account_Id IN (" +
                        " SELECT Account.Account_Id FROM Account INNER JOIN AccountPropertyValue" +
                        " ON Account.Account_Id = AccountPropertyValue.Account_Id" +
                        " WHERE AccountPropertyValue.AccountProperty_Id = " + pid.ToString() +
                        " AND AccountPropertyValue.Value LIKE '" + Renderer.SqlEncode(value) + "')");

                    if (unset)
                    {
                        squery.AppendFormat(
                            " OR Account_Id NOT IN (" +
                            " SELECT Account.Account_Id FROM Account INNER JOIN AccountPropertyValue" +
                            " ON Account.Account_Id = AccountPropertyValue.Account_Id" +
                            " AND AccountPropertyValue.AccountProperty_Id = {0}" +
                            ")", pid);
                    }

                    ISQLQuery query = session.CreateSQLQuery(squery.ToString())
                        .AddEntity("Account", typeof(Account));

                    IList<Account> list = query.List<Account>();

                    foreach (Account account in list)
                    {
                        ManagedAccount ma = new ManagedAccount(session, account);

                        if (!ma.HasVerifiedEmail(sec))
                            continue;

                        CampaignAccountRecepient existing = (CampaignAccountRecepient)session.CreateCriteria(typeof(CampaignAccountRecepient))
                            .Add(Expression.Eq("Account.Id", ma.Id))
                            .Add(Expression.Eq("Campaign.Id", campaign_id))
                            .UniqueResult();

                        if (existing != null)
                            continue;

                        ManagedCampaignAccountRecepient newrecepient = new ManagedCampaignAccountRecepient(session);
                        TransitCampaignAccountRecepient newtransitrecepient = new TransitCampaignAccountRecepient();
                        newtransitrecepient.AccountId = ma.Id;
                        newtransitrecepient.CampaignId = campaign_id;
                        newtransitrecepient.Created = newtransitrecepient.Modified = DateTime.UtcNow;
                        newtransitrecepient.Sent = false;
                        newrecepient.CreateOrUpdate(newtransitrecepient, sec);
                        count++;
                    }

                    trans.Commit();
                    SnCore.Data.Hibernate.Session.Flush();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }

                return count;
            }
        }
Beispiel #6
0
        public int ImportCampaignAccountLocation(string ticket, int campaign_id, string country, string state, string city)
        {
            int userid = ManagedAccount.GetAccountIdFromTicket(ticket);
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);

                ITransaction trans = session.BeginTransaction();

                AccountActivityQueryOptions options = new AccountActivityQueryOptions();
                options.City = city;
                options.Country = country;
                options.State = state;
                options.PicturesOnly = false;
                options.BloggersOnly = false;

                int count = 0;

                try
                {
                    IQuery query = session.CreateQuery(options.CreateQuery());
                    IEnumerator<Account> enumerator = query.Enumerable<Account>().GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        ManagedAccount ma = new ManagedAccount(session, enumerator.Current);

                        if (!ma.HasVerifiedEmail(sec))
                            continue;

                        CampaignAccountRecepient existing = session.CreateCriteria(typeof(CampaignAccountRecepient))
                            .Add(Expression.Eq("Account.Id", ma.Id))
                            .Add(Expression.Eq("Campaign.Id", campaign_id))
                            .UniqueResult<CampaignAccountRecepient>();

                        if (existing != null)
                            continue;

                        ManagedCampaignAccountRecepient newrecepient = new ManagedCampaignAccountRecepient(session);
                        TransitCampaignAccountRecepient newtransitrecepient = new TransitCampaignAccountRecepient();
                        newtransitrecepient.AccountId = ma.Id;
                        newtransitrecepient.CampaignId = campaign_id;
                        newtransitrecepient.Created = newtransitrecepient.Modified = DateTime.UtcNow;
                        newtransitrecepient.Sent = false;
                        newrecepient.CreateOrUpdate(newtransitrecepient, sec);
                        count++;
                    }

                    trans.Commit();
                    SnCore.Data.Hibernate.Session.Flush();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }

                return count;
            }
        }
Beispiel #7
0
        public int ImportCampaignAccountEmails(string ticket, int campaign_id, bool verified_emails, bool unverified_emails)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
                ITransaction trans = session.BeginTransaction();

                int count = 0;

                try
                {
                    ICriteria c = session.CreateCriteria(typeof(Account));
                    IList list = c.List();

                    foreach (Account account in list)
                    {
                        ManagedAccount ma = new ManagedAccount(session, account);

                        if (ma.HasVerifiedEmail(sec))
                        {
                            if (!verified_emails)
                                continue;
                        }
                        else
                        {
                            if (!unverified_emails)
                                continue;
                        }

                        CampaignAccountRecepient existing = (CampaignAccountRecepient)session.CreateCriteria(typeof(CampaignAccountRecepient))
                            .Add(Expression.Eq("Account.Id", ma.Id))
                            .Add(Expression.Eq("Campaign.Id", campaign_id))
                            .UniqueResult();

                        if (existing != null)
                            continue;

                        ManagedCampaignAccountRecepient newrecepient = new ManagedCampaignAccountRecepient(session);
                        TransitCampaignAccountRecepient newtransitrecepient = new TransitCampaignAccountRecepient();
                        newtransitrecepient.AccountId = ma.Id;
                        newtransitrecepient.CampaignId = campaign_id;
                        newtransitrecepient.Created = newtransitrecepient.Modified = DateTime.UtcNow;
                        newtransitrecepient.Sent = false;
                        newrecepient.CreateOrUpdate(newtransitrecepient, sec);
                        count++;
                    }

                    trans.Commit();
                    SnCore.Data.Hibernate.Session.Flush();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }

                return count;
            }
        }
Beispiel #8
0
        public int ImportCampaignAccountRecepients(string ticket, TransitCampaignAccountRecepient[] recepients)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
                ITransaction trans = session.BeginTransaction();

                int count = 0;

                try
                {
                    foreach (TransitCampaignAccountRecepient recepient in recepients)
                    {
                        CampaignAccountRecepient existing = (CampaignAccountRecepient)session.CreateCriteria(typeof(CampaignAccountRecepient))
                            .Add(Expression.Eq("Account.Id", recepient.AccountId))
                            .Add(Expression.Eq("Campaign.Id", recepient.CampaignId))
                            .UniqueResult();

                        if (existing != null)
                            continue;

                        ManagedCampaignAccountRecepient newrecepient = new ManagedCampaignAccountRecepient(session);
                        newrecepient.CreateOrUpdate(recepient, sec);
                        count++;
                    }

                    trans.Commit();
                    SnCore.Data.Hibernate.Session.Flush();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }

                return count;
            }
        }