コード例 #1
0
 public static List<HouseModel> GetAllHouses()
 {
     using (var db = new SystemDBContext())
     {
         return db.Houses.ToList();
     }
 }
コード例 #2
0
 public List<TestModel> GetTestModel()
 {
     using (var db = new SystemDBContext())
     {
         return db.TestModels.ToList();
     }
 }
コード例 #3
0
 public static void InsertHouseModel(HouseModel model)
 {
     using (var db = new SystemDBContext())
     {
         db.Houses.Add(model);
         db.SaveChanges();
     }
 } 
コード例 #4
0
 private static bool CheckTableExists()
 {
     var context = new SystemDBContext();
     try
     {
         context.Houses.Count();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
コード例 #5
0
        public static void UpdateDatabase(string csv_file_path)
        {
            var data = getCSVContent(csv_file_path);
            var houseModel = GetHouseModel(data);

            using (var db = new SystemDBContext())
            {
                if (!CheckTableExists())
                    return;

                var dbHouses = db.Houses.Select(x => x.Hash).ToList();

                foreach (var house in houseModel.Where(house => !dbHouses.Contains(house.Hash)))
                {
                    db.Houses.Add(house);
                }
                db.SaveChanges();
            }
        }
コード例 #6
0
        public static List<HouseModel> GetHouseNear(HouseLocalizationRequest request)
        {
            using (var db = new SystemDBContext())
            {
                var dbHouses = db.Houses.ToList();
                var result = new List<HouseModel>();

                foreach (var house in dbHouses)
                {
                    if (house.Lat != "" && house.Lon != "")
                    {
                        var deltaLon = double.Parse(house.Lon) - request.lonStart;
                        var deltaLat = double.Parse(house.Lat) - request.latStart;

                        if(Math.Sqrt(Math.Pow(deltaLat,2) + Math.Pow(deltaLon, 2)) <= request.radius)
                            result.Add(house);
                    }
                }
                return result;
            }
        }