コード例 #1
0
        public tbCust InsertCust(tbCust cust)
        {
            DBCustManaging db = new DBCustManaging();

            var bus = new tbEntityBusiness();

            if (db.tbEntity.FirstOrDefault() == null)
            {
                bus.InsertEntity();
            }

            var geoLocation = this.getGeoLocation(cust.Address);

            cust.Location = new Tables.Location()
            {
                Lat = geoLocation.results[0].geometry.location.Lat,
                Lng = geoLocation.results[0].geometry.location.Lng
            };

            cust.LegalEntityId = bus.getClosestEntity(cust.Location.Lat, cust.Location.Lng);

            db.tbCust.Add(cust);
            db.SaveChanges();

            return(cust);
        }
コード例 #2
0
        public void InsertEntity()
        {
            string jsonPath = ConfigurationManager.AppSettings["EntityJsonPath"].ToString();

            DBCustManaging db = new DBCustManaging();

            var tbentity = new List <tbEntity>();

            using (var reader = new StreamReader(jsonPath))
            {
                JavaScriptSerializer parser = new JavaScriptSerializer();
                tbentity = parser.Deserialize <List <tbEntity> >(reader.ReadToEnd());
            }

            foreach (var entity in tbentity)
            {
                var geoLocation = new tbCustBusiness().getGeoLocation(entity.Address);

                entity.Lat      = geoLocation.results[0].geometry.location.Lat;
                entity.Lng      = geoLocation.results[0].geometry.location.Lng;
                entity.Distance = 0;

                db.tbEntity.Add(entity);
                db.SaveChanges();
            }
        }
コード例 #3
0
        public string getClosestEntity(double custLat, double custLng)
        {
            DBCustManaging db = new DBCustManaging();

            var entityList = db.tbEntity;

            foreach (var entity in entityList)
            {
                entity.Distance = compareDistance(custLat, custLng, entity.Lat, entity.Lng);
            }

            List <tbEntity> entities = entityList.ToList();

            entities = entities.OrderByDescending(e => e.Distance).ToList();

            return(entities.Select(e => e.Id).Last());
        }