/// <summary>
        /// Permet d'insérer un calendrier
        /// </summary>
        /// <param name="calendar">Le calendrier qu'on doit insérer.</param>
        public async Task<Calendar> InsertCalendar(CalendarListEntry calendar)
        {
            Calendar simplecal = calendar;

            StreamContent calendarJson = new StreamContent(Service.Serialize(simplecal));
            calendarJson.Headers.Add("Content-Type", "application/json;charset=utf-8");
            Stream result = await Service.Post("https://www.googleapis.com/calendar/v3/calendars", calendarJson);
            if (result != null)
            {
                DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(CalendarListEntry));
                CalendarListEntry cal = (CalendarListEntry)deserializer.ReadObject(result);
               // mCalendars.Add(cal);
                return cal;
            }
            return null;
        }
 public EventControler(CalendarListEntry calendar)
 {
     Calendar = calendar;
 }
       /// <summary>
       /// Supprime un calendrier de la liste
       /// </summary>
       /// <param name="cal"></param>
        public void DeleteCalendar(CalendarListEntry cal)
        {

            CalendarBase calfind = null;
            int index = -1;

            foreach (CalendarBase calbase in monpan.Children)
            {
                if (calbase.cal != null)
                {
                    if (calbase.cal.Calendar.Id == cal.Id)
                    {
                        calfind = calbase;
                        index = monpan.Children.IndexOf(calbase);
                    }
                }
            }

            if (index != -1)
            {
                monpan.Children.RemoveAt(index);
                _calendriersIMG.Remove(calfind);
            }

        }
       /// <summary>
       /// Met à jour un calendrier de la liste
       /// </summary>
       /// <param name="cal"></param>
        public void MajCalendar(CalendarListEntry cal)
        {

            CalendarBase calfind = null;
            int index=-1;

            foreach (CalendarBase calbase in monpan.Children)
            {
                if(calbase.cal!=null)
                {   if (calbase.cal.Calendar.Id == cal.Id)
                {
                    calfind = calbase;
                   
                    index = monpan.Children.IndexOf(calbase);
                }
            }
            }

            if (index != -1)
            {
                
                monpan.Children.RemoveAt(index);
                _calendriersIMG.Remove(calfind);
                CalendarBase newcal = new CalendarGoogle(new CalendarViewModel(cal));
                newcal.PointerPressed += Cal_PointerPressed;
                newcal.IsHitTestVisible = true;
                newcal.Opacity = 0.5;
                newcal.Margin = new Thickness(0, 0, 15, 0);
                monpan.Children.Insert(index,newcal);
                _calendriersIMG.Add(newcal);
                _calendriersSelected = null;
            
                 }

           
        }
        /// <summary>
        /// Ajoute un calendrier de la liste
        /// </summary>
        /// <param name="cal"></param>
        public void AddCalendar(CalendarListEntry cal)
        {
            CalendarBase newcal = new CalendarGoogle(new CalendarViewModel(cal));
                newcal.PointerPressed += Cal_PointerPressed;
                newcal.IsHitTestVisible = true;
                newcal.Opacity = 0.5;
                newcal.Margin = new Thickness(0, 0, 15, 0);
                monpan.Children.Add(newcal);
                _calendriersIMG.Add(newcal);
                _calendriersSelected = null;
           


        }
        /// <summary>
        /// Permet de mettre à jour un calendrier.
        /// </summary>
        /// <param name="calendar">Le calendrier avec les modifications à appliquer.</param>
        public async Task<Calendar> UpdateCalendar(CalendarListEntry calendar)
        {
            Calendar simplecal = calendar;


            if (!String.IsNullOrEmpty(simplecal.Id))
            {
                StreamContent calendarJson = new StreamContent(Service.Serialize(simplecal));
                calendarJson.Headers.Add("Content-Type", "application/json;charset=utf-8");

                //Stream result = await Service.Put("https://www.googleapis.com/calendar/v3/users/me/calendarList/" + calendar.Id, calendarJson);

                Stream result = await Service.Put("https://www.googleapis.com/calendar/v3/calendars/" + calendar.Id, calendarJson);
               
                
                if (result != null)
                {
                    DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(CalendarListEntry));
                    CalendarListEntry cal = (CalendarListEntry)deserializer.ReadObject(result);
                  //  mCalendars.Remove(mCalendars.Single(c => c.Id == calendar.Id));
                   // mCalendars.Add(cal);
                    return cal;
                }
            }
            return null;
        }
 /// <summary>
 /// Permet de supprimer un calendrier 
 /// </summary>
 /// <param name="calendar">Le calendrier à supprimer</param>
 public async void DeleteCalendar(CalendarListEntry calendar)
 {
     if (!String.IsNullOrEmpty(calendar.Id))
     {
         StreamContent calendarJson = new StreamContent(Service.Serialize(calendar));
         calendarJson.Headers.Add("Content-Type", "application/json;charset=utf-8");
         Stream result = await Service.Delete("https://www.googleapis.com/calendar/v3/users/me/calendarList/"+calendar.Id);
         if (result != null)
         {
            // mCalendars.Remove(mCalendars.Single(cal => calendar.Id == cal.Id));
         }
     }
     
 }
 public CalendarViewModel(CalendarListEntry calendar)
 {
     _calendar = calendar;
 }