示例#1
0
        public static EtsyItem MakeEtsyItem(string Listing_Id)
        {
            EtsyItem newItem = new EtsyItem();

            newItem.Listing_Id = Listing_Id;
            JObject data = GetEtsyAPI(Listing_Id, "listing");

            if (data["results"][0]["state"].ToString() != "sold_out")
            {
                newItem.Title                = data["results"][0]["title"].ToString();
                newItem.Title                = HttpUtility.HtmlDecode(newItem.Title);
                newItem.Description          = data["results"][0]["description"].ToString();
                newItem.Description          = HttpUtility.HtmlDecode(newItem.Description);
                newItem.Url                  = data["results"][0]["url"].ToString();
                newItem.Price                = data["results"][0]["price"].ToString();
                newItem.Item_Width           = data["results"][0]["item_width"].ToString();
                newItem.Item_Length          = data["results"][0]["item_length"].ToString();
                newItem.Item_Height          = data["results"][0]["item_height"].ToString();
                newItem.Item_Dimensions_unit = data["results"][0]["item_dimensions_unit"].ToString();
                if (newItem.Item_Width != null && newItem.Item_Dimensions_unit != null)
                {
                    newItem.Item_Width  = CalculatePixels(newItem.Item_Width, newItem.Item_Dimensions_unit);
                    newItem.Item_Length = CalculatePixels(newItem.Item_Length, newItem.Item_Dimensions_unit);
                }
                newItem.Currency_Code = data["results"][0]["currency_code"].ToString();
                JObject imageData = GetEtsyAPI(newItem.Listing_Id, "image");
                newItem.ImageThumbUrl = imageData["results"][0]["url_170x135"].ToString();
                newItem.ImageFullUrl  = imageData["results"][0]["url_fullxfull"].ToString();
            }
            return(newItem);
        }
示例#2
0
        public ActionResult FurnitureList(List <string> Left, List <string> Top, string SearchQ, string MaxP, string pageNo = "")
        {
            SpaceController.SavePositions(Left, Top);
            List <EtsyItem> items = new List <EtsyItem>();

            if (SearchQ != null && SearchQ != string.Empty)
            {
                if (pageNo != string.Empty)
                {
                    if (int.Parse(pageNo) > 1)
                    {
                        SearchQ += "&page=" + pageNo;
                    }
                }
                if (MaxP != string.Empty)
                {
                    SearchQ         += "&min_price= 0";
                    SearchQ         += "&max_price= " + MaxP;
                    TempData["MaxP"] = MaxP;
                }
                JObject data = EtsyDAL.GetEtsyAPI(" &limit=5&category=furniture&keywords=" + SearchQ, "active");
                if (SearchQ.Contains('&'))
                {
                    TempData["SearchQ"] = SearchQ.Split('&')[0];
                }
                else
                {
                    TempData["SearchQ"] = SearchQ;
                }
                int prevPage = (int)data["pagination"]["effective_page"];
                if (prevPage > 1)
                {
                    TempData["prevPage"] = prevPage - 1;
                }
                else
                {
                    TempData["prevPage"] = null;
                }
                string nextPage = data["pagination"]["next_page"].ToString();
                if (nextPage != string.Empty)
                {
                    TempData["nextPage"] = (int)data["pagination"]["next_page"];
                }
                for (int i = 0; i < data["results"].Count(); i++)
                {
                    EtsyItem newItem = new EtsyItem();
                    newItem.Listing_Id = data["results"][i]["listing_id"].ToString();
                    newItem            = EtsyDAL.MakeEtsyItem(newItem.Listing_Id);
                    items.Add(newItem);
                    System.Threading.Thread.Sleep(500);
                }
            }
            TempData["items"] = items;
            return(RedirectToAction("Index", "Space"));
        }