예제 #1
0
        public Cohort Add(Cohort cohort)
        {
            Cohort rtnCohort = null;

            using (DbCommand cmd = _db.GetSqlStringCommand(CohortQueries.AddCohort))
            {
                _db.AddInParameter(cmd, "@Name", DbType.String, cohort.Name);
                _db.AddInParameter(cmd, "@SystemName", DbType.String, cohort.SystemName);
                _db.AddInParameter(cmd, "@Type", DbType.String, cohort.TypeName);
                _db.AddInParameter(cmd, "@CreatedBy", DbType.String, cohort.CreatedBy);

                using (IDataReader reader = _db.ExecuteReader(cmd))
                {
                    while (reader.Read())
                    {
                        rtnCohort = ReaderToCohort(reader);
                    }
                }
            }

            foreach (string key in cohort.Properties.Keys)
            {
                using (DbCommand cmd = _db.GetSqlStringCommand(CohortQueries.AddCohortProperty))
                {
                    _db.AddInParameter(cmd, "@CohortId", DbType.Int32, rtnCohort.Id);
                    _db.AddInParameter(cmd, "@Name", DbType.String, key);
                    _db.AddInParameter(cmd, "@Value", DbType.String, cohort.Properties[key]);

                    _db.ExecuteNonQuery(cmd);
                }
            }

            return rtnCohort;
        }
예제 #2
0
        public void Delete(Cohort cohort)
        {
            using (DbCommand cmd = _db.GetSqlStringCommand(CohortQueries.DeleteCohort))
            {
                _db.AddInParameter(cmd, "@CohortId", DbType.Int32, cohort.Id);
                _db.AddInParameter(cmd, "@UpdatedBy", DbType.String, cohort.UpdatedBy);

                _db.ExecuteNonQuery(cmd);
            }
        }
예제 #3
0
 private bool userIsInCohort(Visitor visitor, Cohort cohort)
 {
     loadCohortPrerequisites(visitor, cohort);
     if (visitor.Cohorts.FirstOrDefault(a=>a.SystemName == cohort.SystemName) != null)
     {
         return true;
     }
     if (cohort.IsInCohort(visitor))
     {
         visitor.Request.Cohorts.Add(cohort);
         visitor.Cohorts.Add(cohort);
         return true;
     }
     return false;
 }
예제 #4
0
        private void loadCohortPrerequisites(Visitor visitor, Cohort cohort)
        {
            //New Visitors don't have anything else
            if (!visitor.IsNew)
            {
                if (!visitor.CohortsLoaded)
                {
                    CurrentVisitor = _visitProvider.GetCohorts(visitor);

                    //short circuit if user is in cohort already.
                    if (visitor.Cohorts.FirstOrDefault(a => a.SystemName == cohort.SystemName) != null)
                    {
                        return;
                    }
                }

                if (cohort.RequiresAttributes && !visitor.AttributesLoaded)
                {
                    visitor = _visitProvider.GetAttributes(visitor);
                    visitor.AttributesLoaded = true;
                }

                if (cohort.RequiresLandingUrls && !visitor.LandingUrlsLoaded)
                {
                    visitor = _visitProvider.GetLandingPages(visitor);
                    visitor.LandingUrlsLoaded = true;
                }

                if (cohort.RequiresLandingUrls && !string.IsNullOrEmpty(visitor.Request.LandingUrl))
                {
                    visitor.LandingUrls.Add(visitor.Request.LandingUrl);
                }

                if (cohort.RequiresReferrers && !visitor.ReferrersLoaded)
                {
                    visitor = _visitProvider.GetReferrers(visitor);
                    visitor.ReferrersLoaded = true;
                }

                if (cohort.RequiresReferrers && !string.IsNullOrEmpty(visitor.Request.FilteredReferrer))
                {
                    visitor.Referrers.Add(visitor.Request.FilteredReferrer);
                }

            }
        }
예제 #5
0
        public Cohort Update(Cohort cohort)
        {
            using (DbCommand cmd = _db.GetSqlStringCommand(CohortQueries.UpdateCohort))
            {
                _db.AddInParameter(cmd, "@Name", DbType.String, cohort.Name);
                _db.AddInParameter(cmd, "@UpdatedBy", DbType.String, cohort.UpdatedBy);
                _db.AddInParameter(cmd, "@CohortId", DbType.Int32, cohort.Id);

                _db.ExecuteNonQuery(cmd);
            }

            using (DbCommand cmd = _db.GetSqlStringCommand(CohortQueries.DeleteCohortProperties))
            {
                _db.AddInParameter(cmd, "@CohortId", DbType.Int32, cohort.Id);
                _db.ExecuteNonQuery(cmd);
            }

            foreach (string key in cohort.Properties.Keys)
            {
                using (DbCommand cmd = _db.GetSqlStringCommand(CohortQueries.AddCohortProperty))
                {
                    _db.AddInParameter(cmd, "@CohortId", DbType.Int32, cohort.Id);
                    _db.AddInParameter(cmd, "@Name", DbType.String, key);
                    _db.AddInParameter(cmd, "@Value", DbType.String, cohort.Properties[key]);

                    _db.ExecuteNonQuery(cmd);
                }
            }

            return cohort;
        }