public static product_image ReadAndSaveProductImageFromUrl(this string url, long subdomainid, long ownerid, long?productid) { var req = WebRequest.Create(url); WebResponse resp = null; try { resp = req.GetResponse(); } catch (Exception ex) { Syslog.Write(ex); } if (resp == null) { return(null); } try { var image = new product_image(); using (var repository = new TradelrRepository()) { var sd = repository.GetSubDomain(subdomainid); var extension = url.ToImageFormat().ToStringExtension(); var filename = BuildFilename(ownerid, extension); var handler = new FileHandler(filename, UploadFileType.IMAGE, sd.uniqueid); image.productid = productid; image.subdomainid = subdomainid; image.url = handler.Save(resp.GetResponseStream()); if (productid.HasValue) { repository.AddProductImage(image); var product = repository.GetProduct(productid.Value, subdomainid); if (product != null && !product.thumb.HasValue) { product.thumb = image.id; } repository.Save("ReadAndSaveProductImageFromUrl"); } } return(image); } catch (Exception ex) { Syslog.Write(ex); return(null); } }