public void CreateNationalAccount(Customer hq) { using (var scope = new TransactionScope()) { try { var nationalAccount = new NationalAccount(); nationalAccount.CompanyID = "CPC"; nationalAccount.CreditLimit = 0; nationalAccount.CreditLimitUsed = 0; nationalAccount.Description = hq.Name; nationalAccount.Hold = 0; nationalAccount.NationalAcctID = hq.Id + "N"; hq.PrimaryContact.Shared = true; nationalAccount.Key = _nationalAccountRepository.GetSurrogateKey(); _nationalAccountRepository.Add(nationalAccount); var parentLevel = new NationalAccountLevel(); parentLevel.Key = _nationalAccountLevelRepository.GetSurrogateKey(); parentLevel.Description = "Parent"; parentLevel.NationalAcctKey = nationalAccount.Key; parentLevel.NationalAcctLevel = 1; _nationalAccountLevelRepository.Add(parentLevel); hq.NationalAcctLevelKey = parentLevel.Key; hq.AcctType = "HQ"; _customerRepository.Update(hq); scope.Complete(); } catch (Exception) { scope.Dispose(); throw; } } }
public void AddBranchToNationalAccount(Customer branch, Customer headquarters) { using (var scope = new TransactionScope()) { try { SetBranchDefaultProperties(branch, headquarters); SetUpDocumentTransmittal(branch, headquarters); SetUpPrimaryContactInBranch(branch, headquarters); SetUpSharedContactsInBranch(branch, headquarters); var childLevel = new NationalAccountLevel(); childLevel.Key = _nationalAccountLevelRepository.GetSurrogateKey(); childLevel.Description = "Subsidiary"; childLevel.NationalAcctKey = headquarters.NationalAccountLevel.NationalAccount.Key; childLevel.NationalAcctLevel = 2; branch.NationalAccountLevel = childLevel; branch.NationalAcctLevelKey = childLevel.Key; if (headquarters.Branches == null) { headquarters.Branches = new List <Customer>(); } headquarters.Branches.Add(branch); _customerRepository.UpdateCustomerWithDependecies(headquarters); scope.Complete(); } catch (Exception) { scope.Dispose(); throw; } } }