Esempio n. 1
0
        //get list of reStylers
        public static List<Comment> GetComments(string db, long lookId, int offset = 1, int limit = 20)
        {
            List<Comment> comments = new List<Comment>();

            string query = "EXEC [stp_SS_GetComments] @lookId=" + lookId + ",@offset=" + offset + ",@limit=" + limit;
            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())
                    {
                        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).ToLocalTime()).TotalSeconds;
                        comments.Add(comment);
                    }
                }
            }
            finally
            {
                myConnection.Close();
            }
            return comments;
        }
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).ToLocalTime()).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["OriginalLook"].ToString()))
                {
                    look.originalLookId = int.Parse(dr["OriginalLook"].ToString());
                }

                if (!string.IsNullOrEmpty(dr["contestId"].ToString()))
                {
                    look.contestId = int.Parse(dr["contestId"].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;
        }