public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string name = req.Query["name"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); name = name ?? data?.name; if (String.IsNullOrEmpty(name)) { return(new BadRequestObjectResult("Please pass a name on the query string or in the request body")); } var bagel = new Bagel() { Id = Guid.NewGuid(), Store = name, Schmear = "Plain whipped cream cheese" }; await bagelContainer.CreateItemAsync(bagel, bagel.PartitionKey); return((ActionResult) new OkObjectResult($"Your bagel order, id {bagel.Id}, has been placed at the store named {bagel.Store} for a bagel with the following schmear: {bagel.Schmear}")); }
public async Task PublishCompleted(Bagel bagel) { var bagelCompleted = new BagelCompleted { Id = bagel.Id, OrderId = bagel.OrderId }; await _endpoint.Publish <IBagelCompletedEvent>(bagelCompleted); }
public Bagel CreateBagel(Boolean toasted) { var bagel = new Bagel() { Id = Guid.NewGuid().ToString(), Toasted = toasted }; using (var dbConnection = GetConnection()) { using (var command = new SqlCommand(CREATE_BAGEL_SQL, dbConnection)) { command.Parameters.AddWithValue("@Id", bagel.Id); command.Parameters.AddWithValue("@Toasted", bagel.Toasted); #if DEBUG Debug.WriteLine("Skipping the invocation of the query, compiled with DEBUG"); #else dbConnection.Open(); command.ExecuteNonQuery(); dbConnection.Close(); #endif } } return(bagel); }
public void CategorysMarginCoefficient_Test() { // arrange double bun_margin_coefficient_expected = 1.1; double bread_margin_coefficient_expected = 1.2; double loaf_margin_coefficient_expected = 1.3; double bagel_margin_coefficient_expected = 1.4; double pita_margin_coefficient_expected = 1.5; double delta = 0.1; // act Products bread = new Bread(); Products bagel = new Bagel(); Products bun = new Bun(); Products pita = new Pita(); Products loaf = new Loaf(); // assert Assert.AreEqual(bun_margin_coefficient_expected, bun.MarginCoefficient, delta); Assert.AreEqual(bread_margin_coefficient_expected, bread.MarginCoefficient, delta); Assert.AreEqual(loaf_margin_coefficient_expected, loaf.MarginCoefficient, delta); Assert.AreEqual(bagel_margin_coefficient_expected, bagel.MarginCoefficient, delta); Assert.AreEqual(pita_margin_coefficient_expected, pita.MarginCoefficient, delta); }
public void GetBagel_CreatesAnInstanceOfBagel_Bagel() { Bagel newBagel = new Bagel(0, 0); Assert.AreEqual(typeof(Bagel), newBagel.GetType()); }
public void TestBagel() { Bagel bagel = BagelSolver.Bagel; Assert.AreEqual(4, bagel.Value); }
public async Task Complete(Bagel bagel) { bagel.IsComplete = true; await _publisher.PublishCompleted(bagel); }
private void btnEnter_Click(object sender, EventArgs e) { disableAll(); switch (selectedItem) { case 0: //Bagel //Validate Bagel Name input if (validateItemName(txtName.Text) == true) { double dblResult; //Validate Price per dozen input if (double.TryParse(txtPriceDoz.Text, out dblResult)) { int intResult; //Validate quantity input if (int.TryParse(txtNumber.Text, out intResult)) { Bagel b = new Bagel(txtName.Text, Int32.Parse((txtNumber.Text)), Double.Parse((txtPriceDoz.Text))); statusBar.Text = b.ToString(); checkout.enterItem(b); } else { MessageBox.Show("Please enter a valid quantity", "Invalid Quantity", MessageBoxButtons.OK, MessageBoxIcon.Error); enableBagel(); } } else { MessageBox.Show("Please enter a valid item price per dozen", "Invalid Price Per Dozen", MessageBoxButtons.OK, MessageBoxIcon.Error); enableBagel(); } } else { MessageBox.Show("Please enter a valid bagel name", "Invalid Bagel Name", MessageBoxButtons.OK, MessageBoxIcon.Error); enableBagel(); } break; case 1: //Sandwich //Validate Sandwich Name input if (validateItemName(txtName.Text) == true) { //Validate Topping Name input if (validateItemName(txtTopping.Text) == true) { double dblResult; //Validate Topping Cost input if (double.TryParse(txtToppingCost.Text, out dblResult)) { Sandwich s = new Sandwich(txtName.Text, txtTopping.Text, Double.Parse((txtToppingCost.Text))); statusBar.Text = s.ToString(); checkout.enterItem(s); } else { MessageBox.Show("Please enter a valid topping cost", "Invalid Topping Cost", MessageBoxButtons.OK, MessageBoxIcon.Error); enableSandwich(); } } else { MessageBox.Show("Please enter a valid topping name", "Invalid Topping Name", MessageBoxButtons.OK, MessageBoxIcon.Error); enableSandwich(); } } else { MessageBox.Show("Please enter a valid topping name", "Invalid Sandwich Name", MessageBoxButtons.OK, MessageBoxIcon.Error); enableSandwich(); } break; case 2: //Coffee //Validate Coffee Name input if (validateItemName(txtName.Text) == true) { double dblResult; //Validate Coffee Size input if (double.TryParse(txtSize.Text, out dblResult)) { //Validate Coffee Price Per Ounce input if (double.TryParse(txtPriceOz.Text, out dblResult)) { Coffee c = new Coffee(txtName.Text, Double.Parse((txtSize.Text)), Double.Parse((txtPriceOz.Text))); statusBar.Text = c.ToString(); checkout.enterItem(c); } else { MessageBox.Show("Please enter a valid cost per ounce", "Invalid Cost Per Ounce", MessageBoxButtons.OK, MessageBoxIcon.Error); enableCoffee(); } } else { MessageBox.Show("Please enter a valid coffee size", "Invalid Coffee Size", MessageBoxButtons.OK, MessageBoxIcon.Error); enableCoffee(); } } else { MessageBox.Show("Please enter a valid coffee name", "Invalid Coffee Name", MessageBoxButtons.OK, MessageBoxIcon.Error); enableCoffee(); } break; case 3: //Spread //Validate Spread Name input if (validateItemName(txtName.Text) == true) { double dblResult; //Validate Spread Cost input if (double.TryParse(txtSpreadCost.Text, out dblResult)) { Spread p = new Spread(txtName.Text, Double.Parse((txtSpreadCost.Text))); statusBar.Text = p.ToString(); checkout.enterItem(p); } else { MessageBox.Show("Please enter a valid spread cost", "Invalid Spread Cost", MessageBoxButtons.OK, MessageBoxIcon.Error); enableSpread(); } } else { MessageBox.Show("Please enter a valid spread name", "Invalid Spread Name", MessageBoxButtons.OK, MessageBoxIcon.Error); enableSpread(); } break; } }
/// <summary> /// Разобрать строку содержащую информацию о категории /// </summary> /// <param name="input_string">Строка с информацией о категории</param> /// <param name="is_ok">Ссылка на переменную, указывающую на успешный разбор строки</param> /// <returns>Возвращает Products</returns> static Products ParseCategory(string input_string, ref bool is_ok) { //Формат //"category : CategoryName = Bread, ProductName = Волотовской, Quantity = 10;" Products product = new Bread(); int positions = input_string.LastIndexOf(':');//Определяем позицию после двоеточия string edit_string = input_string.Substring(positions + 1); //Разбиваем строку на массив строк string[] string_array = edit_string.Split(',', StringSplitOptions.RemoveEmptyEntries); //Определяем категорию к которой относится продукция foreach (var item in string_array) { //ищем if (item.IndexOf("CategoryName") == -1) //не существует, ищем дальше { continue; } //Нашли, получаем параметры string[] parameter; parameter = item.Split(new char[] { '=' }); //Разбиваем параметр на 2 части if (parameter.Length < 2) //Проверяем длину { is_ok = false; return(product); } string type = parameter[0]; string category = parameter[1]; //Проверяем, определена ли данная категория if (Products.CategoryIsExcist(category) == false) { is_ok = false; return(product); } else { switch (category) { case Products.CATEGORY_BREAD: product = new Bread(); break; case Products.CATEGORY_LOAF: product = new Loaf(); break; case Products.CATEGORY_BAGEL: product = new Bagel(); break; case Products.CATEGORY_BUN: product = new Bun(); break; case Products.CATEGORY_PITA: product = new Pita(); break; } break;//Выходим из цикла foreach } } //Получаем остальные параметры foreach (var item in string_array) { string[] parameter; parameter = item.Split(new char[] { '=' }); //Разбиваем параметр на 2 части if (parameter.Length < 2) //Проверяем длину { continue; } string type = parameter[0]; string str_value = parameter[1]; double value; switch (type) { case "ProductName": //Наименование продукции try { product.ProductName = str_value; } catch { product.ProductName = ""; } break; case "Quantity": //Количество double.TryParse(string.Join("", str_value.Where(c => char.IsDigit(c))), out value); try { str_value = str_value.Replace('.', ','); double.TryParse(str_value, out value); product.Quantity = value; } catch { product.Quantity = 0; } break; case "CategoryName": //Наименование категории try { product.CategoryName = str_value; } catch { product.CategoryName = ""; } break; } } is_ok = true; return(product); }
/*Event handler for Add to order button*/ private void buttonOrder_Click(object sender, EventArgs e) { decimal Price; if (textBoxQuantity.Text == "") { MessageBox.Show("Please enter the quantity"); } else { /*Taking input for quantity and storing it in a variable*/ Quantity = int.Parse(textBoxQuantity.Text); } try { /*Taking input for quantity and storing it in a variable*/ /*parsing the value of variable*/ BagelCost = decimal.Parse(pricing); /*storing the value of element at that index and storing it in variable*/ stock = BagelStock[BagelSizeIndex, BagelTypeIndex]; /*calculating the priceline for each items*/ priceLine = (Quantity * BagelCost); /*validating if inputed text is not a zero*/ if (Quantity != 0) { /*if stock is greater then quantity updating the stock array */ if (stock >= Quantity) { Price = (Quantity * BagelCost); TotalPrice = (Price) + (TotalPrice); labelTotalPrice.Text = TotalPrice.ToString("c2"); stock -= Quantity; BagelStock[listBoxSize.SelectedIndex, listBoxBagelType.SelectedIndex] = stock; /*creating an object of a class*/ Bagel info = new Bagel(); /*Accessing each value entered by the user*/ info.BagelName = listBoxBagelType.SelectedItem.ToString(); info.SizeofBagel = listBoxSize.SelectedItem.ToString(); info.QuantityofBagel = Quantity; info.priceofBagel = priceLine; info.TotalPriceofBagel = TotalPrice; info.BagelSizeIndex = listBoxSize.SelectedIndex; info.BagelTypeIndex = listBoxBagelType.SelectedIndex; /*Adding all the details which was accessed in array list*/ BagelDetails.Add(info); } else { MessageBox.Show("Remaining stock for selected Bagel is :" + stock); } } else { MessageBox.Show("Please enter the valid amount"); } /*cursor will be set to textbox to get input for quantity*/ textBoxQuantity.Focus(); buttonCompleteOrder.Enabled = true; } catch (Exception ex) { MessageBox.Show("Please select Bagel Type and Size"); } }
public void Put(int id, [FromBody] Bagel bagel) { bagel.BagelId = id; _db.Entry(bagel).State = EntityState.Modified; _db.SaveChanges(); }
public void Post([FromBody] Bagel bagel) { _db.Bagels.Add(bagel); _db.SaveChanges(); }
public void ApplyCreamCheese(Bagel bagel) => Console.WriteLine("Spreading cream cheese on the bagel.");
public static void Main() { Bread bread = new Bread(0, 0); Pastry pastry = new Pastry(0, 0); Bagel bagel = new Bagel(0, 0); Console.WriteLine("Bonjour! Welcome to Pierre's Bakery! What would you like today mon ami? Can I start you off with some bread? (Please enter yes or no!)"); string userInputFirst = Console.ReadLine().ToLower(); { if (userInputFirst == "yes") { Console.WriteLine("Here's what we've got for bread mo' friar: 1 loaf: $5, but if you buy 2, you get 1 free! Please enter the number you'd like!"); string userInputBread = Console.ReadLine(); bread.Quant += int.Parse(userInputBread); bread.Price = Bread.BreadPrice(bread.Quant); Console.WriteLine("Great! Your total for this delicious bread is $" + bread.Price); } else if (userInputFirst == "no") { ; } } Console.WriteLine("Wonderful! Would you like any Pastries today? (Yes/No)"); string userInputSecond = Console.ReadLine().ToLower(); { if (userInputSecond == "yes") { Console.WriteLine("Here are the details for pastries: 1 pastry: $2, but if one buys 3, you can get them for a total of 5$! This is to your liking, non? Go on! Enter a value!"); string userInputPastry = Console.ReadLine(); pastry.Quant += int.Parse(userInputPastry); pastry.Price = Pastry.PastryPrice(pastry.Quant); Console.WriteLine("Excellent! The total for these delicious pastries is $" + pastry.Price); } else if (userInputSecond == "no") { ; } } Console.WriteLine("Tres Bon! And finally would you like some bagels? Our newest special is 4 for $4! (Yes/No)"); string userInputThird = Console.ReadLine().ToLower(); { if (userInputThird == "yes") { Console.WriteLine("Excellent choice mon friar! How many would you like? Our newest deal is 4 for $4!"); string userInputBagel = Console.ReadLine(); bagel.Quant += int.Parse(userInputBagel); bagel.Price = Bagel.BagelPrice(bagel.Quant); Console.WriteLine("Ahhh magnifique! Your total for these fresh bagels will be $" + bagel.Price); } else if (userInputThird == "no") { ; } } Console.WriteLine("Anything else for you? If so type yes! If not, type 'done'!"); string userInputFinal = Console.ReadLine().ToLower(); if (userInputFinal == "yes") { Main(); } else if (userInputFinal == "done") { int total = bread.Price + pastry.Price; Console.WriteLine("Fantastique! Your total is: $" + total); Console.WriteLine("Thank you for visiting mon ami! Please come again, and aou revuare!"); } else { Console.WriteLine("Please enter a valid value!"); } }
public void SetObject_SetObject_Bagel() { int quant = 0; int price = 0; Bagel newBagel = new Bagel(quant, price); }
public void BagelPrice_ShowPriceFor4Bagels_4() { Assert.AreEqual(4, Bagel.BagelPrice(4)); }
public async Task <IActionResult> Complete(Guid id, [FromBody] Bagel bagel) { await _service.Complete(bagel); return(NoContent()); }