public async Task<bool> UpdateMarket(Market market, StorageFile media) { try { if (Utilities.Helpers.NetworkHelper.Instance.HasInternetConnection) { if (market.Image == null || market.Image == "/Assets/LockScreenLogo.scale-200.png") { if (media == null) market.Image = "/Assets/LockScreenLogo.scale-200.png"; else market.Image = null; } JToken data = JToken.FromObject(market); JToken result = await App.MobileService.InvokeApiAsync("Markets", data, HttpMethod.Put, null); JObject response = JObject.Parse(result.ToString()); SelectedMarket = response.ToObject<Market>(); if (media != null) { await Functions.Instance.UploadImageToBlob("markets", SelectedMarket.Image, SelectedMarket.SasQuery, media); } } else { await new MessageDialog("You have not internet connection!", "Insert Product").ShowAsync(); return false; } } catch (Exception ex) { await new MessageDialog(ex.Message.ToString(), "Notification!").ShowAsync(); return false; } return true; }
private void InitializeProperties() { SelectedMarket = new Market(); MarketItemList = new ObservableCollection<Market>(); AllMarket = new ObservableCollection<Market>(); }
private async void ButtonSave_Click(object sender, RoutedEventArgs e) { ToggleProgressRing(); bool check = false; Market selectedMarket = MediateClass.MarketVM.SelectedMarket; if (txtMarketName.Text != "" && txtAddress.Text != null && txtPhone.Text != null && txtLat.Text != null && txtLng.Text != null) { Market temp = new Market(); temp.MarketName = txtMarketName.Text; temp.Address = txtAddress.Text; temp.Phone = txtPhone.Text; temp.OpenTime = tpOpenTime.Time; temp.CloseTime = tpCloseTime.Time; temp.Latitute = float.Parse(txtLat.Text); temp.Longitute = float.Parse(txtLng.Text); if (!MarketViewModel.isUpdate) { check = await MediateClass.MarketVM.InsertMarket(temp, media); } else { temp.MarketId = selectedMarket.MarketId; temp.Image = selectedMarket.Image; temp.SasQuery = selectedMarket.SasQuery; check = await MediateClass.MarketVM.UpdateMarket(temp, media); } if (check) { await new MessageDialog("Successful!", "Market").ShowAsync(); Frame.GoBack(); } else await new MessageDialog("Not successful!", "Market").ShowAsync(); } else await new MessageDialog("Please fill the infomation!", "Market").ShowAsync(); ToggleProgressRing(); }