Exemplo n.º 1
0
        private async void AddButton_Clicked(object sender, EventArgs e)
        {
            bool isEntryRight = true;

            if (NameEntry.Text == null)
            {
                await DisplayAlert(Resource.Error, Resource.EnterTheNameOfConstellation, Resource.OK);

                isEntryRight = false;
            }
            if (isEntryRight)
            {
                string            uri   = ImageEntry.Text ?? "";
                Collection <Star> stars = new Collection <Star>();
                for (int i = 0, count = NamesOfStars.Count; i < count - 1; i++)
                {
                    if (NamesOfStars.ElementAt(i).Value != -1)
                    {
                        stars.Add(Stars.ElementAt(i));
                    }
                }

                if (Constellation != null)
                {
                    bool result = await DisplayAlert(Resource.ConfirmAction, Resource.AreYouSureYouWantToReplaceTheData, Resource.Yes, Resource.No);

                    if (!result)
                    {
                        return;
                    }
                    await DisplayAlert(Resource.Notification, Resource.TheDataWasSuccessfullyReplaced, Resource.OK);

                    Constellation.Name = NameEntry.Text;
                    Constellation.ImageOfConstellation = uri;
                    Constellation.Stars.Clear();
                    foreach (var s in stars)
                    {
                        Constellation.Stars.Add(s);
                    }
                    Constellation.DefinePosition();
                }
                else
                {
                    Data.Constellations.Add(new Constellation(NameEntry.Text, uri, stars));
                    await DisplayAlert(Resource.Notification, Resource.DataWasSuccessfullyAdded, Resource.OK);
                }
                await Navigation.PopModalAsync();
            }
        }