public override async Task InitializeAsync(object navigationData) { if (BasketItems == null) { BasketItems = new ObservableCollection <BasketItem>(); } var authToken = _settingsService.AuthAccessToken; var userInfo = await _userService.GetUserInfoAsync(authToken); // Update Basket var basket = await _basketService.GetBasketAsync(userInfo.UserId, authToken); if (basket != null && basket.Items != null && basket.Items.Any()) { BadgeCount = 0; BasketItems.Clear(); foreach (var basketItem in basket.Items) { BadgeCount += basketItem.Quantity; await AddBasketItemAsync(basketItem); } } MessagingCenter.Unsubscribe <CatalogDetailsViewModel, CatalogItem>(this, MessageKeys.AddProduct); MessagingCenter.Subscribe <CatalogDetailsViewModel, CatalogItem>(this, MessageKeys.AddProduct, async(sender, arg) => { BadgeCount++; await AddCatalogItemAsync(arg); }); await base.InitializeAsync(navigationData); }
public void OnBasketClickCommand() { var basketWindow = new Views.Controls.BasketWindow(); if (basketWindow.DataContext is Controls.BasketWindowViewModel viewModel) { viewModel.LoadBasket(BasketItems); } basketWindow.Owner = System.Windows.Application.Current.MainWindow; basketWindow.ShowDialog(); if (basketWindow.Tag is System.Collections.Generic.List <Models.BasketItem> lst) { BasketItems.Clear(); BasketItems.AddRange(lst); ItemsBasket_CollectionChanged(); } }
public void DeleteItem() { Console.Clear(); Console.WriteLine("BASKET VIEW"); ShowBasket(); Console.WriteLine(); Console.WriteLine("Please provide the item number for deletion"); Console.WriteLine($"To delete all items, write {BasketItems.Count() + 1}"); int itemToDelete = GeneralStaticClass.ReadIntNumber(); while (BasketItems.Count() + 1 < itemToDelete || itemToDelete < 0) { Console.WriteLine("Invalid choice"); itemToDelete = GeneralStaticClass.ReadIntNumber(); } if (itemToDelete == BasketItems.Count() + 1) { BasketItems.Clear(); } else { BasketItems.RemoveAt(itemToDelete - 1); } }
public void ClearBasket() { BasketItems.Clear(); UpdateDiscount(); UpdateTotalPrice(); }
public void LoadBasket(int userid) { BasketItems.Clear(); string page; System.Threading.Thread.Sleep(1000); do { page = helper.GetPageGoods("http://" + helper.loginpage.tbxServer.Text + "/wpbuyings/"); System.Threading.Thread.Sleep(500); } while (page.Length < 10); page = page.Replace("<HEAD>", "\\").Replace("</HEAD>", "\\"). Replace("<BODY>", "\\").Replace("</BODY>", "\\"). Replace("<HTML>", "\\").Replace("</HTML>", "\\"). Replace("<BR>", "\\"); List <BuyingInfo> infos = new List <BuyingInfo>(); string[] lines = page.Split(new char[] { '\r', '\n', '\\' }, StringSplitOptions.RemoveEmptyEntries); foreach (var i in lines) { string[] line = i.Split(new char[] { '|' }, StringSplitOptions.None); BuyingInfo info; try { info = new BuyingInfo() { customerId = int.Parse(line[0]), productId = int.Parse(line[1]), amount = int.Parse(line[2]), }; if (info.customerId == userid) { infos.Add(info); } } catch (Exception) { } } foreach (var i in infos) { string productName = ""; foreach (var j in CompleteData) { if (i.productId.ToString() == j.LineFive) { productName = j.LineOneNoCat; break; } } string productPrice = ""; foreach (var j in CompleteData) { if (i.productId.ToString() == j.LineFive) { productPrice = j.LineTwo; break; } } string uri = ""; foreach (var j in CompleteData) { if (i.productId.ToString() == j.LineFive) { uri = j.ImgUrl; break; } } string lineInfo = i.amount + " шт, $" + productPrice; ItemViewModel item = new ItemViewModel() { LineOne = i.customerId.ToString(), LineTwo = i.productId.ToString(), LineThree = i.amount.ToString(), LineFour = productName, LineFive = productPrice, LineOneNoCat = "", LineCat = "", LineInfo = lineInfo, ImgUrl = uri, }; this.BasketItems.Add(item); } }
public void ClearBasket() { BasketItems.Clear(); }