private void btnAddCoffee_Click(object sender, EventArgs e) { try { if (!string.IsNullOrWhiteSpace(txtSize.Text)) { Coffee newCup = new Coffee(); if (ValidateSizeText(txtSize.Text)) { newCup.Size = newCup.GetSize(txtSize.Text).Value; } if (_order.Coffees.Any()) { DialogResult dialogResult = MessageBox.Show("Would you like another coffee to your order? ", "Another Coffee?", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.No) { return; } } _order.Coffees.Add(newCup); AddToCurrentOrderTextbox($"{newCup.Size.ToString()} coffee started"); } if (!string.IsNullOrWhiteSpace(txtCream.Text)) { Cream cream = new Cream(); if (_order.Coffees.Any() && ValidateCondimentQuantity(txtCream.Text)) { cream.Quantity = cream.GetQuantity(txtCream.Text); _order.Coffees.Last().Cream = cream; AddToCurrentOrderTextbox($"{cream.Quantity} creamer(s) added"); } } if (!string.IsNullOrWhiteSpace(txtSugar.Text)) { Sugar sugar = new Sugar(); if (_order.Coffees.Any() && ValidateCondimentQuantity(txtSugar.Text)) { sugar.Quantity = sugar.GetQuantity(txtSugar.Text); _order.Coffees.Last().Sugar = sugar; AddToCurrentOrderTextbox($"{sugar.Quantity} sugar(s) added"); } } lblOrderTotal.Text = _order?.Total.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Application Error"); } ClearUI(); }
public decimal GetPrice(CoffeeSize size, Cream cream, Sugar sugar) { decimal price = 0m; price += GetBasePrice(size); if (cream != null) { price += cream.Price * cream.Quantity; } if (sugar != null) { price += sugar.Price * sugar.Quantity; } return(price); }