private async Task UpdateDropDownCategories() { con = new Npgsql.NpgsqlConnection(ConfigurationManager.ConnectionStrings["TalentDataContextPostgres"].ConnectionString); try { con.Open(); sqlDataContext = new Agilisium.TalentManager.Model.TalentManagerDataContext(); List <DropDownCategory> oldCategories = sqlDataContext.DropDownCategories.ToList(); // update primary column id List <DropDownCategory> newCategories = postgressDataContext.DropDownCategories.ToList(); foreach (DropDownCategory newRec in newCategories) { int oldPracticeID = oldCategories.FirstOrDefault(p => p.CategoryName == newRec.CategoryName).CategoryID; string qry = $"UPDATE \"TalentManager\".\"DropDownCategory\" SET \"CategoryID\"={oldPracticeID} WHERE \"CategoryID\"={newRec.CategoryID}"; Npgsql.NpgsqlCommand cmd = new Npgsql.NpgsqlCommand(qry, con); int val = await cmd.ExecuteNonQueryAsync(); } } catch (Exception) { } finally { con.Close(); con.Dispose(); } }
private async Task UpdateSystemSettings() { con = new Npgsql.NpgsqlConnection(ConfigurationManager.ConnectionStrings["TalentDataContextPostgres"].ConnectionString); try { con.Open(); sqlDataContext = new Agilisium.TalentManager.Model.TalentManagerDataContext(); List <SystemSetting> oldSettings = sqlDataContext.SystemSettings.ToList(); // update primary column id postgressDataContext = new Agilisium.TalentManager.PostgresModel.TalentManagerDataContext(); List <SystemSetting> newSettings = postgressDataContext.SystemSettings.ToList(); foreach (SystemSetting newRec in newSettings) { int oldPracticeID = oldSettings.FirstOrDefault(p => p.SettingName == newRec.SettingName).SettingEntryID; string qry = $"UPDATE \"TalentManager\".\"SystemSettings\" SET \"SettingEntryID\"={oldPracticeID} WHERE \"SettingEntryID\"={newRec.SettingEntryID}"; Npgsql.NpgsqlCommand cmd = new Npgsql.NpgsqlCommand(qry, con); int val = await cmd.ExecuteNonQueryAsync(); } } catch (Exception) { } finally { con.Close(); con.Dispose(); } }