private static async Task SeedGenerateSolar(Variable generationVariable) { var solarVariable = new AgreegationSubVariable { Name = "Solar", VariableId = generationVariable.Id }; await _context.AgreegationSubVariables.AddAsync(solarVariable); await _context.SaveChangesAsync(); // Solar PV var SolarPVSubVariable = new AgreegationSubVariableSubVariable { Name = "Solar PV", AgreegationSubVariableId = solarVariable.Id }; // Solar thermal var SolarThermalVariable = new AgreegationSubVariableSubVariable { Name = "Solar thermal", AgreegationSubVariableId = solarVariable.Id }; await _context.AgreegationSubVariableSubVariables.AddAsync(SolarPVSubVariable); await _context.AgreegationSubVariableSubVariables.AddAsync(SolarThermalVariable); await _context.SaveChangesAsync(); }
public async Task ImportData() { var scenarios = await _context.Scenarios.ToListAsync(); foreach (var scenario in scenarios) { CurrentSecenarioId = scenario.Id; var keyParameters = _context.KeyParameters.ToList(); foreach (var keyParameter in keyParameters) { CurrentKeyParameterId = keyParameter.Id; var keyParameterLevels = _context.KeyParameterLevels.ToList(); foreach (var keyParameterLevel in keyParameterLevels) { CurrentKeyParameterLevelId = keyParameterLevel.Id; var xlsFile = _context.XlsUploads.FirstOrDefault(x => x.ScenarioId == scenario.Id && x.KeyParameterId == keyParameter.Id && x.KeyParameterLevelId == keyParameterLevel.Id); if (xlsFile == null) { continue; } // Open file var filePath = $"{WorkBookBasePath}/{xlsFile.FileName}"; var fileInfo = new FileInfo(filePath); if (!Directory.Exists(filePath)) { continue; } // Open Xls file using (var package = new ExcelPackage(fileInfo)) { this.CurrentWorkBook = package.Workbook; // update all formulas in xls file UpdateXlsFormulas(); package.Save(); // get Variable Data await GetVariableDataAggreegation(); // get Sub Variable data await GetSubVariableDataAggregategation(); // get Sub Variable GDP await GetSubVariableDataAggregategationGdp(); // get Sub Variable World data await GetSubVariableDataAggregategationWorld(); } try { Directory.Delete(fileInfo.FullName); _context.XlsUploads.Remove(xlsFile); await _context.SaveChangesAsync(); } catch { } } } } //await CalculateSums(); //await CalculateWorldSums(); }