async void EditSubdivisionCommand(DAL.Models.Subdivision subdivision)
        {
            MessagingCenter.Subscribe <EditSubdivisionPage, DAL.Models.Subdivision>(this, "ChangeSubdivision", (sender, sub) =>
            {
                //this.LoadItemsCommand();
                if (sub != null)
                {
                    var pos = Items.IndexOf(Items.Where(x => x.id == sub.id).FirstOrDefault());
                    if (pos >= 0)
                    {
                        Items[pos] = sub;
                    }
                    else //no existe
                    {
                        Items.Add(sub);
                    }
                }
            });
            var edit = new EditSubdivisionPage(country, subdivision)
            {
                CloseWhenBackgroundIsClicked = true
            };

            await Navigation.PushPopupAsync(edit);
        }
예제 #2
0
 public EditSubdivisionViewModel(INavigation nav, Page _page, DAL.Models.Country _country, DAL.Models.Subdivision _sub)
 {
     Navigation = nav;
     page       = _page;
     if (_country == null)
     {
         _country = new DAL.Models.Country();
     }
     if (_sub == null)
     {
         _sub = new DAL.Models.Subdivision();
     }
     country     = _country;
     subdivision = _sub;
     Code        = subdivision.code;
     Name        = subdivision.name;
     Save        = new Command(SaveCommand);
     CloseModal  = new Command(CloseModalCommand);
 }
        async void DeleteCommand(DAL.Models.Subdivision subdivision)
        {
            if (subdivision.id.HasValue)
            {
                var answer = await page.DisplayAlert("Delete", $"Do you wan't to delete the subdivision {subdivision.name}?", "Yes", "No");

                if (answer)
                {
                    var data = await new DAL.Subdivision().DeleteAsync(country.id.Value, subdivision.id.Value);
                    if (data != null && data.Error != null && data.Error.errorMessages?.Count > 0)
                    {
                        await page.DisplayAlert("Subdivision ", data.Error.errorMessages[0], "Ok");
                    }
                    else
                    {
                        Items.Remove(subdivision);
                    }
                }
            }
        }
예제 #4
0
 public EditSubdivisionPage(DAL.Models.Country country, DAL.Models.Subdivision subdivision)
 {
     InitializeComponent();
     BindingContext = new EditSubdivisionViewModel(this.Navigation, this, country, subdivision);
 }