예제 #1
0
        protected async void Save()
        {
            IsBusy = true;
            try
            {
                if (ValidateObject())
                {
                    await App.Current.MainPage.DisplayAlert("Validation", "All Ok", "OK");

                    PetRepository petRepository = new PetRepository();
                    pet.Name         = Name.Value;
                    pet.Breed        = Breed.Value;
                    pet.DOB          = DOB.Value;
                    pet.Sex          = Sex.Value;
                    pet.Neutered     = Neutered.Value;
                    pet.Weight       = Weight.Value;
                    pet.ExerciseGoal = ExerciseGoal.Value;

                    if (PetImagePath.Value != string.Empty)
                    {
                        CopyDPToApplicationFolder();
                        //pet.DisplayPicture = GetBytesFromImageStream(PetImageStream.Value);
                    }

                    pet.DPPath = PetImagePath.Value;
                    bool result = false;
                    if (Id.Value == null || Id.Value <= 0)
                    {
                        result   = petRepository.AddPetAsync(pet);
                        Id.Value = pet.Id;
                    }
                    else if (Id.Value > 0)
                    {
                        pet.Id = Id.Value;
                        result = petRepository.UpdatePetAsync(pet);
                        //Id.Value = pet.Id;
                    }

                    if (result)
                    {
                        await App.Current.MainPage.DisplayAlert("Data Saved", "All Ok", "OK");
                    }
                }

                else
                {
                    await App.Current.MainPage.DisplayAlert("Validation", "Errors during validation", "OK");
                }
            }
            catch (Exception e)
            {
                //Console.WriteLine(e);
                throw;
            }
            finally
            {
                IsBusy = false;
            }
        }