コード例 #1
0
        static void Main(string[] args)
        {
            var services = new ServiceCollection();


            services.AddDbContext <ListingsDbContext>(options =>


                                                      options.UseSqlServer("Server=localhost;Database=properties-api;Trusted_Connection=True;"));

            services.AddScoped <IPropertiesRepository, PropertiesRepository>();
            var serviceProvider = services.BuildServiceProvider();

            _dbcontext = serviceProvider.GetService <ListingsDbContext>();
            _repo      = new PropertiesRepository(_dbcontext);

            // run this to import post codes
            if (!_dbcontext.PostCodes.Any())
            {
                ImportPostCodes();
            }



            //var properties = _dbcontext.Properties.ToList();
            //if (properties.Any())
            //{
            //    System.Console.WriteLine("Removing Properties");
            //    _dbcontext.Properties.RemoveRange(_dbcontext.Properties);
            //    _dbcontext.SaveChanges();
            //}

            //var agents = _dbcontext.Agents.ToList();
            //if (agents.Any())
            //{
            //    System.Console.WriteLine("Removing Agents");
            //    _dbcontext.Agents.RemoveRange(_dbcontext.Agents);
            //    _dbcontext.SaveChanges();
            //}

            //var agencies = _dbcontext.Agencies.ToList();
            //if (agencies.Any())
            //{
            //    System.Console.WriteLine("Removing Agencies");
            //    _dbcontext.Agencies.RemoveRange(_dbcontext.Agencies);
            //    _dbcontext.SaveChanges();
            //}

            PropertyGen propertyGen = new PropertyGen(_dbcontext);

            propertyGen.GenerateProperties();
        }
コード例 #2
0
        private void AddPropertyTypes(ListingsDbContext context)
        {
            if (context.PropertyTypes.Any() == false)
            {
                var propertyTypes = new List <string>()
                {
                    "House", "Appartment", "Unit", "Villa", "Townhouse", "Acerage"
                };

                propertyTypes.ForEach(c => context.Add(new PropertyType
                {
                    Name = c
                }));

                context.SaveChanges();
            }
            propertyTypes = _context.PropertyTypes.ToList();
        }
コード例 #3
0
 public ListingService(ListingsDbContext context, IBus publisher) : base(context)
 {
     this.context   = context;
     this.publisher = publisher;
 }
コード例 #4
0
 public SellerService(ListingsDbContext context)
 {
     this.context = context;
 }
コード例 #5
0
 public Properties(ListingsDbContext context)
 {
     _context = context;
 }
コード例 #6
0
 public LookupSeeder(ListingsDbContext context)
 {
     _context = context;
 }
コード例 #7
0
 public Agencies(ListingsDbContext context)
 {
     _context = context;
 }
コード例 #8
0
 public PropertyGen(ListingsDbContext context)
 {
     _context = context;
 }