protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            switch (hiddenAjaxAction.Value)
            {
                case "saveRoute":
                    aqufitEntities entities = new aqufitEntities();
                    Affine.Data.MapRoute route = new MapRoute()
                    {
                        Name = atiGMapRoute.RouteTitle,
                        PortalKey = this.PortalId,                  // TODO: send this in
                        UserSetting = entities.UserSettings.First( u => u.Id == UserSettings.Id ),
                        RouteDistance = atiGMapRoute.RouteDistance,
                        CreationDate = DateTime.Now,
                        WorkoutTypeId = atiGMapRoute.WorkoutTypeKey
                    };

                    entities.AddToMapRoutes(route);
                    double zoom = atiGMapRoute.FitZoom;
                    double w = atiGMapRoute.MapWidth/200.0;
                    double h = atiGMapRoute.MapHeight/100.0;
                    double r = w > h ? w : h;
                    zoom = r > 0 ? zoom - Math.Sqrt(r) : zoom + Math.Sqrt(r);
                    route.ThumbZoom = (short)Math.Floor(zoom);

                    Affine.Data.MapRoutePoint[] points = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint() { Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order, MapRoute = route }).ToArray<Affine.Data.MapRoutePoint>();
                    route.MapRoutePoints.Concat(points);
                    double minLat = double.MaxValue;
                    double minLng = double.MaxValue;
                    double maxLat = double.MinValue;
                    double maxLng = double.MinValue;
                    foreach( Affine.Data.MapRoutePoint p in points )
                    {
                        if (p.Lat < minLat)
                        {
                            minLat = p.Lat;
                        }
                        if (p.Lng < minLng)
                        {
                            minLng = p.Lng;
                        }
                        if (p.Lat > maxLat)
                        {
                            maxLat = p.Lat;
                        }
                        if (p.Lng > maxLng)
                        {
                            maxLng = p.Lng;
                        }
                    }
                    route.LatMax = maxLat;
                    route.LatMin = minLat;
                    route.LngMax = maxLng;
                    route.LngMin = minLng;
                    // Cull points until there are 100 or less points to make the encoded polyline fit the 512 bytes
                    int len = 100;
                    IList<Affine.Data.MapRoutePoint> pointCopy = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint() { Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order }).ToList<Affine.Data.MapRoutePoint>();
                    pointCopy = CullPoints(pointCopy, len);
                    route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                    while (route.PolyLineEncoding.Length > 512)
                    {
                        len = len/2;
                        pointCopy = CullPoints(pointCopy, len);
                        route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                    }
                    entities.SaveChanges();
                    MapRoute passback = entities.MapRoutes.Where(m => m.UserSetting.Id == this.UserSettings.Id && m.PortalKey == this.PortalId ).OrderByDescending( m => m.Id).FirstOrDefault();
                    // routes creater needs the route to show up in their route list now.
                    User2MapRouteFav fav = new User2MapRouteFav()
                    {
                        MapRoute = passback,
                        UserSettingsKey = UserSettings.Id
                    };
                    entities.AddToUser2MapRouteFav(fav);
                    entities.SaveChanges();

                    Affine.Data.json.MapRoute mr = new Affine.Data.json.MapRoute() { Id = passback.Id, Name = passback.Name, RouteDistance = passback.RouteDistance };
                    RadAjaxManager1.ResponseScripts.Add(" setSelectedMap(" + passback.Id + ", '" + passback.Name + "', " + passback.RouteDistance + ", ''); ");
                    break;
            }
            // save and close  RadAjaxManager1.ResponseScripts.Add();  /
        }
Example #2
0
        protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            try
            {
                aqufitEntities entities = new aqufitEntities();
                switch (hiddenAjaxAction.Value)
                {
                case "addRoute":
                    // few things to do here...
                    // 1) check to see if this route is already in the fav.
                    long             rid   = Convert.ToInt64(hiddenAjaxValue.Value);
                    User2MapRouteFav check = entities.User2MapRouteFav.FirstOrDefault(f => f.UserSettingsKey == this.UserSettings.Id && f.MapRoute.Id == rid);
                    if (check != null)
                    {
                        // TODO: postback a message saying that the route is already there.
                        //    status = "Route already in list.  TODO: dialog with a way to 'view my routes' | 'record workout for route'";
                    }
                    else
                    {       // add the route.
                        MapRoute         mr  = entities.MapRoutes.First(r => r.Id == rid);
                        User2MapRouteFav fav = new User2MapRouteFav()
                        {
                            UserSettingsKey = this.UserSettings.Id,
                            MapRoute        = mr
                        };
                        entities.AddToUser2MapRouteFav(fav);
                        entities.SaveChanges();
                        //TODO: dialog with a way to 'view my routes' | 'record workout for route'";
                        RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.RouteAddedDialog.open(); ");
                    }
                    break;

                case "remRoute":
                    // few things to do here...
                    long             remid = Convert.ToInt64(hiddenAjaxValue.Value);
                    User2MapRouteFav toRem = entities.User2MapRouteFav.FirstOrDefault(f => f.UserSettingsKey == this.UserSettings.Id && f.MapRoute.Id == remid);
                    if (toRem != null)
                    {
                        // remove the route from fav... any workouts will still be logged though.
                        entities.DeleteObject(toRem);
                        entities.SaveChanges();
                        //   status = "TODO:";
                    }
                    break;

                case "delStream":
                    long sid = Convert.ToInt64(hiddenAjaxValue.Value);
                    Affine.Data.Managers.LINQ.DataManager.Instance.deleteStream(UserSettings, sid);
                    break;

                case "delComment":
                    long cid = Convert.ToInt64(hiddenAjaxValue.Value);
                    Affine.Data.Managers.LINQ.DataManager.Instance.deleteComment(UserSettings, cid);
                    break;
                }
            }
            catch (Exception ex)
            {
                // TODO: better error handling
                RadAjaxManager1.ResponseScripts.Add(" alert('" + ex.Message + "');");
            }
        }
Example #3
0
        protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            switch (hiddenAjaxAction.Value)
            {
            case "saveRoute":
                aqufitEntities       entities = new aqufitEntities();
                Affine.Data.MapRoute route    = new MapRoute()
                {
                    Name          = atiGMapRoute.RouteTitle,
                    PortalKey     = this.PortalId,                  // TODO: send this in
                    UserSetting   = entities.UserSettings.First(u => u.Id == UserSettings.Id),
                    RouteDistance = atiGMapRoute.RouteDistance,
                    CreationDate  = DateTime.Now,
                    WorkoutTypeId = atiGMapRoute.WorkoutTypeKey
                };

                entities.AddToMapRoutes(route);
                double zoom = atiGMapRoute.FitZoom;
                double w    = atiGMapRoute.MapWidth / 200.0;
                double h    = atiGMapRoute.MapHeight / 100.0;
                double r    = w > h ? w : h;
                zoom            = r > 0 ? zoom - Math.Sqrt(r) : zoom + Math.Sqrt(r);
                route.ThumbZoom = (short)Math.Floor(zoom);

                Affine.Data.MapRoutePoint[] points = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint()
                {
                    Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order, MapRoute = route
                }).ToArray <Affine.Data.MapRoutePoint>();
                route.MapRoutePoints.Concat(points);
                double minLat = double.MaxValue;
                double minLng = double.MaxValue;
                double maxLat = double.MinValue;
                double maxLng = double.MinValue;
                foreach (Affine.Data.MapRoutePoint p in points)
                {
                    if (p.Lat < minLat)
                    {
                        minLat = p.Lat;
                    }
                    if (p.Lng < minLng)
                    {
                        minLng = p.Lng;
                    }
                    if (p.Lat > maxLat)
                    {
                        maxLat = p.Lat;
                    }
                    if (p.Lng > maxLng)
                    {
                        maxLng = p.Lng;
                    }
                }
                route.LatMax = maxLat;
                route.LatMin = minLat;
                route.LngMax = maxLng;
                route.LngMin = minLng;
                // Cull points until there are 100 or less points to make the encoded polyline fit the 512 bytes
                int len = 100;
                IList <Affine.Data.MapRoutePoint> pointCopy = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint()
                {
                    Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order
                }).ToList <Affine.Data.MapRoutePoint>();
                pointCopy = CullPoints(pointCopy, len);
                route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                while (route.PolyLineEncoding.Length > 512)
                {
                    len       = len / 2;
                    pointCopy = CullPoints(pointCopy, len);
                    route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                }
                entities.SaveChanges();
                MapRoute passback = entities.MapRoutes.Where(m => m.UserSetting.Id == this.UserSettings.Id && m.PortalKey == this.PortalId).OrderByDescending(m => m.Id).FirstOrDefault();
                // routes creater needs the route to show up in their route list now.
                User2MapRouteFav fav = new User2MapRouteFav()
                {
                    MapRoute        = passback,
                    UserSettingsKey = UserSettings.Id
                };
                entities.AddToUser2MapRouteFav(fav);
                entities.SaveChanges();

                Affine.Data.json.MapRoute mr = new Affine.Data.json.MapRoute()
                {
                    Id = passback.Id, Name = passback.Name, RouteDistance = passback.RouteDistance
                };
                RadAjaxManager1.ResponseScripts.Add(" setSelectedMap(" + passback.Id + ", '" + passback.Name + "', " + passback.RouteDistance + ", ''); ");
                break;
            }
            // save and close  RadAjaxManager1.ResponseScripts.Add();  /
        }
 protected void bAjaxPostback_Click(object sender, EventArgs e)
 {
     try
     {
         aqufitEntities entities = new aqufitEntities();
         switch (hiddenAjaxAction.Value)
         {
             case "addRoute":
                 // few things to do here...
                 // 1) check to see if this route is already in the fav.
                 long rid = Convert.ToInt64(hiddenAjaxValue.Value);
                 User2MapRouteFav check = entities.User2MapRouteFav.FirstOrDefault(f => f.UserSettingsKey == this.UserSettings.Id && f.MapRoute.Id == rid);
                 if (check != null)
                 {
                     // TODO: postback a message saying that the route is already there.
                 //    status = "Route already in list.  TODO: dialog with a way to 'view my routes' | 'record workout for route'";
                 }
                 else
                 {   // add the route.
                     MapRoute mr = entities.MapRoutes.First(r => r.Id == rid);
                     User2MapRouteFav fav = new User2MapRouteFav()
                     {
                         UserSettingsKey = this.UserSettings.Id,
                         MapRoute = mr
                     };
                     entities.AddToUser2MapRouteFav(fav);
                     entities.SaveChanges();
                     //TODO: dialog with a way to 'view my routes' | 'record workout for route'";
                     RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.RouteAddedDialog.open(); ");
                 }
                 break;
             case "remRoute":
                 // few things to do here...
                 long remid = Convert.ToInt64(hiddenAjaxValue.Value);
                 User2MapRouteFav toRem = entities.User2MapRouteFav.FirstOrDefault(f => f.UserSettingsKey == this.UserSettings.Id && f.MapRoute.Id == remid);
                 if (toRem != null)
                 {
                     // remove the route from fav... any workouts will still be logged though.
                     entities.DeleteObject(toRem);
                     entities.SaveChanges();
                  //   status = "TODO:";
                 }
                 break;
             case "delStream":
                 long sid = Convert.ToInt64(hiddenAjaxValue.Value);
                 Affine.Data.Managers.LINQ.DataManager.Instance.deleteStream(UserSettings, sid);
                 break;
             case "delComment":
                 long cid = Convert.ToInt64(hiddenAjaxValue.Value);
                 Affine.Data.Managers.LINQ.DataManager.Instance.deleteComment(UserSettings, cid);
                 break;
         }
     }
     catch (Exception ex)
     {
         // TODO: better error handling
         RadAjaxManager1.ResponseScripts.Add( " alert('" + ex.Message + "');");
     }
 }