/// <summary> /// Initialize function list in splitview control /// </summary> private void InitializeData() { NewMerchandiseItemList = new ObservableCollection<AdvertiseItem>(); SaleMerchandiseItemList = new ObservableCollection<AdvertiseItem>(); HotMerchandiseItemList = new ObservableCollection<AdvertiseItem>(); for (var i = 0; i < 10; i++) { var ad = new AdvertiseItem { Image = "/Assets/lol.jpg", Merchandise = "Mèo nguyên chất - Giảm giá siêu khuyến mãi cực hot", Market = "Chơ Phạm Văn Hai - K69" }; _newMerchandiseItemList.Add(ad); _saleMerchandiseItemList.Add(ad); _hotMerchandiseItemList.Add(ad); } }
private async void ButtonSave_Click(object sender, RoutedEventArgs e) { ToggleProgressRing(); bool check = false; if (txtTitle.Text != "" && txtDescribes.Text != null && cbStore.SelectedValue != null) { if (dpStartDate.Date <= dpEndDate.Date) { AdvertiseItem temp = new AdvertiseItem(); temp.Title = txtTitle.Text; temp.Describes = txtDescribes.Text; temp.StartDate = dpStartDate.Date.DateTime; temp.EndDate = dpEndDate.Date.DateTime; temp.StoreId = Convert.ToInt32(cbStore.SelectedValue); temp.IsRequired = MediateClass.AdvertiseVM.SelectedSale.IsRequired; if (!AdvertiseViewModel.isUpdate) { check = await MediateClass.AdvertiseVM.InsertSale(temp, media); } else { temp.SaleId = MediateClass.AdvertiseVM.SelectedSale.SaleId; temp.Image = MediateClass.AdvertiseVM.SelectedSale.Image; temp.SasQuery = MediateClass.AdvertiseVM.SelectedSale.SasQuery; check = await MediateClass.AdvertiseVM.UpdateSale(temp, media); } if (check) { await new MessageDialog("Successful!", "Sales").ShowAsync(); Frame.GoBack(); } else await new MessageDialog("Not successful!", "Sales").ShowAsync(); } else { await new MessageDialog("Start date must be lower or equal end date!", "Sales").ShowAsync(); } } else await new MessageDialog("Please fill the infomation!", "Sale").ShowAsync(); ToggleProgressRing(); }
public async Task<bool> DeleteSale() { try { if (Utilities.Helpers.NetworkHelper.Instance.HasInternetConnection) { JObject result = new JObject(); IDictionary<string, string> param = new Dictionary<string, string> { {"saleId", SelectedSale.SaleId.ToString()} }; var response = await App.MobileService.InvokeApiAsync("SaleInfoes", HttpMethod.Delete, param); result = JObject.Parse(response.ToString()); AdvertiseItem saleDel = result.ToObject<AdvertiseItem>(); if(saleDel.Image != null && saleDel.SasQuery != null) await Functions.Instance.DeleteImageInBlob("sales", saleDel.Image, saleDel.SasQuery); SelectedSale = null; } else { await new MessageDialog("You have not internet connection!", "Insert Product").ShowAsync(); return false; } } catch (Exception ex) { await new MessageDialog(ex.Message.ToString(), "Delete Sale").ShowAsync(); return false; } return true; }
public async Task<bool> UpdateSale(AdvertiseItem sale, StorageFile media) { try { if (Utilities.Helpers.NetworkHelper.Instance.HasInternetConnection) { if (sale.Image == null || sale.Image == "/Assets/LockScreenLogo.scale-200.png") { if (media == null) sale.Image = "/Assets/LockScreenLogo.scale-200.png"; else sale.Image = null; } JToken data = JToken.FromObject(sale); JToken result = await App.MobileService.InvokeApiAsync("SaleInfoes", data, HttpMethod.Put, null); JObject response = JObject.Parse(result.ToString()); SelectedSale = response.ToObject<AdvertiseItem>(); if (media != null) { await Functions.Instance.UploadImageToBlob("sales", SelectedSale.Image, SelectedSale.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; }
/// <summary> /// Get data from database with Json /// </summary> /// <param name="argument">parameter will get</param> /// <param name="type">type product will get : New,Sale,Best sale</param> /// <returns></returns> private async Task ImportData(IDictionary<string, string> argument) { JToken _product = null; try { if (NetworkHelper.Instance.HasInternetConnection) { _product = await App.MobileService.InvokeApiAsync("SaleInfoes", HttpMethod.Get, argument); JArray results = JArray.Parse(_product.ToString()); AdvertiseItemList = results.ToObject<ObservableCollection<AdvertiseItem>>(); _selectedAd = AdvertiseItemList[0]; _selectedAd.IsSelected = true; } } catch (Exception ex) { await new MessageDialog(ex.Message, "Error loading items").ShowAsync(); } }
//private void InitializeDummyAds() //{ // DummyAdvertiseList = new ObservableCollection<AdvertiseItem>(); // DummyAdvertiseList2 = new ObservableCollection<AdvertiseItem>(); // for (int i=0; i < 20; i++) // { // AdvertiseItem ad = new AdvertiseItem(); // ad.Image = "ms-appx:///Assets/Icon/FruitIcon.png"; // DummyAdvertiseList.Add(ad); // } // AdvertiseItem ad2 = new AdvertiseItem(); // ad2.Image = "ms-appx:///Assets/Icon/WelcomePaybay.png"; // DummyAdvertiseList2.Add(ad2); //} /// <summary> /// Initialize market /// </summary> private void InitializeProperties() { AdvertiseItemList = new ObservableCollection<AdvertiseItem>(); SaleList = new ObservableCollection<AdvertiseItem>(); SelectedAd = new AdvertiseItem(); SelectedSale = new AdvertiseItem(); }