public void InsertNewOption(TypeOfOption type, string key, string value) { if (string.IsNullOrWhiteSpace(key)) { throw new ApplicationDbException("Data are not filled correctedly"); } using (new WriterLock(_lock)) { IOption option = GetOption(type, key); if (option == null) { Option newoption = new Option { Type = type, Key = key, Value = value }; AddToDbAndUpdateReferential(newoption, InsertInReferential); } else if (option.Value != value) { RemoveFromDbAndUpdateReferential(option as Option, RemoveFromReferential); Option newoption = new Option { Type = type, Key = key, Value = value }; AddToDbAndUpdateReferential(newoption, InsertInReferential); } } }
private bool GetOptionValue(TypeOfOption typeOfOption, string optionName) { bool ret = true; IOption option = _magicDatabase.GetOption(typeOfOption, optionName); if (option != null) { ret = bool.Parse(option.Value); } return ret; }
public IList <IOption> GetOptions(TypeOfOption type) { CheckReferentialLoaded(); using (new ReaderLock(_lock)) { if (!_allOptions.TryGetValue(type, out IList <IOption> options)) { return(null); } return(new List <IOption>(options).AsReadOnly()); } }
public void DeleteOption(TypeOfOption type, string key) { if (string.IsNullOrWhiteSpace(key)) { throw new ApplicationDbException("Data are not filled correctedly"); } using (new WriterLock(_lock)) { IOption option = GetOption(type, key); if (option == null) { return; } RemoveFromDbAndUpdateReferential(option as Option, RemoveFromReferential); } }
public IOption GetOption(TypeOfOption type, string key) { IList <IOption> options = GetOptions(type); return(options == null ? null : options.FirstOrDefault(o => o.Key == key)); }