public ITravelCompany Get(string name) { UtilityClass.CheckNotNull(name); UtilityClass.CheckNameLength(name); UtilityClass.CheckOnlyAlphanumChar(name); try { using (var brokerDBContext = new TravelCompanyBrokerContext(dbConnectionString)) { var TCConnString = (from tc in brokerDBContext.travelCompanies where tc.TravelCompanyName == name select tc.TravelCompanyConnectionString).Single(); return(new TravelCompany(name, TCConnString)); } } catch (InvalidOperationException) { throw new NonexistentTravelCompanyException(); } catch (Exception e) { throw new DbConnectionException(e.Message, e); } }
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); } }
public ReadOnlyCollection <string> KnownTravelCompanies() { try { using (var brokerDBContext = new TravelCompanyBrokerContext(dbConnectionString)) { List <string> travelCompanies = new List <string>(); var query = from tc in brokerDBContext.travelCompanies select tc.TravelCompanyName; foreach (var item in query) { travelCompanies.Add(item); } return(travelCompanies.AsReadOnly()); } } catch (Exception e) { throw new DbConnectionException(e.Message, e); } }