示例#1
0
        public double GetDistance(string source, string destination)
        {
            double distance = GetExistsDistance(source, destination);

            if (distance != -1) //if the specific place not exists in the db
            {
                return(distance);
            }

            distance = GetDistanceByGoogleMaps(source, destination);
            if (distance == -1)
            {
                return(-1);
            }

            DistanceModel dis = new DistanceModel();

            dis.Destination = destination;
            dis.Source      = source;
            dis.Hits        = 1;
            dis.Distance    = distance;
            CreateDistance(dis);

            return(distance);
        }
示例#2
0
        public DistanceModel GetPopularDistances()
        {
            DistanceTable popular = DB.DistanceTables.OrderByDescending(d => d.hits).FirstOrDefault();
            DistanceModel model   = DistanceConverter.EntityToModel(popular);

            //List<DistanceTable> popList = DB.DistanceTables.OrderByDescending(d => d.hits).Take(10).ToList();
            return(model);
        }
        public static DistanceModel EntityToModel(DistanceTable entity)
        {
            DistanceModel model = new DistanceModel();

            model.Destination = entity.destination;
            model.Distance    = entity.distance;
            model.Hits        = entity.hits;
            model.Source      = entity.source;
            model.Id          = entity.id;
            return(model);
        }
        public static DistanceTable ModelToEntity(DistanceModel model)
        {
            DistanceTable dis = new DistanceTable();

            dis.destination = model.Destination;
            dis.distance    = model.Distance;
            dis.hits        = model.Hits;
            dis.source      = model.Source;
            dis.id          = model.Id;
            return(dis);
        }
示例#5
0
        public void CreateDistance(DistanceModel model)
        {
            DistanceTable distance = DistanceConverter.ModelToEntity(model);

            DB.DistanceTables.Add(new DistanceTable
            {
                source      = distance.source,
                destination = distance.destination,
                distance    = distance.distance,
                hits        = 1
            });
            DB.SaveChanges();
        }