Esempio n. 1
0
        public static List <Tag> getPopularHashtags(long userId, string db, int offset = 1, int limit = 10)
        {
            List <Tag> popularTags = new List <Tag>();

            string hpTags = GetTags();

            string query = "EXEC [stp_SS_GetPopularTags] @userId=" + userId + ",@offset=" + offset + ",@limit=" + limit + ",@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();

                    popularTags = Tag.GetTagsFromSqlReader(dr);
                }
            }
            finally
            {
                myConnection.Close();
            }

            return(popularTags);
        }
Esempio n. 2
0
        public static Look GetLookFromSqlReader(SqlDataReader dr)
        {
            Look look = new Look();

            look.products  = new List <Product>();
            look.Likers    = new List <UserProfile>();
            look.ReStylers = new List <UserProfile>();
            look.comments  = new List <Comment>();
            look.tags      = new List <Tag>();

            while (dr.Read())
            {
                if (dr != null)
                {
                    int vote = int.Parse(dr["Vote"].ToString());
                    if (vote != 2)
                    {
                        look.isLoved = true;
                    }
                }
            }
            dr.NextResult();

            while (dr.Read())
            {
                if (dr != null)
                {
                    look.isReStyled = true;
                }
            }
            dr.NextResult();

            //top likers
            while (dr.Read())
            {
                UserProfile liker = UserProfile.GetUserFromSqlReader(dr);
                look.Likers.Add(liker);
            }

            dr.NextResult();

            //top restylers
            while (dr.Read())
            {
                UserProfile reStyler = UserProfile.GetUserFromSqlReader(dr);
                look.ReStylers.Add(reStyler);
            }
            dr.NextResult();

            while (dr.Read())
            {
                Comment comment = new Comment();
                comment.id          = long.Parse(dr["CommentId"].ToString());
                comment.commenter   = UserProfile.GetUserFromSqlReader(dr);
                comment.commentText = dr["CommentText"].ToString().Replace("''", "'");
                DateTime commentTime = DateTime.Parse(dr["CommentCreateTime"].ToString());
                comment.commentTime = (commentTime - new DateTime(1970, 1, 1)).TotalSeconds;
                look.comments.Add(comment);
            }
            dr.NextResult();

            while (dr.Read())
            {
                look.id           = int.Parse(dr["Id"].ToString());
                look.upVote       = int.Parse(dr["UpVote"].ToString());
                look.downVote     = int.Parse(dr["DownVote"].ToString());
                look.title        = dr["Title"].ToString().Replace("''", "'");
                look.restyleCount = int.Parse(dr["ReStyleCount"].ToString());
                look.viewCount    = int.Parse(dr["ViewCount"].ToString());
                look.shareCount   = int.Parse(dr["ShareCount"].ToString());
                look.commentCount = int.Parse(dr["CommentCount"].ToString());
                if (!string.IsNullOrEmpty(dr["UpdateDate"].ToString()))
                {
                    DateTime updateTime = DateTime.Parse(dr["UpdateDate"].ToString());
                    look.updateTime = (updateTime - new DateTime(1970, 1, 1)).TotalSeconds;
                }
                if (!string.IsNullOrEmpty(dr["OriginalLook"].ToString()))
                {
                    look.originalLookId = int.Parse(dr["OriginalLook"].ToString());
                }

                if (!string.IsNullOrEmpty(dr["contestId"].ToString()))
                {
                    look.contestId = int.Parse(dr["contestId"].ToString());
                }
                if (!string.IsNullOrEmpty(dr["OOTD"].ToString()))
                {
                    int isOOTD = int.Parse(dr["OOTD"].ToString());
                    look.isOOTD = isOOTD == 1 ? true : false;
                }
                if (!string.IsNullOrEmpty(dr["OOTDdate"].ToString()))
                {
                    DateTime date = DateTime.Parse(dr["OOTDdate"].ToString());
                    date          = date.ToLocalTime();
                    look.OOTDdate = date.ToString("MMM dd");
                }
                if (!string.IsNullOrEmpty(dr["TagDetails"].ToString()))
                {
                    look.featuredTag = dr["TagDetails"].ToString();
                }
            }

            //if a look was found
            if (look.id != 0)
            {
                dr.NextResult();

                // read the creator
                while (dr.Read())
                {
                    look.creator = UserProfile.GetUserFromSqlReader(dr);
                }

                //read original User
                dr.NextResult();
                while (dr.Read())
                {
                    look.originalCreator = UserProfile.GetUserFromSqlReader(dr);
                }

                // read the tags
                dr.NextResult();
                List <Tag> tags = Tag.GetTagsFromSqlReader(dr);
                look.tags = tags;


                //read the products
                if (dr.NextResult())
                {
                    while (dr.Read())
                    {
                        look.products.Add(Product.GetProductFromSqlDataReader(dr));
                    }
                }
            }

            return(look);
        }