public void AddOrUpdate(FederalUpperLimit ful, string ndc) { Guid ndcId, drugId; if (NdcToDrug.TryGetValue(ndc, out drugId) && NdcToPackage.TryGetValue(ndc, out ndcId)) { ful.Id = Guid.NewGuid(); ful.PackageId = ndcId; ful.DrugId = drugId; Fuls.Add(ful); } }
public static async Task <int> Import(string baseDir, SiteConfig config) { string workDir = Path.Combine(baseDir, config.ShortName); Directory.CreateDirectory(workDir); //using (HttpClient httpClient = new HttpClient()) //{ // HttpResponseMessage msg = await httpClient.GetAsync(new Uri(config.DownloadFiles[0])); // using (StreamWriter sw = new StreamWriter(Path.Combine(workDir, "acaful.csv"))) // { // await (msg.Content.CopyToAsync(sw.BaseStream)); // sw.Flush(); // } //} using (StreamReader sr = new StreamReader(Path.Combine(workDir, "acaful.csv"))) { var csv = new CsvReader(sr); csv.Configuration.RegisterClassMap <AcaFulMap>(); csv.Configuration.Delimiter = ","; var records = csv.GetRecords <AcaFulObject>(); foreach (var rec in records) { FederalUpperLimit ful = new FederalUpperLimit { AvgMfgPrice = rec.WeightedAverageAmps, Ful = rec.AcaFedUpperLimit, PackageSize = rec.PackageSize, ReportingDate = new DateTime(rec.Year, rec.Month, 1), UnitType = rec.MdrUnitType, Ndc = rec.Ndc }; ImporterCache.Instance.AddOrUpdate(ful, rec.Ndc); } } return(0); }