private async void addNewPointFromShareAsync(string routeName)
 {
     if (_sharePointMessage != null)
     {
         ViewRoutePoint newPoint = new ViewRoutePoint(_routeItem.RouteId, string.Empty);
         newPoint.Version++;
         if (string.IsNullOrEmpty(_sharePointMessage.Subject))
         {
             string name = _sharePointMessage.Description.Substring(0, 15);
             if (_sharePointMessage.Description.Length > 15)
             {
                 name += "...";
             }
             newPoint.Name = name;
         }
         else
         {
             newPoint.Name = _sharePointMessage.Subject;
         }
         newPoint.Description = _sharePointMessage.Description;
         CustomGeocoding geo = new CustomGeocoding(newPoint.Description);
         if (await geo.GetCoordinatesAsync())
         {
             newPoint.Longitude = geo.Longtitude;
             newPoint.Latitude  = geo.Latitude;
         }
         if (newPoint.Save())
         {
             _sharePointMessage = null;
         }
     }
 }
        public bool Make(AutoGeneratedRouted autoRoute, string creatorId)
        {
            if (autoRoute.Points.Count > 0)
            {
                var vroute = new ViewRoute(string.Empty);
                vroute.CreatorId  = creatorId;
                vroute.CreateDate = DateTime.Now;
                vroute.Name       = autoRoute.Name;
                if (vroute.Save())
                {
                    foreach (var autoPoint in autoRoute.Points.Where(p => !p.IsDeleted))
                    {
                        var vroutePoint = new ViewRoutePoint(vroute.RouteId, string.Empty);
                        vroutePoint.Name      = autoPoint.Name;
                        vroutePoint.Longitude = autoPoint.Longitude;
                        vroutePoint.Latitude  = autoPoint.Latitude;
                        vroutePoint.Version++;
                        if (vroutePoint.Save())
                        {
                            foreach (var autoMedia in autoPoint.Images.Where(i => !i.IsDeleted))
                            {
                                string localImageId = autoMedia.Id;

                                /*if (mediaObjectIsExists(mediaId))
                                 * {
                                 *  //в случае если мы используем одно и то же фото в нескольких альбомах, придется его дублировать
                                 *  //связано с тем, что id media соответствует имени файла и если меняем свойства объекта в каком-то маршруте, меняется для всех
                                 *  //media object в этом случае один, и это проблема
                                 *  mediaId = makeNewMediaObject(mediaId);
                                 * }*/
                                string mediaId = makeNewMediaObject(localImageId);
                                vroutePoint.AddMediaItem(mediaId, MediaObjectTypeEnum.Image);
                            }
                            vroutePoint.Save();
                        }
                    }
                    return(true);
                }
            }


            return(false);
        }
Example #3
0
        private async Task <bool> updatePoints(RouteRoot routeRoot)
        {
            bool updateResult = true;

            List <string> pointsToUpload = new List <string>();
            var           pointsByRoute  = _routePointManager.GetPointsByRouteId(_routeId, true);

            //если есть новые точки, на отправку
            pointsToUpload.AddRange(pointsByRoute
                                    .Where(p => !routeRoot.Route.Points.Any(sp => sp.Id == p.RoutePointId)).Select(p => p.Id)
                                    .ToList());

            foreach (var serverPoint in routeRoot.Route.Points)
            {
                var localPoint = _routePointManager.GetPointById(serverPoint.Id);
                if ((localPoint == null) || (serverPoint.Version > localPoint.Version))
                {
                    ViewRoutePoint updatePoint = new ViewRoutePoint(serverPoint.RouteId, serverPoint.Id);
                    updatePoint.FillFromWSModel(serverPoint);
                    updateResult = updatePoint.Save();
                }
                else if (serverPoint.Version < localPoint.Version)
                {
                    //на сервере более старая версия, в очередь на отправку
                    pointsToUpload.Add(serverPoint.Id);
                }

                if (!updateResult)
                {
                    return(false);
                }
            }


            if (pointsToUpload.Count > 0)
            {
                List <ViewRoutePoint> viewPointsToUpload = new List <ViewRoutePoint>();

                foreach (string routePointId in pointsToUpload)
                {
                    viewPointsToUpload.Add(new ViewRoutePoint(routeRoot.Route.Id, routePointId));
                }

                updateResult = await UploadAsync(GetJsonStructuresPoints(viewPointsToUpload), _routePointsApi);
            }

            return(updateResult);
        }
 public void ApplyChanges()
 {
     Analytics.TrackEvent("Description edited");
     _vpoint.Version++;
     _vpoint.Save();
 }