public bool ExtractStockFilesFromSites() { using (var context = new StockEntities()) { bool isExtracted = false; var sitesWithSymbol = (from site in context.Sites from symbol in context.StockSymbols select new { site, symbol }).ToList(); for (int count = 0; count < sitesWithSymbol.Count; count++) { string fileContent = ExtractDataFromSites(sitesWithSymbol[count].site.Url.Replace("{0}", sitesWithSymbol[count].symbol.Symbol)); if(!String.IsNullOrEmpty(fileContent)) { var stockFile = new StockFile(); stockFile.SiteId = sitesWithSymbol[count].site.ID; stockFile.StockId = sitesWithSymbol[count].symbol.ID; stockFile.FileName = sitesWithSymbol[count].site.Name + "_" + sitesWithSymbol[count].symbol.Symbol; stockFile.File = fileContent; stockFile.DownloadedDate = DateTime.Now; context.StockFiles.AddObject(stockFile); } } context.SaveChanges(); isExtracted = true; return isExtracted; } }
public bool RemoveAllStockFiles() { using (var context = new StockEntities()) { bool isDeleted = false; var records = from s in context.StockFiles select s; foreach (var record in records) { context.StockFiles.DeleteObject(record); } context.SaveChanges(); isDeleted = true; return isDeleted; } }