public void CompletePurchase() { //Do transaction if (ProductsInBasket.Count > 0) { Transaction transaction = new Transaction(this.ProductsInBasket.ToList()); transaction.ExecuteTransaction(); //Move products to soldproducts List <SoldProduct> soldList = new List <SoldProduct>(); foreach (List <Product> x in this.ProductsInBasket.ToList()) { foreach (Product product in x) { SoldProduct soldproduct = new SoldProduct(product); soldproduct.transactionid = transaction.id; soldList.Add(soldproduct); } } AddSoldProductsToDatabase(soldList); RemoveProductsInBasketFromDatabase(ProductsInBasket.ToList()); notifyUserAboutCompletedPurchase(transaction.id, transaction.sum); } else { PopupService.PopupMessage("Der er ikke blevet tilføjet nogen produkter til kurven.", "Ingen produkter"); } }
public IHttpActionResult AddProductToBasket(Models.AddProductToBasket Ap) { try { Basket basket = db.Basket.Where(x => x.CustomerID == Ap.CustomerID && x.Active == true).FirstOrDefault(); if (basket == null) { Basket b = new Basket() { CustomerID = Ap.CustomerID, Active = true }; db.Basket.Add(b); } int basketID = basket.BasketID; Decimal TotalProductPrice = Convert.ToDecimal(db.Product.Where(x => x.ProductID == Ap.ProductID).FirstOrDefault().ProductPrice); ProductsInBasket addProductToBasket = new ProductsInBasket() { BasketID = Ap.BasketID, ProductID = Ap.ProductID, ProductPiece = Ap.ProductPiece, Price = TotalProductPrice }; db.ProductsInBasket.Add(addProductToBasket); db.SaveChanges(); return(Ok(true)); } catch (Exception e) { throw new Exception(e.ToString()); } }
public void AddSelectedToBasket() { if (Product != null && this.Quantity >= Convert.ToInt32(this.SelectedAmount) && (this.Quantity - Convert.ToInt32(this.SelectedAmount)) >= 0) { List <Product> productList = new List <Product>(); for (int i = 0; i < Convert.ToInt32(SelectedAmount); i++) { Product product = new Product(); product = this.Product.ShallowCopy(); productList.Add(product); this.TotalPrice = (Convert.ToDouble(this.TotalPrice) + product.price).ToString(); } ProductsInBasket.Add(productList); //this.TotalPrice = ProductsInBasket.Sum(x => x.price).ToString(); this.Quantity -= Convert.ToInt32(this.SelectedAmount); //Reset this textbox this.SelectedAmount = 1.ToString(); } else { PopupService.PopupMessage("Du forsøger at tilføje flere produkter end der findes.", "Produkter"); } }
public void SetBasketsCost() { decimal cost = 0; ProductsInBasket.ForEach(product => cost += product.Price * product.Count); BasketCost = cost; }
public void ClearAllProductsFromBasket() { ProductsInBasket.Clear(); this.TotalPrice = "0"; }