Ejemplo n.º 1
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);
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
        public double GetExistsDistance(string source, string destination)
        {
            DistanceTable distance = DB.DistanceTables.FirstOrDefault(d => d.source == source && d.destination == destination);

            if (distance != null)
            {
                DB.DistanceTables.Attach(distance);
                distance.hits++;
                DB.SaveChanges();
                return(distance.distance);
            }
            return(-1);
        }