public ShoppingCartVM(ShopperHomeVM parent, Account acct) { Parent = parent; LoggedInUser = acct; AccountList = PostgreSQL.getAllAccounts(); AnimalCollection = PostgreSQL.getAllPets(); }
private void ReadInAllData() { AnimalCollection = PostgreSQL.getAllPets(); if (AnimalCollection == null) { AnimalCollection = new ObservableCollection <Animal>(); } }
public PlaceOrderVM(ShopperHomeVM parent, Account acct) { this.Parent = parent; this.LoggedInShopper = acct; AnimalCollection = PostgreSQL.getAllPets(); AccountList = PostgreSQL.getAllAccounts(); // Receipt Text string header = $"Receipt For {LoggedInShopper.FirstName} {LoggedInShopper.LastName}\n"; this.ReceiptText = header; UpdateQuantities(); }
private void AddToCartClicked(object obj) { ObservableCollection <Account> AccountList; AnimalCollection = PostgreSQL.getAllPets(); AccountList = PostgreSQL.getAllAccounts(); lb = obj as ListBox; Animal selectedAnimal = lb.SelectedItem as Animal; isCartEmpty = (Cart.Count == 0) ? true : false; if (Quantity == null) { MessageBox.Show("Please enter a valid quantity to add to your cart", "Invalid Quantity"); } else { int purchAmt = int.Parse(Quantity); if (selectedAnimal == null) { MessageBox.Show("Please select an animal before adding it to your cart", "Invalid Selection"); } else if (selectedAnimal.Price == "Pricele$$") { MessageBox.Show("This item cannot be purchased", "The Rock Says:"); } else { if (isCartEmpty) { if ((int.Parse(selectedAnimal.Quantity) - purchAmt) < 0) { MessageBox.Show($"Requested Quantity Exceeds the number of {selectedAnimal.Type}s in stock", "Invalid Quantity"); } else { selectedAnimal.Quantity = (int.Parse(selectedAnimal.Quantity) - purchAmt).ToString(); selectedAnimal.PurchasedAmount = purchAmt.ToString(); Cart.Add(selectedAnimal as object); TotalCost += double.Parse(selectedAnimal.Price.Replace("$", "")) * purchAmt; TotalItem += double.Parse(selectedAnimal.PurchasedAmount); CollectionViewSource.GetDefaultView(lb.ItemsSource).Refresh(); foreach (Account a in AccountList) { if (a.id == LoggedInUser.id) // CHANGE THIS TO ACCOUNT ID { if (LoggedInUser.CartContent == null) { LoggedInUser.CartContent = new ObservableCollection <Animal>(); } LoggedInUser.CartContent.Add(selectedAnimal); LoggedInUser.CartTotal = TotalCost.ToString(); LoggedInUser.CartItems = TotalItem.ToString(); } } CollectionViewSource.GetDefaultView(selectedAnimal.Quantity).Refresh(); PostgreSQL.addShopper(LoggedInUser, selectedAnimal); } } else { foreach (object o in Cart.ToList()) { Animal amal = o as Animal; if (amal.Type == selectedAnimal.Type) { MessageBox.Show("You already have that animal in your shopping cart. Click Review Order to change the quantity", "Oopsies"); } else { selectedAnimal.Quantity = (int.Parse(selectedAnimal.Quantity) - purchAmt).ToString(); selectedAnimal.PurchasedAmount = purchAmt.ToString(); Cart.Add(selectedAnimal as object); TotalCost += double.Parse(selectedAnimal.Price.Replace("$", "")) * purchAmt; TotalItem += double.Parse(selectedAnimal.PurchasedAmount); CollectionViewSource.GetDefaultView(lb.ItemsSource).Refresh(); foreach (Account a in AccountList) { if (a.id == LoggedInUser.id) { LoggedInUser.CartContent.Add(selectedAnimal); LoggedInUser.CartTotal = TotalCost.ToString(); LoggedInUser.CartItems = TotalItem.ToString(); } } CollectionViewSource.GetDefaultView(selectedAnimal.Quantity).Refresh(); PostgreSQL.addShopper(LoggedInUser, selectedAnimal); } } } } } }