public ITravelCompanyBroker GetBroker(string dbConnectionString) { UtilityClass.CheckNotNull(dbConnectionString); UtilityClass.CheckConnectionStringLength(dbConnectionString); try { using (var brokerDBContext = new TravelCompanyBrokerContext(dbConnectionString)) { if (!brokerDBContext.Database.Exists()) { throw new NonexistentObjectException(); } } return(new TravelCompanyBroker(dbConnectionString)); } catch (NonexistentObjectException) { throw; } catch (Exception e) { throw new DbConnectionException(e.Message, e); } }
public ITravelCompany CreateNew(string travelCompanyConnectionString, string name) { UtilityClass.CheckNotNull(travelCompanyConnectionString); UtilityClass.CheckNotNull(name); UtilityClass.CheckNotEmpty(travelCompanyConnectionString); UtilityClass.CheckNotEmpty(name); UtilityClass.CheckConnectionStringLength(travelCompanyConnectionString); UtilityClass.CheckNameLength(name); UtilityClass.CheckOnlyAlphanumChar(name); if (dbConnectionString.Equals(travelCompanyConnectionString)) { throw new SameConnectionStringException(); } try { using (var brokerDBContext = new TravelCompanyBrokerContext(dbConnectionString)) { var travelCompany = new TravelCompanyDB() { TravelCompanyName = name, TravelCompanyConnectionString = travelCompanyConnectionString }; brokerDBContext.travelCompanies.Add(travelCompany); brokerDBContext.SaveChanges(); using (var travelCompanyDBContext = new TravelCompanyContext(travelCompanyConnectionString)) { travelCompanyDBContext.Database.Delete(); travelCompanyDBContext.Database.Create(); } return(new TravelCompany(name, travelCompanyConnectionString)); } } catch (DbUpdateException e) { if (e.ToString().Contains("KEY")) { throw new TapDuplicatedObjectException(); } throw new SameConnectionStringException(); } catch (Exception e) { throw new DbConnectionException(e.Message, e); } }
public ITravelCompanyBroker CreateNewBroker(string dbConnectionString) { UtilityClass.CheckNotNull(dbConnectionString); UtilityClass.CheckConnectionStringLength(dbConnectionString); try { using (var brokerDBContext = new TravelCompanyBrokerContext(dbConnectionString)) { brokerDBContext.Database.Delete(); brokerDBContext.Database.Create(); } return(new TravelCompanyBroker(dbConnectionString)); } catch (Exception e) { throw new DbConnectionException(e.Message, e); } }