Beispiel #1
0
        public bool ProvinceCodeExists(string provinceCode)
        {
            if (provinceCode.Length != 2)
            {
                return(false);
            }
            if (_context == null)
            {
                _context = Context.GetContext();
            }
            var checkCode = _context.Province.Where(p => p.ProvinceCode == provinceCode).ToList();

            return(checkCode.Count() > 0);
        }
 public static void MakeContext(IConfiguration config)
 {
     // Singleton pattern is overkill I think, instance is made in Startup.cs
     // so should be availble everywhere.  Static context / _context ensure only
     // one variable of context can exist
     if (_context == null)
     {
         lock (padlock) {
             if (_context == null)
             {
                 string connectionString = config["Database:connection"];
                 var    optionsBuilder   = new DbContextOptionsBuilder <BusServiceContext>();
                 optionsBuilder.UseSqlServer(connectionString);
                 _context = new BusServiceContext(optionsBuilder.Options);
             }
         }
     }
 }
Beispiel #3
0
        private BusServiceContext _context; // database connection injection

        public Driver(BusServiceContext context)
        {
            _context = context;
        }