Beispiel #1
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;
        }
Beispiel #2
0
        public static Tag GetTagFromSqlReader(SqlDataReader dr)
        {
            Tag tag = new Tag();

            tag.id = long.Parse(dr["Id"].ToString());
            tag.name = dr["Name"].ToString().Replace("''", "'");
            tag.imageUrl = dr["ImageUrl"].ToString();
            tag.prettyName = dr["PrettyName"].ToString();
            tag.BigBannerUrl = dr["BigBannerUrl"].ToString();
            tag.SwatchUrl = dr["SwatchUrl"].ToString();
            if (!string.IsNullOrEmpty(dr["Type"].ToString()))
            {
                int type = int.Parse(dr["Type"].ToString());
                switch (type)
                {
                    case 1: tag.type = TagType.ENTERTAINMENT;
                        break;
                    case 2: tag.type = TagType.STYLETRENDS;
                        break;
                    case 3: tag.type = TagType.PEOPLENEWSEVENTS;
                        break;
                    case 4: tag.type = TagType.DESIGNERS;
                        break;
                }

            }

            if (ColumnExists(dr, "following") && !string.IsNullOrEmpty(dr["following"].ToString()))
            {
                tag.IsFollowing = int.Parse(dr["following"].ToString());
            }
            if (ColumnExists(dr, "Editorial") && !string.IsNullOrEmpty(dr["Editorial"].ToString()))
            {
                tag.IsEditorial = bool.Parse(dr["Editorial"].ToString());
            }

            //if imageurl and bannerurl are empty - then default to amazon S3 url
            if (string.IsNullOrEmpty(tag.imageUrl) && tag.IsEditorial)
                tag.imageUrl = "https://s3-us-west-2.amazonaws.com/fkcontentpics/" + tag.name + "_small.png";

            if (string.IsNullOrEmpty(tag.BigBannerUrl) && tag.IsEditorial)
                tag.BigBannerUrl = "https://s3-us-west-2.amazonaws.com/fkcontentpics/" + tag.name + "_big.png";

            return tag;
        }