public static void UpdateAffiliateLinks(int retailerId) { //Get product id, url string query = "SELECT id,Url from [nirveek_de].[SS_Product] where AffiliateUrl is null and retailerid=" + retailerId; SqlConnection myConnection = new SqlConnection(connectionString); List<Product> products = new List<Product>(); 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 = new Product(); p.id = long.Parse(dr["id"].ToString()); p.url = dr["Url"].ToString(); products.Add(p); //products.Add(p); } } } finally { myConnection.Close(); } try { myConnection.Open(); int i = 0; Console.WriteLine(products.Count); foreach (Product p in products) { i++; //Thread.Sleep(500); p.AffiliateUrl = AffiliateLink.GetAffiliateLink(p.url); query = "update [nirveek_de].[SS_Product] set AffiliateUrl = N'" + p.AffiliateUrl + "' where Id =" + p.id; Console.WriteLine(i); using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection)) { SqlCommand cmd = adp.SelectCommand; cmd.CommandTimeout = 300000; cmd.ExecuteNonQuery(); } } } finally { myConnection.Close(); } //calculate affiliatelink //save affilaitelink }
public static IList<Product> GetLovesByUserId(long userId, Product product, long retailerId, string db) { IList<Product> loves = new List<Product>(); string query = "EXEC [stp_SS_GetTopLoves] @UId=" + userId + ", @PId1=" + product.id + ", @PId2=" + product.id + ",@RId=" + retailerId; 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()) { Product p = Product.GetProductFromSqlDataReader(dr); loves.Add(p); } } } finally { myConnection.Close(); } return loves; }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["pid"] == null) { return; } string db = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString; this.productId = long.Parse(Request.QueryString["pid"]); product = ShopSenseDemo.Product.GetProductById(this.productId, db); if (product == null) { this.RedirectToErrorPage(ErrorPageType.GenericError, true); return; } SetOGTags(); //set the user //this.GetUser(db); //TEMP: Find a look with that product id and redirect to look page Look look = Look.GetLookByProductId(this.productId, db); Response.Redirect("look.aspx?lid=" + look.id); // BrandName.Text = product.brandName; ProductName.Text = product.name; ProductImg.ImageUrl = product.GetImageUrl(); ProductDesc.Text = product.description; Retailer.Text = "Buy at " + product.retailer; //Colors.Text = "<strong>Available Color: </strong>" + product.colorString; Sizes.Text = "<strong>Available Size: </strong>" + product.sizeString; Price.Text = string.Format("{0:c}", product.price); if (product.salePrice != 0) { Price.CssClass += "strike-through"; SalePrice.Text = string.Format("{0:c}", product.salePrice); SalePrice.Visible = true; } BuyLink.NavigateUrl = product.url; LoveCount.Text = product.loves.ToString(); //set the user if (this.Session["user"] != null) { this.user = this.Session["user"] as UserProfile; UserProfile user = this.Session["user"] as UserProfile; this.UserId.Text = user.userId.ToString(); } else { this.GetUser(db); } //meta data PId.Text = this.productId.ToString(); }
public static bool ReportItem(long userId, long productId, string db) { bool isSuccess = false; string query = "EXEC [stp_SS_SaveReportedProduct] @pId=" + productId + ", @uId=" + userId; SqlConnection myConnection = new SqlConnection(db); Product p = new Product(); try { myConnection.Open(); using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection)) { SqlCommand cmd = adp.SelectCommand; cmd.CommandTimeout = 300000; System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader(); isSuccess = true; } } finally { myConnection.Close(); } return isSuccess; }
public static bool HeartItem(long userId, long productId,bool isHeart,string colorId, string catId, string db) { int heart = isHeart == true ? 1 : 0; bool isSuccess = false; string query = "EXEC [stp_SS_SaveLove] @uid=" + userId + ", @pid=" + productId + ",@love=" + heart+ ",@colorId='" + colorId + "',@catId='" + catId +"'" ; SqlConnection myConnection = new SqlConnection(db); Product p = new Product(); try { myConnection.Open(); using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection)) { SqlCommand cmd = adp.SelectCommand; cmd.CommandTimeout = 300000; System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader(); isSuccess = true; } } finally { myConnection.Close(); } return isSuccess; }
public static Product GetProductFromSqlDataReader(SqlDataReader dr) { Product p = new Product(); p.id = long.Parse(dr["id"].ToString()); p.name = dr["Name"].ToString().Replace("\"","'" ); p.images = new List<Image>(); p.categories = new List<string>(); p.categoryNames = new List<string>(); p.colors = new List<Color>(); Image img = new Image(); img.url = p.GetBestImageUrl(dr["ImageUrl"].ToString()); p.images.Add(img); p.url = dr["Url"].ToString(); p.price = (Decimal)dr["Price"]; p.salePrice = (Decimal)dr["SalePrice"]; p.loves = int.Parse(dr["Loves"].ToString()); p.brandId = int.Parse(dr["BrandId"].ToString()); p.retailerId = int.Parse(dr["RetailerId"].ToString()); p.sizeString = dr["Size"].ToString().TrimEnd(','); p.extractDate = dr["ExtractDate"].ToString(); if (!string.IsNullOrEmpty(p.extractDate)) { DateTime extractDate = DateTime.Parse(p.extractDate); if (extractDate > DateTime.UtcNow.Subtract(new TimeSpan(15, 0, 0, 0))) p.isNewItem = true; } if (dr["BrandName"] != null) { p.brandName = dr["BrandName"].ToString().Replace("\"", "'"); } if (dr["RetailerName"] != null) { p.retailer = dr["RetailerName"].ToString().Replace("\"", "'"); } if (!string.IsNullOrEmpty(dr["AffiliateUrl"].ToString())) { p.AffiliateUrl = dr["AffiliateUrl"].ToString(); //p.url = p.AffiliateUrl; } if ( ColumnExists(dr, "ColorImageUrl") && !string.IsNullOrEmpty(dr["ColorImageUrl"].ToString())) { Image colorImg = new Image(); colorImg.url = dr["ColorImageUrl"].ToString(); p.images[0] = colorImg; } if (ColumnExists(dr, "CategoryId") && !string.IsNullOrEmpty(dr["CategoryId"].ToString())) { string cat = dr["CategoryId"].ToString(); string catName = dr["CategoryName"].ToString().Replace("\"", "'"); p.categories.Add(cat); p.categoryNames.Add(catName); } else if (ColumnExists(dr, "DefaultCatId") && !string.IsNullOrEmpty(dr["DefaultCatId"].ToString())) { string cat = dr["DefaultCatId"].ToString(); string catName = dr["DefaultCatName"].ToString().Replace("\"", "'"); p.categories.Add(cat); p.categoryNames.Add(catName); } if (ColumnExists(dr, "IsCover") && !string.IsNullOrEmpty(dr["IsCover"].ToString())) { string isCover = dr["IsCover"].ToString(); p.isCover = isCover == "True" ? true : false; } //IF color id is present - then take that otherwise choose default color if (ColumnExists(dr, "ColorId") && !string.IsNullOrEmpty(dr["ColorId"].ToString())) { Color color = new Color(); color.canonical = new List<string>(); color.canonical.Add(dr["ColorId"].ToString()); if (ColumnExists(dr, "ColorName") && !string.IsNullOrEmpty(dr["ColorName"].ToString())) { color.name = dr["ColorName"].ToString().Replace("\"", "'"); } p.colors.Add(color); } else if (ColumnExists(dr, "DefaultColorId") && !string.IsNullOrEmpty(dr["DefaultColorId"].ToString())) { Color color = new Color(); color.canonical = new List<string>(); color.canonical.Add(dr["DefaultColorId"].ToString()); color.name = dr["DefaultColorId"].ToString(); p.colors.Add(color); } if (ColumnExists(dr, "SwatchUrl") && !string.IsNullOrEmpty(dr["SwatchUrl"].ToString())) { p.swatchUrl = dr["SwatchUrl"].ToString(); } if (ColumnExists(dr, "InCloset") && !string.IsNullOrEmpty(dr["InCloset"].ToString())) { if(dr["InCloset"].ToString()!="0") p.inCloset = true; } if (ColumnExists(dr, "InMultipleColors") && !string.IsNullOrEmpty(dr["InMultipleColors"].ToString())) { if (dr["InMultipleColors"].ToString() != "False") p.inMultipleColors = true; } //Trim product name out of brand name case insensitive if (!string.IsNullOrEmpty(p.brandName) && p.name.ToLower().IndexOf(p.brandName.ToLower()) == 0) p.name = p.name.Substring(p.brandName.Length).TrimStart(); return p; }