示例#1
0
        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);
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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);
            }
        }