Ejemplo n.º 1
0
        void _list_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem == null)                                     // ensures we ignore this handler when the selection is just being cleared
            {
                return;
            }
            var selected = (CorsoCompleto)_list.SelectedItem;

            Preferiti newFavourite = new Preferiti()
            {
                Codice = selected.Codice, Insegnamento = selected.Insegnamento, Docente = selected.Docente
            };

            int index = _preferiti.FindIndex(f => f.Insegnamento == newFavourite.Insegnamento);

            if (index >= 0)
            {
                MessagingCenter.Send <ListaCorsi, Preferiti>(this, "deselect_fav", newFavourite);
                _preferiti.RemoveAt(index);
            }
            else
            {
                MessagingCenter.Send <ListaCorsi, Preferiti>(this, "select_fav", newFavourite);
                _preferiti.Add(newFavourite);
            }

            ((ListView)sender).SelectedItem = null;
        }
Ejemplo n.º 2
0
        public async Task DeletePreferito(Preferiti preferito)
        {
            await Initialize();

            var preferiti = await preferitiTable.Where(x => x.UserId == Settings.UserId && x.IdCorso == preferito.IdCorso).ToEnumerableAsync();


            if (preferiti.Count() > 0)
            {
                try
                {
                    await preferitiTable.DeleteAsync(preferiti.FirstOrDefault());
                }
                catch(Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }


            //TO DO try to delete Corso
            //devo verificare se ci sono altri utenti che hanno quel corso tra i preferiti, altrimenti lo "potrei" cancellare
            //if preferitiTable.Where(x => x.IdCorso == preferito.IdCorso).ToEnumerableAsync().Count() == 0) 
            //allora cancello anche dalla tabella corso
        }
Ejemplo n.º 3
0
        public async Task AddPreferito(Preferiti preferito)
        {
            await Initialize();

            checkAuthentication();

            if(! await ExistsPreferito(preferito))
                await preferitiTable.InsertAsync(preferito);

            //ho aggiunto un nuovo corso quindi devo aggiornare
            Settings.ToUpdate = true;

            //if (!await ExistsPreferito(preferito)) //se il corso non esiste, lo aggiungo
            //    await corsoTable.InsertAsync(preferito);
            //else
            //    await corsoTable.UpdateAsync(preferito); //magari è cambiato l'insegnante??

            //else
            //{
            //    await corsoTable.UpdateAsync(corso);
            //}

            //var users = await userTable.Where(x => x.Id == User.Id).ToEnumerableAsync();
            //if (users.Count() == 0) //se non esiste già un utente con lo stesso id
            //    await userTable.InsertAsync(User);
            //else //DA ELIMINARE SE NON SI VUOLE PERMETTERE L'UPDATE all'autenticazione
            //    await userTable.UpdateAsync(User);
        }
Ejemplo n.º 4
0
        public async Task<bool> ExistsPreferito(Preferiti preferito)
        {
            await Initialize();

            var preferiti = await preferitiTable.Where(x => x.UserId == Settings.UserId && x.IdCorso == preferito.IdCorso).ToEnumerableAsync();
            if (preferiti.Count() > 0)
                return true;
            else
                return false;
        }
Ejemplo n.º 5
0
//		void RemoveAction_Clicked (object sender, EventArgs e)
//		{
//			var mi = ((Xamarin.Forms.MenuItem)sender);
//			var orario = mi.CommandParameter as Orari;
//
//			var corso = _db.GetAllMieiCorsi().FirstOrDefault(x => x.Insegnamento == orario.Insegnamento);
//			_db.DeleteMieiCorsi(corso);
//
//			MessagingCenter.Send<OrarioGiornCell>(this, "delete_corso_context");
//			Debug.WriteLine(orario.Insegnamento);
//		}

        async void AddAction_Clicked(object sender, EventArgs e)
        {
            var mi     = ((Xamarin.Forms.MenuItem)sender);
            var orario = mi.CommandParameter as CorsoGiornaliero;
            var x      = _db.GetAllMieiCorsi();

            var toast = DependencyService.Get <IToastNotificator>();

            //if (_db.CheckAppartieneMieiCorsi (orario)) {
            //	await toast.Notify (ToastNotificationType.Error, "Attenzione!", orario.Insegnamento + " è già stato aggiunto ai tuoi preferiti!", TimeSpan.FromSeconds (3));
            //} else {
            //	_db.Insert(new Preferiti() { Codice = orario.Codice, Docente = orario.Docente, Insegnamento = orario.Insegnamento });
            //	await toast.Notify (ToastNotificationType.Success, "Complimenti", orario.Insegnamento + " aggiunto ai preferiti!", TimeSpan.FromSeconds (3));
            //}

            if (_db.CheckAppartieneMieiCorsi(orario))
            {
                await toast.Notify(ToastNotificationType.Error, "Attenzione!", orario.Insegnamento + " è già stato aggiunto ai tuoi preferiti!", TimeSpan.FromSeconds(3));
            }
            else
            {
                //**NON C'E CONNESSIONE INTERNET**
                if (!CrossConnectivity.Current.IsConnected)
                {   //non connesso a internet
                    await toast.Notify(ToastNotificationType.Error, "Errore", "Nessun accesso a internet", TimeSpan.FromSeconds(3));

                    return;
                }
                //await _service.Initialize();
                var preferito = new Preferiti()
                {
                    Codice = orario.Codice, Docente = orario.Docente, Insegnamento = orario.Insegnamento
                };
                var corso = new Corso()
                {
                    Insegnamento = preferito.Insegnamento, Codice = preferito.Codice, Docente = preferito.Docente,
                };

                await _service.AddCorso(corso);

                corso = await _service.GetCorso(corso);

                preferito.IdCorso = corso.Id;
                await _service.AddPreferito(preferito);

                _db.Insert(preferito);
                await toast.Notify(ToastNotificationType.Success, "Complimenti", orario.Insegnamento + " aggiunto ai preferiti!", TimeSpan.FromSeconds(3));
            }
        }