Exemple #1
0
        static void Main(string[] args)
        {
            string db = @"Data Source=mssql2008.reliablesite.net,14333,14333;Initial Catalog=facebook;Persist Security Info=True;User ID=nirveek_de;Password=Fashionkred123";
            string query = "EXEC [stp_SS_NewsLetter] @contestId=" + contestId;
            SqlConnection myConnection = new SqlConnection(db);
            Look look = new Look();
            List<long> subscriberList = new List<long>();

            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())
                    {
                        long fbId = long.Parse(dr["FacebookId"].ToString());
                        subscriberList.Add(fbId);
                    }
                    dr.NextResult();

                    look = Look.GetLookFromSqlReader(dr);
                }

                 SendLookNotification(subscriberList, look);

            }
            finally
            {
                myConnection.Close();
            }
        }
Exemple #2
0
        //Get a random product combo from the specified category and retailer

        public static Look GetRandomLook(int contestId, long userId, string db)
        {
            //Outfit choosing logic
            //Find outfits that are created/voted by friends which the user hasn't voted yet- if not try to find recently created best voted outfit

            Look look = new Look();

            look.products = new List <Product>();

            string        query        = "EXEC [stp_SS_GetRandomLook] @contestId=" + contestId + ", @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();

                    look = GetLookFromSqlReader(dr);
                }
            }
            finally
            {
                myConnection.Close();
            }
            return(look);
        }
Exemple #3
0
        public static List <Look> GetPopularLooksOfWeek(string db, long uId, int offset = 1, int limit = 15)
        {
            List <Look> looks = new List <Look>();
            string      query = "EXEC [stp_SS_GetPopularLooksOfWeek] @userId=" + uId + ",@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();

                    looks = Look.GetLooksFromSqlReader(dr);
                }
            }
            finally
            {
                myConnection.Close();
            }

            return(looks);
        }
Exemple #4
0
        //Get look By specific id
        public static Look GetLookById(long id, long userId, string db)
        {
            Look look = new Look();

            look.products = new List <Product>();

            string        query        = "EXEC [stp_SS_GetLookWithUserId] @id=" + id + ", @uid=" + 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();
                    look = GetLookFromSqlReader(dr);
                }
            }
            finally
            {
                myConnection.Close();
            }
            return(look);
        }
Exemple #5
0
        //Get look containing a particular product - helps product.aspx redirect
        public static Look GetLookByProductId(long id, string db)
        {
            Look look = new Look();

            look.products = new List <Product>();

            string        query        = "EXEC [stp_SS_GetLookByProduct] @id=" + id;
            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())
                    {
                        look.id       = int.Parse(dr["Id"].ToString());
                        look.upVote   = int.Parse(dr["UpVote"].ToString());
                        look.downVote = int.Parse(dr["DownVote"].ToString());
                    }
                }
            }
            finally
            {
                myConnection.Close();
            }
            return(look);
        }
Exemple #6
0
        //Get looks for homepage
        public static List <Look> GetLooksFromSqlReader(SqlDataReader dr)
        {
            List <Look> looks = new List <Look>();

            do
            {
                Look look = Look.GetLookFromSqlReader(dr);
                looks.Add(look);
            } while (dr.NextResult());

            return(looks);
        }
Exemple #7
0
        public static List <Look> GetTaggedLooks(string db, long uId, long tagId, int offset = 1, int limit = 20, bool isPopular = false)
        {
            List <Look> looks = new List <Look>();

            string query;

            if (isPopular)
            {
                query = "EXEC [stp_SS_GetTaggedPopularLooks] @tagId=" + tagId + ",@userId=" + uId + ",@offset=" + offset + ",@limit=" + limit;
            }
            else
            {
                query = "EXEC [stp_SS_GetTaggedLooks] @tagId=" + tagId + ",@userId=" + uId + ",@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();
                    int countLooks = 0;
                    while (dr.Read())
                    {
                        countLooks = int.Parse(dr["total"].ToString());
                    }
                    dr.NextResult();
                    looks = Look.GetLooksFromSqlReader(dr);
                }
            }
            finally
            {
                myConnection.Close();
            }

            if (looks.Count == 0)
            {
                looks = null;
            }

            return(looks);
        }
Exemple #8
0
        public static void SendLookNotification(List<long> subscriberList, Look look)
        {
            var client = new FacebookClient();
            client.AppId = appId;
            client.AppSecret = appSecret;

            dynamic response = client.Get("oauth/access_token",
            new
            {
                client_id = appId,
                client_secret = appSecret,
                grant_type = "client_credentials"
            });
            string appAccessToken = response.access_token;

            foreach (long subscriber in subscriberList)
            {
                if (subscriber > 0)
                {
                    string path = "/" + subscriber + "/notifications?access_token=" + appAccessToken;
                    string templateString = "#LookOfTheWeek: Check out the top voted look of the week in FashionKred!";

                    var parameters = new Dictionary<string, object>
                    {
                            { "href" ,  "?lid=" + look.id },
                            { "template" ,  templateString },
                            { "ref" ,  "looknotifications" }
                    };

                    try
                    {
                        client.Post(path, parameters);
                    }
                    catch(FacebookOAuthException ex)
                    {
                        //log exception and unsubscribe
                    }
                }
            }
        }
Exemple #9
0
        public static Look SaveLook(string db, string productMap, long userId, string tagMap, string title, long originalLookId = 0, long editLookId = 0, bool isFeaturedStylist = false)
        {
            Look look = new Look();

            string query = "EXEC [stp_SS_SaveLook] @product='" + productMap + "', @uid=" + userId + ",@tag='" + tagMap.Replace("'", "''") + "', @title=N'" + title.Replace("'", "''") + "'";

            if (originalLookId != 0)
            {
                query += (", @originalLook=" + originalLookId);
            }

            if (editLookId != 0)
            {
                query += (", @editLookId=" + editLookId);
            }
            if (isFeaturedStylist)
            {
                query += (", @isFeaturedStylist=" + 1);
            }
            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();

                    look = Look.GetLookFromSqlReader(dr);
                }
            }
            finally
            {
                myConnection.Close();
            }
            return(look);
        }
Exemple #10
0
        public static List <Look> GetHomePageLooks(string db, long uId, int offset = 1, int limit = 10, bool isFilter = true)
        {
            List <Look> looks = new List <Look>();
            string      query;

            if (isFilter)
            {
                query = "EXEC [stp_SS_GetHomePageLooks] @userId=" + uId + ",@offset=" + offset + ",@limit=" + limit;
            }
            else
            {
                query = "EXEC [stp_SS_GetHomePageLooks_NoFilter] @userId=" + uId + ",@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();

                    looks = Look.GetLooksFromSqlReader(dr);
                }
            }
            finally
            {
                myConnection.Close();
            }

            return(looks);
        }
Exemple #11
0
        //Get a random product combo from the specified category and retailer
        public static Look GetRandomLook(int contestId, long userId, string db)
        {
            //Outfit choosing logic
            //Find outfits that are created/voted by friends which the user hasn't voted yet- if not try to find recently created best voted outfit

            Look look = new Look();
            look.products = new List<Product>();

            string query = "EXEC [stp_SS_GetRandomLook] @contestId=" + contestId + ", @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();

                    look = GetLookFromSqlReader(dr);
                }
            }
            finally
            {
                myConnection.Close();
            }
            return look;
        }
Exemple #12
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;
        }
Exemple #13
0
        //Get look containing a particular product - helps product.aspx redirect
        public static Look GetLookByProductId(long id, string db)
        {
            Look look = new Look();
            look.products = new List<Product>();

            string query = "EXEC [stp_SS_GetLookByProduct] @id=" + id;
            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())
                    {
                        look.id = int.Parse(dr["Id"].ToString());
                        look.upVote = int.Parse(dr["UpVote"].ToString());
                        look.downVote = int.Parse(dr["DownVote"].ToString());
                    }
                }
            }
            finally
            {
                myConnection.Close();
            }
            return look;
        }
Exemple #14
0
        //Get look By specific id
        public static Look GetLookById(long id, long userId, string db)
        {
            Look look = new Look();
            look.products = new List<Product>();

            string query = "EXEC [stp_SS_GetLookWithUserId] @id=" + id + ", @uid=" + 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();
                    look = GetLookFromSqlReader(dr);
                }
            }
            finally
            {
                myConnection.Close();
            }
            return look;
        }
Exemple #15
0
        public static List <Object> GetLastNotifications(long userId, string db, int offset = 1, int limit = 20)
        {
            List <object> notifications = new List <object>();
            SqlConnection myConnection  = new SqlConnection(db);

            try
            {
                myConnection.Open();
                string query = "EXEC [stp_SS_GetLastNotifications] @userId=" + userId + ",@offset=" + offset + ",@limit=" + limit;
                using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection))
                {
                    SqlCommand cmd = adp.SelectCommand;
                    cmd.CommandTimeout = 300000;
                    System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();

                    while (dr.Read())
                    {
                        NotificationType type = (NotificationType)int.Parse(dr["Type"].ToString());
                        if (type == NotificationType.Contest)
                        {
                            Contest contest = new Contest();
                            contest.Name  = dr["contestName"].ToString();
                            contest.TagId = int.Parse(dr["TagId"].ToString());
                            contest.Image = "https://s3-us-west-2.amazonaws.com/fkcontentpics/" + contest.Name + "_small.png";
                            contest.Type  = type;
                            DateTime CreateTime = DateTime.Parse(dr["CreateDate"].ToString());
                            contest.CreateTime = (CreateTime - new DateTime(1970, 1, 1)).TotalSeconds;
                            notifications.Add(contest);
                        }

                        else
                        {
                            Notification notification = new Notification();
                            notification.Type        = type;
                            notification.User.userId = userId;

                            notification.Subject.userId      = long.Parse(dr["SubjectId"].ToString());
                            notification.Subject.pic         = dr["Pic"].ToString();
                            notification.Subject.userName    = dr["UserName"].ToString();
                            notification.Subject.IsFollowing = int.Parse(dr["following"].ToString());

                            if (notification.Type != NotificationType.FollowUser)
                            {
                                long lookId = long.Parse(dr["LookId"].ToString());
                                notification.Look = Look.GetLookById(lookId, userId, db);
                            }

                            if (notification.Type == NotificationType.CreateLookTag)
                            {
                                notification.Tag.id   = long.Parse(dr["TagId"].ToString());
                                notification.Tag.name = dr["contestName"].ToString();
                            }

                            DateTime CreateTime = DateTime.Parse(dr["CreateDate"].ToString());
                            notification.CreateTime = (CreateTime - new DateTime(1970, 1, 1)).TotalSeconds;
                            notifications.Add(notification);
                        }
                    }
                }
            }
            finally
            {
                myConnection.Close();
            }

            return(notifications);
        }
Exemple #16
0
        public void GetUser(string db)
        {
            user = new UserProfile();

            //Check if there is a lid in the querystring - then set the look.id
            if (Request.QueryString["lid"] != null)
            {
                this.Session["lid"] = long.Parse(Request.QueryString["lid"]);
            }
            else if (Request.QueryString["pid"] != null)
            {
                long pid = long.Parse(Request.QueryString["pid"]);

                //Find a look with that product id
                Look look = Look.GetLookByProductId(pid, db);
                this.Session["lid"] = look.id;
            }

            string sid = string.Empty;

            if (this.Session["lid"] != null)
            {
                sid = this.Session["lid"].ToString();
            }


            //Get the fb-connected user id
            if (user.userId == 0)
            {
                //Check if it's the fb Crawler then skip authentication
                if (Request.UserAgent == "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)")
                {
                    user = UserProfile.GetUserProfileById(3, db);
                }

                else if (this.Session["access_token"] == null)
                {
                    if (Request.QueryString["error_code"] != null)
                    {
                        Response.Write(Request.QueryString["error_string"]);
                        return;
                    }

                    if (Request.QueryString["code"] == null)
                    {
                        //means the user is not authorized yet from fb - redirect to login via fb

                        string redirectUrl = FacebookHelper.GetCode(sid);
                        Response.Redirect(redirectUrl);
                    }
                    else
                    {
                        try
                        {
                            //if code exists - check for state for lid
                            if (Request.QueryString["state"] != null)
                            {
                                long state = long.Parse(Request.QueryString["state"]);
                                if (state != 0)
                                {
                                    this.Session["lid"] = state;
                                }
                            }
                            string userReferral = "Unknown";
                            if (this.Request.Cookies["__userReferralid"] != null)
                            {
                                userReferral = this.Request.Cookies["__userReferralid"].Value;
                            }
                            string ipAddress = WebHelper.GetIpAddress(this.Request);
                            string userAgent = this.Request.UserAgent.ToString();
                            user = FacebookHelper.GetUser(Request.QueryString["code"], userReferral, db);
                            this.Session["access_token"] = user.accessToken;
                            this.Session["user"]         = user;

                            // create user cookie
                            HttpCookie userid = new HttpCookie("__userid");
                            userid.Value   = user.userId.ToString();
                            userid.Expires = DateTime.UtcNow.AddDays(14);
                            Response.Cookies.Add(userid);

                            // create authentication cookie
                            HttpCookie auth = new HttpCookie("__auth");
                            auth.Value   = WebHelper.CreateAuthString(user.userId);
                            auth.Expires = DateTime.UtcNow.AddDays(14);
                            Response.Cookies.Add(auth);
                        }
                        catch (Facebook.FacebookOAuthException ex)
                        {
                            if (ex.ErrorCode >= 100 && ex.ErrorCode < 200) // token expired or app unistalled
                            {
                                //code might have expired - try again
                                string redirectUrl = FacebookHelper.GetCode(sid);
                                Response.Redirect(redirectUrl);
                            }
                        }
                    }
                }
                else
                {
                    user = FacebookHelper.GetUserFromToken(this.Session["access_token"].ToString(), db);
                }
            }
        }
Exemple #17
0
        public static Look SaveLook(string db, string productMap, long userId, string tagMap, string title, long originalLookId = 0, long editLookId = 0, bool isFeaturedStylist = false)
        {
            Look look = new Look();

            string query = "EXEC [stp_SS_SaveLook] @product='" + productMap + "', @uid=" + userId + ",@tag='" + tagMap.Replace("'", "''") + "', @title=N'" + title.Replace("'", "''") + "'";
            if (originalLookId!= 0)
            {
                query += (", @originalLook=" + originalLookId);
            }

            if (editLookId!= 0)
            {
                query += (", @editLookId=" + editLookId);
            }
            if (isFeaturedStylist)
            {
                query += (", @isFeaturedStylist=" + 1);
            }
            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();

                    look = Look.GetLookFromSqlReader(dr);
                }
            }
            finally
            {
                myConnection.Close();
            }
            return look;
        }
Exemple #18
0
        public static string SendLookNotification(string appAccessToken, long creatorId, long userId, Look look)
        {
            var client = new FacebookClient();

            client.AppId     = appId;
            client.AppSecret = appSecret;

            if (string.IsNullOrEmpty(appAccessToken))
            {
                dynamic response = client.Get("oauth/access_token",
                                              new
                {
                    client_id     = appId,
                    client_secret = appSecret,
                    grant_type    = "client_credentials"
                });
                appAccessToken = response.access_token;
            }

            string path           = "/" + userId + "/notifications?access_token=" + appAccessToken;
            string templateString = "#LookOfTheWeek: Check out the top voted look by @[" + creatorId + "] in FashionKred!";

            var parameters = new Dictionary <string, object>
            {
                { "href", "/look.aspx?lid=" + look.id },
                { "template", templateString },
                { "ref", "looknotifications" }
            };

            client.Post(path, parameters);

            return(appAccessToken);
        }
Exemple #19
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);
        }
Exemple #20
0
        public static IList<Product> GetLovesByUserId(long userId, Look look, long retailerId, string db, out  bool P1Love, out bool P2Love, out bool P3Love)
        {
            IList<Product> loves = new List<Product>();

            string query = "EXEC [stp_SS_GetTopLoves] @UId=" + userId + ", @PId1=" + look.products[0].id + ", @PId2=" + look.products[1].id + ",@RId=" + retailerId;
            if (look.products.Count == 3)
            {
                query += (", @PId3=" + look.products[2].id);
            }
            SqlConnection myConnection = new SqlConnection(db);

            P1Love = false;
            P2Love = false;
            P3Love = false;

            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())
                    {
                        Product p = Product.GetProductFromSqlDataReader(dr);
                        loves.Add(p);
                    }

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

                    dr.NextResult();

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

                    while (dr.Read())
                    {
                        if (dr != null)
                            P3Love = true;
                    }
                }
            }
            finally
            {
                myConnection.Close();
            }

            return loves;
        }
Exemple #21
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);
        }