Ejemplo n.º 1
0
        public static Dictionary <string, List <Product> > GetPopularProductsByFiltersv3(long userId, string db, int brandId = 0, string tags = null, string categoryId = null, string colorId = null,
                                                                                         int offset = 1, int limit = 20, int items = 5, string filter = null)
        {
            Dictionary <string, List <Product> > popularProducts = new Dictionary <string, List <Product> >();
            string query = "EXEC [stp_SS_GetPopularProductsByFilters] @uId =" + userId + ",@offset=" + offset + ",@limit=" + limit;

            if (categoryId != null)
            {
                query += ",@categoryId=N'" + categoryId + "'";
            }
            if (colorId != null)
            {
                query += ",@colorId=N'" + colorId + "'";
            }
            if (tags != null)
            {
                query += ",@tags=N'" + tags + "'";
            }
            if (brandId != 0)
            {
                query += ",@brandId=" + brandId;
            }
            if (items != 0)
            {
                query += ",@items=" + items;
            }
            if (filter != null)
            {
                query += ",@filter=" + filter;
            }

            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();

                    do
                    {
                        string         type        = string.Empty;
                        List <Product> closetItems = new List <Product>();

                        while (dr.Read())
                        {
                            type = dr["type"].ToString();
                            closetItems.Add(Product.GetProductFromSqlDataReader(dr));
                        }
                        if (!string.IsNullOrEmpty(type))
                        {
                            if (!popularProducts.ContainsKey(type))
                            {
                                popularProducts.Add(type, closetItems);
                            }
                            else
                            {
                                popularProducts[type] = closetItems;
                            }
                        }
                    } while (dr.NextResult());
                }
            }
            finally
            {
                myConnection.Close();
            }
            return(popularProducts);
        }
Ejemplo 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);
        }