/// <summary>
        /// Initializes a new instance of the AddTripViewModel class.
        /// </summary>
        public AddEditTripViewModel(INavigationService navigationService)
        {
            Messenger.Default.Register<Tuple<int, Mode>>(this,
            tuple =>
            {
            this.Mode = tuple.Item2;
            Departure = String.Empty;
            Destination = String.Empty;

            if (this.Mode == Mode.add)
            {
            Trip = new Trip();
            Trip.BeginDate = DateTime.Now;
            }
            else
            {
            DataServiceTrip dsTrip = new DataServiceTrip();
            this.Trip = dsTrip.getTripById(tuple.Item1);
            }

            this.FriendList = Utility.FriendToList(Trip.FriendList);
            InitialiseValidator();

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

            this._navigationService = navigationService;
        }
        public void DeleteTripInCascade(Trip trip)
        {
            List<Note> noteList = dsNote.LoadNotesFromTrip(trip);
            List<Picture> pictureList = dsPicture.LoadPicturesFromTrip(trip);
            List<PointOfInterest> poiList = dsPoi.LoadPointOfInterestsFromTrip(trip).ToList();

            // Removing items
            DeleteNotesAndPictures(noteList, pictureList);
            DeletePois(poiList, true);
        }
        public void DeleteTrip(Trip trip)
        {
            var existing = db.trips.Single(x => x.Id == trip.Id);

            if (existing != null)
            {
                DataServiceCommon dsCommon = new DataServiceCommon();
                dsCommon.DeleteTripInCascade(trip);

                db.trips.DeleteOnSubmit(existing);
                db.SubmitChanges();
            }
        }
        public void UpdateTrip(Trip trip)
        {
            Trip tripToUpdate = db.trips.Where(x => x.Id == trip.Id).First();

            tripToUpdate.Name = trip.Name;
            tripToUpdate.BeginDate = trip.BeginDate;
            //tripToUpdate.Departure = trip.Departure;
            //tripToUpdate.Destination = trip.Destination;
            tripToUpdate.EndDate = trip.EndDate;

            try
            {
                db.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while trying to save a trip" + e);
            }
        }
        /// <summary>
        /// Met a jour la tuile sur l'écran d'accueil avec les nouvelles infos du voyage en cours
        /// </summary>
        /// <param name="current"></param>
        public void CheckUpdateTile(Trip current)
        {
            IconicTileData newTileData = new IconicTileData();
            newTileData.Title = "Checkmapp";
            newTileData.WideContent1 = String.Empty;
            newTileData.WideContent2 = String.Empty;
            newTileData.IconImage = new Uri(@"Assets/Logo.png", UriKind.Relative);
            newTileData.SmallIconImage = new Uri(@"Assets/Logo.png", UriKind.Relative);
            if (current != null)
            {
                newTileData.WideContent1 = current.Name;
                int day = 0;
                TimeSpan elapsed = DateTime.Now.Subtract(current.BeginDate);
                if (elapsed.TotalDays > 0)
                    day = (int)elapsed.TotalDays;

                newTileData.WideContent2 = AppResources.Day + " " + day;
            }

            //Mise a jour (pour le texte)
            ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault();
            if (tile != null)
                tile.Update(newTileData);
        }
 public void addTrip(Trip newTrip)
 {
     db.trips.InsertOnSubmit(newTrip);
     db.SubmitChanges();
 }
 public ObservableCollection<PointOfInterest> LoadPointOfInterestsFromTrip(Trip trip)
 {
     List<PointOfInterest> listPOI = db.pointsOfInterests.Where(x => x.Trip == trip).ToList();
     return new ObservableCollection<PointOfInterest>(listPOI);
 }
 private void DeleteTrip(Trip trip)
 {
     DataServiceTrip dsTrip = new DataServiceTrip();
     dsTrip.DeleteTrip(trip);
     Messenger.Default.Send<List<Trip>, TimelineViewModel>(ArchiveTripList.ToList());
 }
 public List<Picture> LoadPicturesFromTrip(Trip trip)
 {
     return db.pictures.Where(x => x.Trip == trip).ToList();
 }
 private void OnUserControlElementTap(Trip trip)
 {
     if (UserControlElementTap != null)
     {
         UserControlElementTap(trip, EventArgs.Empty);
     }
 }
 public List<Note> LoadNotesFromTrip(Trip trip)
 {
     return db.notes.Where(x => x.Trip == trip).ToList();
 }