Skip to content

Commit cbe6810

Browse files
authored
Merge pull request #1 from Maxjaco/fix-connectionStringQueryString
Updated so that we use the connectionstring in SqlLookupRepository, a…
2 parents 626ef57 + 9d11dee commit cbe6810

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

Src/LookupUtility/LookupUtilityService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public LookupUtilityService(ILookupRepository lookupRepository)
2323
public string GetValue(string list, string key, string defaultValue)
2424
{
2525
var dict = GetList(list);
26-
27-
if (!dict.TryGetValue(key, out string val))
26+
string val;
27+
if (!dict.TryGetValue(key, out val))
2828
{
2929
return defaultValue;
3030
}
@@ -35,15 +35,15 @@ public string GetValue(string list, string key, string defaultValue)
3535
public string GetValue(string list, string key, bool throwIfNotExists = false, bool allowDefaults = false)
3636
{
3737
var dict = GetList(list);
38-
39-
if (!dict.TryGetValue(key, out string val))
38+
string val;
39+
if (!dict.TryGetValue(key, out val))
4040
{
4141
if (throwIfNotExists)
4242
{
4343
throw new ArgumentException(string.Format("The specified property {0} does not exist in list {1}", key, list));
4444
}
45-
46-
if (allowDefaults && dict.TryGetValue(DEFAULT_KEY, out string defaultValue))
45+
string defaultValue;
46+
if (allowDefaults && dict.TryGetValue(DEFAULT_KEY, out defaultValue))
4747
{
4848
return defaultValue;
4949
}

Src/LookupUtility/Repository/SharepointLookupRepository.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ public Dictionary<string, string> LoadList(string list)
3232

3333
var dictionary = new Dictionary<string, string>();
3434

35+
object keyName;
36+
object valueName;
3537
foreach (var item in collListItem)
3638
{
37-
item.FieldValues.TryGetValue("Key", out object keyName);
38-
item.FieldValues.TryGetValue("Value", out object valueName);
39+
item.FieldValues.TryGetValue("Key", out keyName);
40+
item.FieldValues.TryGetValue("Value", out valueName);
3941

4042
dictionary.Add(keyName.ToString(), valueName as string);
4143
}

Src/LookupUtility/Repository/SqlLookupRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public class SqlLookupRepository : ILookupRepository
1212
{
1313
public Dictionary<string, string> LoadList(string list)
1414
{
15-
string query = string.Format("SELECT Key, Value FROM {0}", list);
15+
string query = string.Format("SELECT [Key], Value FROM {0}", list);
1616

1717
var connectionString = ConfigurationManager.ConnectionStrings["SqlLookupRepository"].ConnectionString;
1818
var dictionary = new Dictionary<string, string>();
1919

20-
using (var con = new SqlConnection())
20+
using (var con = new SqlConnection(connectionString))
2121
{
2222
con.Open();
2323
using (var cmd = new SqlCommand(query, con))

0 commit comments

Comments
 (0)