Ejemplo n.º 1
0
        public static Tag GetTagByName(string tagName, long userId, string db)
        {
            Tag tag = new Tag();

            string query = "EXEC [stp_SS_GetTagByName] @tagName=N'" + tagName + "', @userId=" + userId;

            SqlConnection myConnection = new SqlConnection(db);

            try
            {
                myConnection.Open();
                using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection))
                {
                    SqlCommand cmd = adp.SelectCommand;
                    cmd.CommandTimeout = 300000;
                    System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();

                    while (dr.Read())
                    {
                        tag = Tag.GetTagFromSqlReader(dr);
                    }
                }
            }
            finally
            {
                myConnection.Close();
            }

            return(tag);
        }
Ejemplo n.º 2
0
        public static Dictionary <TagType, List <Tag> > getFeaturedHashtags(long userId, string db)
        {
            Dictionary <TagType, List <Tag> > featuredTags = new Dictionary <TagType, List <Tag> >();

            string query = "EXEC [stp_SS_GetFeaturedTags] @userId=" + userId;

            SqlConnection myConnection = new SqlConnection(db);

            try
            {
                myConnection.Open();
                using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection))
                {
                    SqlCommand cmd = adp.SelectCommand;
                    cmd.CommandTimeout = 300000;
                    System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();

                    while (dr.Read())
                    {
                        Tag tag = Tag.GetTagFromSqlReader(dr);
                        if (!featuredTags.ContainsKey(tag.type))
                        {
                            List <Tag> tags = new List <Tag>();
                            tags.Add(tag);
                            featuredTags.Add(tag.type, tags);
                        }
                        else
                        {
                            featuredTags[tag.type].Add(tag);
                        }
                    }

                    //dr.NextResult();
                    //while (dr.Read())
                    //{
                    //    Tag tag = Tag.GetTagFromSqlReader(dr);
                    //    if (!featuredTags.ContainsKey(tag.type))
                    //    {
                    //        List<Tag> tags = new List<Tag>();
                    //        tags.Add(tag);
                    //        featuredTags.Add(tag.type, tags);
                    //    }
                    //    else
                    //    {
                    //        featuredTags[tag.type].Add(tag);
                    //    }
                    //}
                }
            }
            finally
            {
                myConnection.Close();
            }

            return(featuredTags);
        }
Ejemplo n.º 3
0
        public static List <Tag> GetTagsFromSqlReader(SqlDataReader dr)
        {
            List <Tag> tags = new List <Tag>();

            while (dr.Read())
            {
                Tag tag = Tag.GetTagFromSqlReader(dr);
                tags.Add(tag);
            }

            return(tags);
        }
Ejemplo n.º 4
0
        public static Dictionary <string, object> GetTagMetaInfo(long userId, long tagId, int noOfLooks, int noOfItems, int noOfStylists, string db)
        {
            Dictionary <string, object> metaInfo = new Dictionary <string, object>();

            string query = "EXEC [stp_SS_GetTagMetaInfo] @tagId=" + tagId + ",@userId=" + userId + ",@noOfLooks=" + noOfLooks + ",@noOfItems=" + noOfItems + ",@noOfStylists=" + noOfStylists;

            SqlConnection myConnection = new SqlConnection(db);

            try
            {
                myConnection.Open();
                using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection))
                {
                    SqlCommand cmd = adp.SelectCommand;
                    cmd.CommandTimeout = 300000;
                    System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();

                    //Get popular looks
                    List <Look> popularLooks = new List <Look>();

                    int counter = 0; int countLooks = 0;
                    while (dr.Read())
                    {
                        countLooks = int.Parse(dr["total"].ToString());
                    }
                    dr.NextResult();
                    do
                    {
                        Look look = Look.GetLookFromSqlReader(dr);
                        popularLooks.Add(look);
                        counter++;
                        if (counter >= noOfLooks || counter >= countLooks)
                        {
                            break;
                        }
                    } while (dr.NextResult());
                    metaInfo.Add("Popular Looks", popularLooks);

                    /*Get fresh looks
                     * List<Look> recentLooks = new List<Look>();
                     * dr.NextResult();
                     * counter = 0; countLooks = 0;
                     * while (dr.Read())
                     * {
                     *  countLooks = int.Parse(dr["total"].ToString());
                     * }
                     * dr.NextResult();
                     * do
                     * {
                     *  Look look = Look.GetLookFromSqlReader(dr);
                     *  recentLooks.Add(look);
                     *  counter++;
                     *  if (counter >= noOfLooks || counter >= countLooks)
                     *      break;
                     * } while (dr.NextResult());
                     * metaInfo.Add("Recent Looks", recentLooks);*/

                    //Get top stylists
                    List <UserProfile> stylists = new List <UserProfile>();
                    dr.NextResult();
                    while (dr.Read())
                    {
                        UserProfile user = UserProfile.GetUserFromSqlReader(dr);
                        stylists.Add(user);
                    }
                    metaInfo.Add("Top Stylists", stylists);

                    /*Get top products
                     * List<Product> topItems = new List<Product>();
                     * dr.NextResult();
                     *
                     * while (dr.Read())
                     * {
                     *  topItems.Add(Product.GetProductFromSqlDataReader(dr));
                     * }
                     * metaInfo.Add("Top Items", topItems);*/

                    dr.NextResult();
                    Tag tag = new Tag();
                    while (dr.Read())
                    {
                        tag = Tag.GetTagFromSqlReader(dr);
                    }
                    metaInfo.Add("Tag", tag);
                }
            }
            finally
            {
                myConnection.Close();
            }

            return(metaInfo);
        }
Ejemplo n.º 5
0
        public static Dictionary <int, List <Object> > getHPFeaturedTags(long userId, string db)
        {
            Dictionary <int, List <Object> > featuredTags = new Dictionary <int, List <Object> >();

            HomeTheme edTags = GetEditorialTags();
            //add the editorial info

            List <Object> editorialInfo = new List <Object>();

            editorialInfo.Add(edTags.editionType);
            editorialInfo.Add(edTags.editionNumber);
            editorialInfo.Add(edTags.headline);
            featuredTags.Add(0, editorialInfo);

            string hpTags = string.Empty;

            foreach (Theme theme in edTags.themes)
            {
                hpTags += (theme.themeName + ",");
            }
            hpTags = hpTags.TrimEnd(',');

            string query = "EXEC [stp_SS_GetHPFeaturedTags] @userId=" + userId + ",@hpTags='" + hpTags.Replace("'", "''") + "'";

            SqlConnection myConnection = new SqlConnection(db);

            try
            {
                myConnection.Open();
                using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection))
                {
                    SqlCommand cmd = adp.SelectCommand;
                    cmd.CommandTimeout = 300000;
                    System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();

                    while (dr.Read())
                    {
                        Tag tag  = Tag.GetTagFromSqlReader(dr);
                        int slot = 0;
                        if (ColumnExists(dr, "slot") && !string.IsNullOrEmpty(dr["slot"].ToString()))
                        {
                            slot = int.Parse(dr["slot"].ToString());
                        }
                        if (!featuredTags.ContainsKey(slot))
                        {
                            List <Object> tags = new List <Object>();
                            tags.Add(tag);
                            featuredTags.Add(slot, tags);
                        }
                        else
                        {
                            featuredTags[slot].Add(tag);
                        }
                    }
                }
            }
            finally
            {
                myConnection.Close();
            }

            return(featuredTags);
        }