/// <summary> /// Enables the DataRepository to programatically create and /// pass in a <c>NetTiersProvider</c> during runtime. /// </summary> /// <param name="provider">An instatiated NetTiersProvider.</param> /// <param name="setAsDefault">ability to set any valid provider as the default provider for the DataRepository.</param> public static void LoadProvider(NetTiersProvider provider, bool setAsDefault) { if (provider == null) throw new ArgumentNullException("provider"); if (_providers == null) { lock(SyncRoot) { if (_providers == null) _providers = new NetTiersProviderCollection(); } } if (_providers[provider.Name] == null) { lock (_providers.SyncRoot) { _providers.Add(provider); } } if (_provider == null || setAsDefault) { lock (SyncRoot) { if(_provider == null || setAsDefault) _provider = provider; } } }
/// <summary> /// Adds the specified provider. /// </summary> /// <param name="provider">The provider.</param> public void Add(NetTiersProvider provider) { if (provider == null) { throw new ArgumentNullException("provider"); } if (!(provider is NetTiersProvider)) { throw new ArgumentException("Invalid provider type", "provider"); } base.Add(provider); }
/// <summary> /// Enables the DataRepository to programatically create and /// pass in a <c>NetTiersProvider</c> during runtime. /// </summary> /// <param name="provider">An instatiated NetTiersProvider.</param> public static void LoadProvider(NetTiersProvider provider) { LoadProvider(provider, false); }
///<summary> /// Configuration based provider loading, will load the providers on first call. ///</summary> private static void LoadProviders() { // Avoid claiming lock if providers are already loaded if (_provider == null) { lock (SyncRoot) { // Do this again to make sure _provider is still null if (_provider == null) { // Load registered providers and point _provider to the default provider _providers = new NetTiersProviderCollection(); ProvidersHelper.InstantiateProviders(NetTiersSection.Providers, _providers, typeof(NetTiersProvider)); _provider = _providers[NetTiersSection.DefaultProvider]; if (_provider == null) { throw new ProviderException("Unable to load default NetTiersProvider"); } } } } }
/// <summary> /// Instantiates the configured providers based on the supplied connection string. /// </summary> private void LoadProviders() { DataRepository.LoadProviders(); // Avoid claiming lock if providers are already loaded if ( _providers == null ) { lock ( SyncRoot ) { // Do this again to make sure _provider is still null if ( _providers == null ) { // apply connection information to each provider for ( int i = 0; i < NetTiersSection.Providers.Count; i++ ) { NetTiersSection.Providers[i].Parameters["connectionStringName"] = _connectionStringName; // remove previous connection string, if any NetTiersSection.Providers[i].Parameters.Remove("connectionString"); if ( !String.IsNullOrEmpty(_connectionString) ) { NetTiersSection.Providers[i].Parameters["connectionString"] = _connectionString; } } // Load registered providers and point _provider to the default provider _providers = new NetTiersProviderCollection(); ProvidersHelper.InstantiateProviders(NetTiersSection.Providers, _providers, typeof(NetTiersProvider)); _provider = _providers[NetTiersSection.DefaultProvider]; } } } }
//private void SaveAddress(Address address) //{ // AddressService addressService = new AddressService(); // addressService.Insert() // TransactionManager transactionManager = null; // try // { // transactionManager = ConnectionScope.CreateTransaction(); // NetTiersProvider dataProvider = ConnectionScope.Current.DataProvider; // EmployeeService employeeService = new EmployeeService(); // dataProvider.EmployeeProvider.Insert(transactionManager, employee); // foreach (var address in addresses) // { // address.EmployeeId = employee.EmployeeId; // } // dataProvider.AddressProvider.Insert(transactionManager, addresses); // transactionManager.Commit(); // Clear(); // } // catch (Exception exc) // { // if (transactionManager != null && transactionManager.IsOpen) // transactionManager.Rollback(); // lblMsg.Text = "An error occurred while processing your request!"; // } //} private bool UpdateEmployee(EmployeeModel employeeModel, List <AddressModel> addressModels) { TransactionManager transactionManager = null; try { transactionManager = ConnectionScope.CreateTransaction(); NetTiersProvider dataProvider = ConnectionScope.Current.DataProvider; if (string.IsNullOrEmpty(employeeModel.FullName) || !Employee.FullName.Equals(employeeModel.FullName)) { Employee.FullName = employeeModel.FullName; } if (string.IsNullOrEmpty(employeeModel.EmployeeCode) || !Employee.EmployeeCode.Equals(employeeModel.EmployeeCode)) { Employee.EmployeeCode = employeeModel.EmployeeCode; } if (string.IsNullOrEmpty(employeeModel.FirstName) || !Employee.FirstName.Equals(employeeModel.FirstName)) { Employee.FirstName = employeeModel.FirstName; } if (string.IsNullOrEmpty(employeeModel.MiddlesName) || !Employee.MiddlesName.Equals(employeeModel.MiddlesName)) { Employee.MiddlesName = employeeModel.MiddlesName; } if (string.IsNullOrEmpty(employeeModel.LastName) || !Employee.LastName.Equals(employeeModel.LastName)) { Employee.LastName = employeeModel.LastName; } if (!employeeModel.DOB.HasValue || (Employee.DOB.HasValue && employeeModel.DOB.HasValue && DateTime.Compare(Employee.DOB.Value, employeeModel.DOB.Value) != 0)) { Employee.DOB = employeeModel.DOB; } if (string.IsNullOrEmpty(employeeModel.Email) || !Employee.Email.Equals(employeeModel.Email)) { Employee.Email = employeeModel.Email; } if (string.IsNullOrEmpty(employeeModel.Bio) || !Employee.Bio.Equals(employeeModel.Bio)) { Employee.Bio = employeeModel.Bio; } dataProvider.EmployeeProvider.Update(transactionManager, Employee); //if (!dataProvider.EmployeeProvider.Update(transactionManager, Employee)) //{ // throw new Exception("Can't update Employee"); //} TList <Address> addressForUpdate = Employee.AddressCollection; foreach (var model in addressModels) { if (model.AddressId == 0) { var address = new Address { EmployeeId = model.EmployeeId, Line1 = model.Line1, Line2 = model.Line2, TownCity = model.TownCity, StateOrProvince = model.StateOrProvince, PostCod = model.PostCod, CountryCode = model.CountryCode }; dataProvider.AddressProvider.Insert(transactionManager, address); } else { var address = addressForUpdate.Single(a => a.AddressId == model.AddressId); if (string.IsNullOrEmpty(address.Line1) || !address.Line1.Equals(model.Line1)) { address.Line1 = model.Line1; } if (string.IsNullOrEmpty(address.Line2) || !address.Line2.Equals(model.Line2)) { address.Line2 = model.Line2; } if (string.IsNullOrEmpty(address.TownCity) || !address.TownCity.Equals(model.TownCity)) { address.TownCity = model.TownCity; } if (string.IsNullOrEmpty(address.StateOrProvince) || !address.StateOrProvince.Equals(model.StateOrProvince)) { address.StateOrProvince = model.StateOrProvince; } if (string.IsNullOrEmpty(address.PostCod) || !address.PostCod.Equals(model.PostCod)) { address.PostCod = model.PostCod; } if (string.IsNullOrEmpty(address.CountryCode) || !address.CountryCode.Equals(model.CountryCode)) { address.CountryCode = model.CountryCode; } } } dataProvider.AddressProvider.Update(transactionManager, addressForUpdate); //if (dataProvider.AddressProvider.Update(transactionManager, addressForUpdate) == 0) //{ // throw new Exception("Can't update Address"); //} transactionManager.Commit(); } catch (Exception exc) { if (transactionManager != null && transactionManager.IsOpen) { transactionManager.Rollback(); } return(false); } return(true); }