/// <summary> /// Add AccountDictionaryRecords to database /// </summary> /// <param name="instances">AccountDictionaryRecord instance array</param> /// <param name="accountDictionary">AccountDictionary instance for instances</param> /// <param name="saveAfterInsert">Save database after insertion</param> /// <param name="waitUntilSaving">Wait until saving</param> public void AccountDictionaryRecordAdd(IEnumerable<AccountDictionaryRecord> instances, AccountDictionary accountDictionary, bool saveAfterInsert = true, bool waitUntilSaving = true) { try { if (instances == null) throw new ArgumentNullException("instances"); if (accountDictionary == null) throw new ArgumentNullException("accountDictionary"); instances = instances.Where(i => i != null).ToArray(); try { foreach (var i in instances) if (i.Dictionary != accountDictionary) i.Dictionary = accountDictionary; this.Context.AccountDictionaryRecords.AddRange(instances); if (saveAfterInsert) this.SaveChanges(waitUntilSaving); } catch (Exception ex) { var e = new Exception(ex.Message, ex); for (int i = 0; i < instances.Count();i++) e.Data.Add(string.Format("instance_{0}", i), instances.ElementAt(i).ToString()); throw e; } } catch (Exception ex) { Helpers.Log.Add(ex, string.Format("Repository.AccountDictionaryRecordAdd(instances=[{0}],saveAfterInsert={1},waitUntilSaving={2})", instances == null ? "NULL" : instances.Count().ToString(), saveAfterInsert, waitUntilSaving)); throw; } }
/// <summary> /// Create/Get new AccountDictionaryRecord instance without any link to database /// </summary> /// <returns>AccountDictionaryRecord instance</returns> public AccountDictionaryRecord AccountDictionaryRecordNew(AccountDictionary accountDictionary = null, Street street = null, Street streetChangeTo = null, object anonymousObject = null) { try { var res = new AccountDictionaryRecord() { Street = street, ChangeStreetTo = streetChangeTo, Dictionary = accountDictionary, }; if (anonymousObject != null) res.FillFromAnonymousType(anonymousObject); if (accountDictionary != null) accountDictionary.Records.Add(res); return res; } catch(Exception ex) { Helpers.Log.Add(ex, string.Format("Repository.AccountDictionaryRecordNew()")); throw; } }
/// <summary> /// Add AccountDictionaryRecord to database /// </summary> /// <param name="instance">AccountDictionaryRecord instance</param> /// <param name="accountDictionary">AccountDictionary instance for instance</param> /// <param name="saveAfterInsert">Save database after insertion</param> /// <param name="waitUntilSaving">Wait until saving</param> public void AccountDictionaryRecordAdd(AccountDictionaryRecord instance, AccountDictionary accountDictionary, bool saveAfterInsert = true, bool waitUntilSaving = true) { AccountDictionaryRecordAdd(new AccountDictionaryRecord[] { instance }, accountDictionary, saveAfterInsert, waitUntilSaving); }
/// <summary> /// Create/Get new AccountDictionaryExclude instance without any link to database /// </summary> /// <returns>AccountDictionaryExclude instance</returns> public AccountDictionaryExclude AccountDictionaryExcludeNew(AccountDictionary accountDictionary = null, string exclude = null) { try { var res = new AccountDictionaryExclude(); if (exclude != null) res.Exclude = exclude; if (accountDictionary != null) accountDictionary.Excludes.Add(res); return res; } catch(Exception ex) { Helpers.Log.Add(ex, string.Format("Repository.AccountDictionaryExcludeNew()")); throw; } }