Esempio n. 1
0
 private void addthisStruct(object obj)
 {
     isEnabled = false;
     isBusy    = true;
     Task.Run(async() =>
     {
         var doc = obj as hList;
         var d   = doc.hstruct;
         if (await _restServices.AddHStructFromDb(d.id))
         {
             await _hStructServices.SaveStruct(d);
             MessagingCenter.Send(this, "newStructAdd");
             _dialogServices.ShowMessage(d.fullName + " a été ajouter a votre liste de contact", false);
         }
         else
         {
             _dialogServices.ShowMessage("Erreur : Veuillez réessayer plus tard", true);
         }
         isBusy    = false;
         isEnabled = true;
         doc.add   = false;
         //refreshing(null);
     });
 }
        private void addHstruct(object obj)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                isEnabled = false;
                isBusy    = true;
            });
            var hstruct = new HealthStruct()
            {
                fullName = fullName,
                adress   = adress,
                phNumber = phNumber,
                email    = email,
                star     = star
            };

            if (!isEdit)
            {
                Task.Run(async() =>
                {
                    try
                    {
                        if (await _hStructServices.SaveStruct(hstruct))
                        {
                            MessagingCenter.Send(this, "HstructUpdated");
                        }
                        if (await _restServices.AddHealthStruct(hstruct))
                        {
                            _dialogSservices.ShowMessage(fullName + " a été ajouté avec succès ", false);

                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                await App.Current.MainPage.Navigation.PopModalAsync();
                            });
                        }
                    }
                    catch
                    {
                        Console.WriteLine("error adding new hstruct");
                        _dialogSservices.ShowMessage("Erreur , veuillez essayer plus tard", true);
                    }
                });
            }
            if (isEdit)
            {
                Task.Run(async() =>
                {
                    hstruct.id = id;
                    try
                    {
                        if (await _hStructServices.UpdateHStructAsync(hstruct))
                        {
                            MessagingCenter.Send(this, "HstructUpdated");
                        }
                        if (_restServices.UpdateHStruct(hstruct))
                        {
                            _dialogSservices.ShowMessage(fullName + " a été modifié avec succès ", false);
                        }
                    }
                    catch
                    {
                        Console.WriteLine("error adding new hstruct");
                        _dialogSservices.ShowMessage("Erreur , veuillez essayer plus tard", true);
                    }
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        await CoreMethods.PopPageModel();
                        RaisePropertyChanged();
                    });
                });
            }

            isBusy    = false;
            isEnabled = true;
        }