public void DeletePoiInCascade(PointOfInterest poi)
        {
            List<Note> noteList = dsNote.LoadNotesByPoiId(poi.Id);
            List<Picture> pictureList = dsPicture.LoadPicturesByPoiId(poi.Id);

            // Removing items
            DeleteNotesAndPictures(noteList, pictureList);
        }
        public void DeletePoi(PointOfInterest poi, bool deleteCascade)
        {
            var existing = db.pointsOfInterests.FirstOrDefault(x => x.Id == poi.Id);

            if (existing != null)
            {
                if (deleteCascade)
                {
                    DataServiceCommon dsCommon = new DataServiceCommon();
                    dsCommon.DeletePoiInCascade(poi);
                }

                db.pointsOfInterests.DeleteOnSubmit(existing);
                db.SubmitChanges();
            }
        }
        public void UpdatePoi(PointOfInterest poi)
        {
            PointOfInterest poiToUpdate = db.pointsOfInterests.First(x => x.Id == poi.Id);

            poiToUpdate.Location = poi.Location;
            poiToUpdate.Name = poi.Name;
            poiToUpdate.Latitude = poi.Latitude;
            poiToUpdate.Longitude = poi.Longitude;

            try
            {
                db.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while trying to save a point of interest : " + e);
            }
        }
        private void Init(int trip, int note, PointOfInterest poi, Mode mode)
        {
            this.Mode = mode;

            if (this.Mode == ViewModels.Mode.add)
            {
                Note = new Note();
                DataServiceTrip dsTrip = new DataServiceTrip();
                Note.Trip = dsTrip.getTripById(trip);
                Note.Date = DateTime.Now;
                if (poi != null)
                    this.POISelected = poi;
            }
            else
            {
                Note = GetNoteInDB(note);
            }

            if (Note.Trip.PointsOfInterests != null)
                _poiList = new List<PointOfInterest>(Note.Trip.PointsOfInterests);

            EditableObject = new Caretaker<Note>(this.Note);
            EditableObject.BeginEdit();

            InitialiseValidator();
        }
 public void addPoi(PointOfInterest poi)
 {
     db.pointsOfInterests.InsertOnSubmit(poi);
     db.SubmitChanges();
 }
        void MyPushpin_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            CheckMapp.Utils.PlaceNearToMap.PlaceNearMap placeNearYou = (CheckMapp.Utils.PlaceNearToMap.PlaceNearMap)(sender as Pushpin).Tag;

            //Create a new custom message box
            CustomMessageBox messageBox = new CustomMessageBox()
            {
                Caption = placeNearYou.Info,
                Message = placeNearYou.Summary + Environment.NewLine + Environment.NewLine + AppResources.PlaceNearAdd,
                LeftButtonContent = AppResources.Add.ToLower(),
                RightButtonContent = AppResources.Cancel.ToLower(),
                IsFullScreen = false,
            };

            messageBox.Dismissed += (s1, e1) =>
            {
                switch (e1.Result)
                {
                    case CustomMessageBoxResult.LeftButton:
                        PointOfInterest newPOI = new PointOfInterest();
                        newPOI.Trip = ViewModel.Trip;
                        newPOI.Latitude = placeNearYou.Coordinate.Latitude;
                        newPOI.Longitude = placeNearYou.Coordinate.Longitude;
                        newPOI.Name = placeNearYou.Info;
                        ViewModel.AddPOINearCommand.Execute(newPOI);
                        break;
                    default:
                        break;
                }
            };

            messageBox.Show();
        }
        /// <summary>
        /// Message personnalisé pour savoir comment on gere les objets reliés au POI
        /// </summary>
        /// <param name="poiSelected"></param>
        private void ConfirmDeletePOI(PointOfInterest poiSelected)
        {
            CheckBox checkBoxDelete = new CheckBox()
            {
                Content = AppResources.DeletePOIObject,
                Margin = new Thickness(0, 14, 0, -2)
            };

            CheckBox checkBoxNull = new CheckBox()
            {
                Content = AppResources.NullPOIObject,
                Margin = new Thickness(0, 14, 0, -2)
            };

            //Simulation de grouped Checkbox
            checkBoxDelete.Checked += (s1, e1) =>
            {
                checkBoxNull.IsChecked = !(s1 as CheckBox).IsChecked;
            };
            checkBoxDelete.Unchecked += (s1, e1) =>
            {
                if (checkBoxNull.IsChecked == checkBoxDelete.IsChecked)
                    checkBoxDelete.IsChecked = !checkBoxDelete.IsChecked;
            };
            checkBoxNull.Unchecked += (s1, e1) =>
            {
                if (checkBoxNull.IsChecked == checkBoxDelete.IsChecked)
                    checkBoxNull.IsChecked = !checkBoxNull.IsChecked;
            };
            checkBoxNull.Checked += (s1, e1) =>
            {
                checkBoxDelete.IsChecked = !(s1 as CheckBox).IsChecked;
            };

            checkBoxNull.IsChecked = true;
            checkBoxDelete.IsChecked = false;

            TiltEffect.SetIsTiltEnabled(checkBoxDelete, true);
            TiltEffect.SetIsTiltEnabled(checkBoxNull, true);

            StackPanel stack = new StackPanel();
            stack.Orientation = System.Windows.Controls.Orientation.Vertical;
            stack.Children.Add(checkBoxDelete);
            stack.Children.Add(checkBoxNull);

            //Create a new custom message box
            CustomMessageBox messageBox = new CustomMessageBox()
            {
                Caption = AppResources.Warning,
                Message = AppResources.POIObject,
                Content = stack,
                LeftButtonContent = "ok",
                RightButtonContent = AppResources.Cancel.ToLower(),
                IsFullScreen = false
            };

            //Define the dismissed event handler
            messageBox.Dismissed += (s1, e1) =>
            {
                ViewModel.DeletePOIObject = (bool)checkBoxDelete.IsChecked;

                if (e1.Result == CustomMessageBoxResult.LeftButton)
                {
                    if (poiSelected != null)
                    {
                        ViewModel.DeletePOICommand.Execute(poiSelected);
                        POILLS.ItemsSource = ViewModel.PointOfInterestList;
                    }
                    else
                    {
                        var placeToDeleteList = new List<object>(POILLS.SelectedItems as IList<object>);

                        ViewModel.DeletePOIsCommand.Execute(new List<object>(POILLS.SelectedItems as IList<object>));
                        POILLS.ItemsSource = ViewModel.PointOfInterestList;
                    }

                    (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = (POILLS.ItemsSource.Count > 0);

                }
            };

            //launch the task
            messageBox.Show();
        }
        private void Init(int trip, int photo, PointOfInterest poi, Mode mode)
        {
            this.Mode = mode;

            if (this.Mode == ViewModels.Mode.add)
            {
                Picture = new Picture();
                DataServiceTrip dsTrip = new DataServiceTrip();
                Picture.Trip = dsTrip.getTripById(trip);
                Picture.Date = DateTime.Now;
                if (poi != null)
                    POISelected = poi;
            }
            else
            {
                Picture = GetPictureInDB(photo);
            }

            if (Picture.Trip.PointsOfInterests != null)
                PoiList = new List<PointOfInterest>(Picture.Trip.PointsOfInterests);

            EditableObject = new Caretaker<Picture>(this.Picture);
            EditableObject.BeginEdit();

            InitialiseValidator();
        }