/// <summary> /// Add a coffee product to the current customers order /// Multiplies given coffee product by amount purchased and passes to /// AddToTotal_ method /// </summary> /// <param name="coffeeProduct"></param> /// <param name="quantity"></param> public void AddProductToOrder(CoffeeTypes coffeeProduct, int quantity) { Coffee coffee = new Coffee(); double coffeePrice = 0.00; using var context = new joshfordproject0Context(s_dbContextOptions); IQueryable <Product> menu = context.Products .OrderBy(x => x.ProductName); foreach (Product products in menu) { if (coffeeProduct.ToString().Equals(products.ProductName)) { coffeePrice = products.ProductPrice; } } /* * coffeePrice = double.Parse(context.Products * .Select(x => x.ProductPrice) * .Where(x => x.Equals(custCoffee)) * .ToString()); */ customerCoffee.Add(coffeeProduct); AddToTotalOrderPrice(coffeePrice * quantity); }
/// <summary> /// Retrieves a given products price /// </summary> /// <param name="productToPrice"></param> public void GetProductPrice(Enum productToPrice) { using var context = new joshfordproject0Context(s_dbContextOptions); CoffeeTypes coffeeToPrice = (CoffeeTypes)productToPrice; var priceOfCoffee = context.Products .Select(x => x.ProductPrice) .Where(x => x.Equals(coffeeToPrice.ToString())); Console.WriteLine($"{coffeeToPrice}: $ {priceOfCoffee}"); }