private ProductSolytronViewModel GetFullInfo(string fullInfoUrl) { XDocument doc = XDocument.Load(fullInfoUrl); var elementRoot = doc.Root; Guid id = Guid.Parse(elementRoot.Attribute("productId").Value); //var name = elementRoot.Element("name").Value; var descriptionProperties = elementRoot.Elements("propertyGroup") .LastOrDefault() .Elements("property"); StringBuilder description = new StringBuilder(); foreach (var property in descriptionProperties) { if (property.Attribute("propertyId").Value != "55" && property.Attribute("propertyId").Value != "56" && property.Attribute("propertyId").Value != "57" ) { string propertyName = property.Attribute("name").Value; string propertyValue = property.Element("value").Value; description.Append("<p><b>" + propertyName + ": </b>" + propertyValue + "</p>"); } } var imagesElements = elementRoot.Elements("image"); ICollection <Picture> images = new List <Picture>(); foreach (var img in imagesElements) { //string fileSaveAddress = string.Empty; //using (WebClient client = new WebClient()) //{ // //client.DownloadFile(new Uri(img.Value), @"c:\temp\image35.png"); // //OR // string url = img.Value; // int start = url.IndexOf("resources/") + 10; // int end = url.LastIndexOf("?"); // fileSaveAddress = "./wwwroot/productImages/" + url.Substring(start, end - start); // client.DownloadFileAsync(new Uri(img.Value), fileSaveAddress); //} //Picture pic = new Picture //{ // ImageUrl = fileSaveAddress.Substring(9) //}; Picture pic = new Picture { ImageUrl = img.Value }; images.Add(pic); } ProductSolytronViewModel product = new ProductSolytronViewModel { FullDescription = description.ToString(), Pictures = images, //Supplier = Supplier.Solytron }; return(product); }
private ICollection <ProductSolytronViewModel> GetProductsFromSubCategories(CategorySolytronViewModel subCategory, Category category) { XDocument doc = XDocument.Load(subCategory.CategoryLink); ICollection <ProductSolytronViewModel> products = new List <ProductSolytronViewModel>(); IEnumerable <XElement> productElement = doc.Descendants("productSet") .Elements("product"); foreach (var item in productElement) { //Check if product is availible string availability = string.Empty; if (item.Descendants("stockInfoValue").Any()) { availability = item.Element("stockInfoValue").Value; } if (availability == "OnOrder" || availability == string.Empty) { continue; } //Check for End User Price if (!item.Descendants("priceEndUser").Any()) { continue; } //Get Name string name = item.Element("name").Value; //var isExist = this.productsService.GetByName(name.Substring(20)) // .Where(x => x.Supplier == Supplier.Stantek && x.IsPublished == true) // .FirstOrDefault(); //if (isExist != null) //{ // continue; //} string codeId = item.Attribute("codeId").Value; string groupId = item.Attribute("groupId").Value; string fullInfoUrl = "https://solytron.bg/products/xml/product.xml?codeId=" + codeId + "&groupId=" + groupId + "&j_u=cavescomputers&j_p=Magurata2000"; ProductSolytronViewModel newProduct = GetFullInfo(fullInfoUrl); string vendor = item.Element("vendor").Value; string nameAndVendor = string.Empty; //Check name whether start with vendor if (vendor.Length > name.Length || vendor.ToLower() != name.Substring(0, vendor.Length).ToLower()) { nameAndVendor = vendor + " " + name; } else { nameAndVendor = name; } if (nameAndVendor.Length > ValidationConstants.StandartMaxLength) { nameAndVendor = nameAndVendor.Substring(0, ValidationConstants.StandartMaxLength); } newProduct.Name = nameAndVendor; //Get Price string currency = item.Element("priceEndUser").Attribute("currency").Value; decimal priceValue = decimal.Parse(item.Element("priceEndUser").Value); if (currency == "BGN") { newProduct.Price = priceValue; } else if (currency == "EUR") { decimal price = priceValue * Constants.EURValue; newProduct.Price = Math.Round(price, 2); } else { decimal price = priceValue * Constants.USDValue; newProduct.Price = Math.Round(price, 2); } //Get warranty //if (item.Descendants("warrantyUnit").Any()) //{ // string warrantyType = item.Element("warrantyUnit").Value; // string warrantyValue = item.Element("warrantyQty").Value; // if (warrantyType == "2") // { // string warranty = "<p><b>Гаранция: </b>" + warrantyValue + " месеца</p>"; // newProduct.FullDescription = newProduct.FullDescription + warranty; // } //} newProduct.Category = category; //Add Id??? products.Add(newProduct); } return(products); }