public async void TestAsync() { PersonsService service = new PersonsService(); Person2 newPerson = new Person2(new User(), "Jonaitis", "199-11-21", "2018-11-21", "test"); Console.WriteLine("person: " + newPerson); try { var response = await service.AddNewPersonAsync(newPerson); if (response != null) { Console.WriteLine("Done"); } else { Console.WriteLine("Error"); } } catch (Exception ex) { Console.WriteLine("error: " + ex); } /* var response2 = await service.GetPersonsList(); * * foreach (Person2 person in response2) * Console.WriteLine(person.Name);*/ }
async void OnAddPersonsDataButtonClicked(object sender, EventArgs e) { if (string.IsNullOrEmpty(nameTextBox.Text)) { await DisplayAlert(ConfigurationManager.AppSettings["SystemErrorTitle"], ConfigurationManager.AppSettings["AddPersonInvalidNoName"], ConfigurationManager.AppSettings["MessageBoxClosingBtnText"]); return; } if (_PersonSelected == null && PersonVM.Faces.Count < 1) { await DisplayAlert(ConfigurationManager.AppSettings["SystemErrorTitle"], ConfigurationManager.AppSettings["AddPersonInvalidNo"], ConfigurationManager.AppSettings["MessageBoxClosingBtnText"]); return; } addPerson.IsEnabled = false; editPerson.IsEnabled = false; //deletePerson.IsEnabled = false; PersonVM.Username = nameTextBox.Text; PersonVM.BirthDate = birthdatePicker.Date; PersonVM.MissingDate = missingdatePicker.Date; PersonVM.AdditionalInfo = addInfoTextBox.Text; if (string.IsNullOrEmpty(PersonVM.AdditionalInfo)) { PersonVM.AdditionalInfo = ""; } try { IList <byte[]> newPhotos = new List <byte[]>(); foreach (Face face in PersonVM.Faces) { if (face.PhotoByteArr != null && string.IsNullOrEmpty(face.BlobURI)) { newPhotos.Add(face.PhotoByteArr); } } if (_PersonSelected == null) { var addPerson = await _personsService.AddNewPersonAsync( new Person { Name = PersonVM.Username, BirthDate = PersonVM.BirthDate.ToString(), MissingDate = PersonVM.MissingDate.ToString(), AdditionalInfo = PersonVM.AdditionalInfo, CreatorId = App.CurrentUser, Photos = newPhotos } ); if (addPerson.Success) { await DisplayAlert("Success", "Person added", "Close"); ClearData(); } else { await DisplayAlert("Adding error" + ConfigurationManager.AppSettings["SystemErrorTitle"], addPerson.Error, ConfigurationManager.AppSettings["MessageBoxClosingBtnText"]); ErrorLogger.Instance.LogError(addPerson.Error); } } else { var updatePerson = await _personsService.UpdatePersonAsync( new Person { Id = PersonVM.Id, Name = PersonVM.Username, BirthDate = PersonVM.BirthDate.ToString(), MissingDate = PersonVM.MissingDate.ToString(), AdditionalInfo = PersonVM.AdditionalInfo, CreatorId = App.CurrentUser, Photos = newPhotos }, _PersonSelected.Id ); if (updatePerson.Success) { await DisplayAlert("Success", "Person updated", "Close"); } else { await DisplayAlert(ConfigurationManager.AppSettings["SystemErrorTitle"], updatePerson.Error, ConfigurationManager.AppSettings["MessageBoxClosingBtnText"]); ErrorLogger.Instance.LogError(updatePerson.Error); } } } catch (Exception ex) { ErrorLogger.Instance.LogException(ex); await DisplayAlert(ConfigurationManager.AppSettings["SystemErrorTitle"], ConfigurationManager.AppSettings["SystemErrorMessage"], ConfigurationManager.AppSettings["MessageBoxClosingBtnText"]); } finally { addPerson.IsEnabled = true; editPerson.IsEnabled = true; //deletePerson.IsEnabled = true; } }