private async void SaveAction() { var item = new ModelsShared.Models.userprofile { Address = this.Address, FirstName = this.FirstName, LastName = this.LastName, UserId = this.UserId, Photo = this.Photo, UserName = this.UserName }; bool result = false; if (IsNew) { result = await MainVM.UserProfileCollections.Add(item); } else { result = await MainVM.UserProfileCollections.Update(this.UserId, item); } if (result) { ResourcesBase.ShowMessage("Data Berhasil Disimpan"); } else { ResourcesBase.ShowMessageError("Data Tidak Tersimpan"); } }
public void Add(T item) { Client client = new Client(); var obj = JsonConvert.SerializeObject(item); StringContent content = new StringContent(obj, Encoding.UTF8, "application/json"); try { var response = client.ClientContext.PostAsync(uri, content).Result; if (response.IsSuccessStatusCode == true) { var result = JsonConvert.DeserializeObject <T>(response.Content.ReadAsStringAsync().Result); if (response != null) { list.Add(result); OnChangeSource?.Invoke(result); SourceView.Refresh(); } ResourcesBase.ShowMessage("Data Berhasil Ditambah"); } else { throw new SystemException(response.ReasonPhrase); } } catch (Exception ex) { ResourcesBase.ShowMessageError(ex.Message); } }