protected void btnSave_Click(object sender, EventArgs e) { try { string name = txtName.Text; string type = ddType.SelectedValue; double price = Convert.ToDouble(txtPrice.Text); string image = ddImage.SelectedValue; string description = txtDescription.Text; double weight; if (txtWeight.Text.Equals("")) { weight = 0; } else { weight = Convert.ToDouble(txtWeight.Text); } string dimensions = txtDimensions.Text; string ingredients = txtDimensions.Text; string holiday = ddHoliday.SelectedValue; Chocolate chocolate = new Chocolate(name, type, price, image, description, weight, dimensions, ingredients, holiday); ConnectionClass.AddChocolate(chocolate); lblResult.Text = "Upload succesful!"; ClearTextFields(); } catch (Exception) { lblResult.Text = "Upload failed!"; } }
private ArrayList getOrders() { ArrayList orderList = new ArrayList(); List <Tuple <int, int> > basketList = (List <Tuple <int, int> >)Session["ordersIds"]; List <Tuple <int, int> > newBasketList = new List <Tuple <int, int> >(); if (basketList.Count != 0) { foreach (Tuple <int, int> t in basketList) { TextBox textBox = pnlProducts.FindControl(Convert.ToString(t.Item1)) as TextBox; string txt = textBox.Text; if (txt != "") { if (Convert.ToInt32(txt) > 0) { newBasketList.Add(new Tuple <int, int>(t.Item1, Convert.ToInt32(txt))); } } } } foreach (Tuple <int, int> t in newBasketList) { int amountOfOrders = t.Item2; Chocolate chocolate = ConnectionClass.GetChocolateById(t.Item1); Order order = new Order(Session["login"].ToString(), chocolate.name, amountOfOrders, chocolate.price, DateTime.Now, false, txtAddress.Text); orderList.Add(order); } Session["ordersIds"] = newBasketList; return(orderList); }
public void PropertyUsageDescriptionTest() { //Arrange string info = "choklad"; string expectedNullUsageDescription = "Unknown usage"; string initialDefaultDescription = "Eat it and enjoy!"; int price = 20; var choc = new Chocolate(price, info, info); //Act string initialDescr = choc.UsageDescription; //what is set by constructor choc.UsageDescription = null; string nullDescr = choc.UsageDescription; choc.UsageDescription = ""; string emptyDescr = choc.UsageDescription; choc.UsageDescription = info; string changedDescr = choc.UsageDescription; string usageDescriptionFromUse = choc.Use(); //Assert Assert.Equal(initialDefaultDescription, initialDescr); Assert.Equal(expectedNullUsageDescription, nullDescr); Assert.Equal(expectedNullUsageDescription, emptyDescr); Assert.Equal(info, changedDescr); Assert.Equal(info, usageDescriptionFromUse); }
static void Main(string[] args) { //Основы кофе для декорации Bevegare bevegare = new Espresso(); Bevegare bevegare1 = new DarkRoast(); Bevegare bevegare2 = new Decaf(); Bevegare bevegare3 = new HouseBlind(); Console.WriteLine($"{bevegare.description} UAH {bevegare.cost()}"); Console.WriteLine($"{bevegare1.description} UAH {bevegare1.cost()}"); Console.WriteLine($"{bevegare2.description} UAH {bevegare2.cost()}"); Console.WriteLine($"{bevegare3.description} UAH {bevegare3.cost()}"); Console.WriteLine(new string('-', 50)); //Decorators coffee Chocolate chocolate = new Chocolate(); Milk milk = new Milk(); Mocha mocha = new Mocha(); Whip whip = new Whip(); //Decorator with coffee chocolate.SetComponent(bevegare); milk.SetComponent(chocolate); mocha.SetComponent(milk); whip.SetComponent(mocha); //Display in screen Console.WriteLine($"{chocolate.GetDescription()} UAH {chocolate.cost()}"); Console.WriteLine($"{milk.GetDescription()} UAH {milk.cost()}"); Console.WriteLine($"{mocha.GetDescription()} UAH {mocha.cost()}"); Console.WriteLine($"{whip.GetDescription()} UAH {whip.cost()}"); Console.ReadLine(); }
public string Post(string type, string manufacturer, double priceHRK) { Chocolate dummyChocolate = new Chocolate(type, manufacturer, priceHRK); chocolateList.Add(dummyChocolate); return("Bravo!"); }
public void PropertyNameTest() { //Arrange string name = "Marabou Nötchoklad"; string expectedNullName = "Unknown name"; int price = 20; //Act var choc = new Chocolate(price, name, ""); string initialName = choc.Name; choc.Name = null; string nullName = choc.Name; choc.Name = ""; string emptyName = choc.Name; choc.Name = name; string changedName = choc.Name; //Assert Assert.Equal(name, initialName); Assert.Equal(expectedNullName, nullName); Assert.Equal(expectedNullName, emptyName); Assert.Equal(changedName, name); }
void SpawnItem() { if (items.Count == locations.Count) { return; } int locationInd = Random.Range(0, locations.Count - 1); while (locationToObjectId.ContainsKey(locationInd)) { locationInd = (++locationInd) % locations.Count; } Vector3 pos = locations[locationInd]; GameObject item = Instantiate(chocolate, pos, Quaternion.Euler(270, 0, 0)) as GameObject; Chocolate chococompo = item.GetComponent <Chocolate>(); if (chococompo != null) { chococompo.itemSp = this; chococompo.locationId = locationInd; } items.Add(item); locationToObjectId.Add(locationInd, item.GetInstanceID()); lastSpawnTime = Time.time; }
void m_modelObj_ChocolateAdded(Chocolate newChocolate) { //perform your task what you want to do with newly added chocolate //if you want whole list of chocolates List <Chocolate> chocolateList = m_modelObj.ChocolateList; }
static void Main(string[] args) { Console.WriteLine("----義大利餐館菜單----"); Spaghetti normalSpaghetti = new NormalSpaghetti(); // 產生平民義大利麵 normalSpaghetti = new Chocolate(normalSpaghetti); // 加點火腿 normalSpaghetti = new Egg(normalSpaghetti); // 加點蛋 normalSpaghetti = new Cheese(normalSpaghetti); // 加點起司 normalSpaghetti = new Bacon(normalSpaghetti); // Console.WriteLine("名稱:{0} 價錢:{1} 材料:{2}", normalSpaghetti.GetName(), normalSpaghetti.GetPrice(), normalSpaghetti.GetDescription()); Spaghetti spaghettiBolognese = new SpaghettiBolognese(); // 產生茄汁肉醬義大利麵 spaghettiBolognese = new Strawberry(spaghettiBolognese); spaghettiBolognese = new Banana(spaghettiBolognese); spaghettiBolognese = new Sugar(spaghettiBolognese); Console.WriteLine("名稱:{0} 價錢:{1} 材料:{2}", spaghettiBolognese.GetName(), spaghettiBolognese.GetPrice(), spaghettiBolognese.GetDescription()); Console.ReadLine(); }
public void PropertyInformationTest() { //Arrange string info = "choklad 100 g"; string expectedNullInfo = "Information unknown"; int price = 20; //Act var choc = new Chocolate(price, "", info); string initialInfo = choc.Info; choc.Info = null; string nullName = choc.Info; choc.Info = ""; string emptyName = choc.Info; choc.Info = info; string changedName = choc.Info; //Assert Assert.Equal(info, initialInfo); Assert.Equal(expectedNullInfo, nullName); Assert.Equal(expectedNullInfo, emptyName); Assert.Equal(changedName, info); }
static void Main(string[] args) { IGift gift = new Gift("Gift 1", new List <ISweetness>()); Candy candy1 = new Candy("Сhupa Chups XXL 4D", 29, 0.65, 91, 370, TypeOfCandy.Lollipop, Stuffing.Without_Stuffing); Candy candy2 = new Candy("Аэрофлотские", 150, 1.95, 64.3, 483, TypeOfCandy.Chocolate, Stuffing.With_Waffle_Сrumb_Stuffing); Chocolate choco1 = new Chocolate("Спартак", 75, 1.45, 48, 540, TypeOfChocolate.Dark, DriedFruits.Contains_Nut, 59, VariantsOfChocolateProducts.Porous_Chocolate); Chocolate choco2 = new Chocolate("Любимая Алёнка", 200, 2.99, 51.5, 550, TypeOfChocolate.Milk, DriedFruits.Without_Dried_Fruits, 40, VariantsOfChocolateProducts.Chocolate); Halva halva1 = new Halva("Бобруйская", 60, 0.55, 45, 530, TypeOfHalva.Sunflower_Based, WithNuts.Without_Nuts); Halva halva2 = new Halva("Азовская", 250, 2.20, 29.1, 545, TypeOfHalva.Peanut_Butter_Based, WithNuts.Without_Nuts); Marshmallows Marshmallows1 = new Marshmallows("Удалить", 150, 115, 250, 450, TypeOfMarshmallows.White_Pink, DriedFruits.Contains_Peanut, Thickener.AgarAgar); Marshmallows Marshmallows2 = new Marshmallows("Первый Бобруйский", 250, 2.19, 81, 310, TypeOfMarshmallows.White_Pink, DriedFruits.Contains_Candied_Fruit, Thickener.AgarAgar); Marshmallows Marshmallows3 = new Marshmallows("Чаровей", 80, 0.89, 74, 340, TypeOfMarshmallows.Vanilla, DriedFruits.Without_Dried_Fruits, Thickener.Pectin); gift.AddSweet(candy1); gift.AddSweet(candy2); gift.AddSweet(choco1); gift.AddSweet(choco2); gift.AddSweet(halva1); gift.AddSweet(halva2); gift.AddSweet(Marshmallows1); gift.AddSweet(Marshmallows2); gift.AddSweet(Marshmallows3); gift.RemoveSweet(Marshmallows1); gift.ShowItems(); }
public void test_coffee() { { ICoffee coffee = new Espresso(); Chocolate decoratorChocolate = new Chocolate(coffee); decoratorChocolate.AddCondiment(); Assert.That(coffee.GetPrice() == 3.98); Milk decoratorMilk = new Milk(coffee); decoratorMilk.AddCondiment(); Assert.That(coffee.GetPrice() == 5.97); } { ICoffee coffee = new Espresso(); Chocolate decoratorChocolate = new Chocolate(coffee); decoratorChocolate.AddCondiment(); Milk decoratorMilk = new Milk(decoratorChocolate); decoratorMilk.AddCondiment(); Assert.That(coffee.GetPrice() == 5.97); } }
public IActionResult CreatePost(Chocolate choco) { if (GetCurrentUser() == null) { return(RedirectToAction("Login", "User")); } try { if (ModelState.IsValid) { if (choco.UserId == 0) { choco.UserId = GetCurrentUser().Id; } Db.Chocolates.Add(choco); Db.SaveChanges(); return(RedirectToAction("Index", "Home")); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View("Create", choco)); }
public JsonResult DrinkActions(string drink) { List <String> actions = null; switch (drink.ToLower()) { case "coffee": var coffee = new Coffee(); actions = coffee.Actions(); break; case "lemontea": var tea = new LemonTea(); actions = tea.Actions(); break; case "chocolate": var chocolate = new Chocolate(); actions = chocolate.Actions(); break; default: // empty list actions = new List <String>(); break; } return(new JsonResult(actions)); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); Chocolate.EnableChocolateTestAds(DO_ENABLE_TEST_ADS); Chocolate.Init(this, CHOCOLATE_API_KEY, chocolateAdRequest, this); /* admobBannerAd = FindViewById<AdView>(Resource.Id.adView); * var adRequest = new AdRequest.Builder().Build(); * admobBannerAd.LoadAd(adRequest); */ chocolateInviewAdContainer = FindViewById <ViewGroup>(Resource.Id.chocolateInviewAdContainer); loadInterstitialButton = FindViewById <Button>(Resource.Id.load_interstitial_button); loadInterstitialButton.SetOnClickListener(new OnClickListener(this, ADTYPE_INTERSTITIAL)); loadRewardedButton = FindViewById <Button>(Resource.Id.load_rewarded_button); loadRewardedButton.SetOnClickListener(new OnClickListener(this, ADTYPE_REWARDED)); loadInviewButton = FindViewById <Button>(Resource.Id.load_inview_button); loadInviewButton.SetOnClickListener(new OnClickListener(this, ADTYPE_INVIEW)); chocolateAdRequest = new LVDOAdRequest(this); chocolateRewardedAd = new LVDORewardedAd(this, CHOCOLATE_API_KEY, this); chocolateInterstitialAd = new LVDOInterstitialAd(this, CHOCOLATE_API_KEY, this); chocolateInviewAd = new LVDOBannerAd(this, LVDOAdSize.IabMrect, CHOCOLATE_API_KEY, this); }
public async Task <IActionResult> Edit(int id, [Bind("Id_Chocolate,Marca,Porcent_Cacau,Tipo,Data_Validade,Preco,Porcent_Desconto")] Chocolate chocolate) { if (id != chocolate.Id_Chocolate) { return(NotFound()); } if (ModelState.IsValid) { try { chocolate.Preco = chocolate.CalcularDesconto(chocolate.Preco, chocolate.Porcent_Desconto); _context.Update(chocolate); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ChocolateExists(chocolate.Id_Chocolate)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(chocolate)); }
public void PropertyPriceTest() { //Arrange string name = "Marabou Nötchoklad"; string info = "chokladkaka 100g"; int price = 20; var choc1 = new Chocolate(price, name, info); //Act int initialPrice = choc1.Price; //try to set it to a negative price int negativePrice = -100; choc1.Price = negativePrice; int expectedNegativePrice = 100; int receivedNegativePrice = choc1.Price; //try set price to 0 choc1.Price = 0; int zeroPrice = choc1.Price; //try normal update of price choc1.Price = price; int updatedPrice = choc1.Price; //Assert Assert.Equal(price, initialPrice); Assert.Equal(expectedNegativePrice, receivedNegativePrice); Assert.Equal(0, zeroPrice); Assert.Equal(price, updatedPrice); }
public void TestMethod1() { Ingredient chocolate = new Chocolate(); double expected = 15.0; double actual = chocolate.GetPrice(); Assert.AreEqual(expected, actual); }
public void AddChocolate(Chocolate chocolates) { using (AccountContext db = new AccountContext()) { db.Chocolate.Add(chocolates); db.SaveChanges(); } }
private void button1_Click(object sender, EventArgs e) { //adding new chocolate to list; Chocolate newChocolate = new Chocolate(comboBoxChocolateSelection.SelectedItem.ToString(), 12.5, true, 2); m_model.AddChocolateInList(newChocolate); this.Close(); }
public void UpdateChocolate(Chocolate chocolate) { using (AccountContext db = new AccountContext()) { db.Entry(chocolate).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
public void AddChocolateInList(Chocolate chocolate) { ChocolateList.Add(chocolate); if (ChocolateAdded != null) { ChocolateAdded(chocolate); } }
static void Main(string[] args) { ServiceReference.ServiceClient client = new ServiceReference.ServiceClient(); string line; Console.WriteLine("Insert an option\n1 - show available chocolates\n2 - insert new chocolate\nexit - finish program"); Console.Write(">"); while ((line = Console.ReadLine()) != null) { if (line == "1") { Chocolate[] all = client.GetChocolates(); for (int i = 0; i < all.Length; i++) { Console.WriteLine("id " + all[i].ChocId + ": " + all[i].ChocName + "(" + all[i].ChocType + ") - " + all[i].ChocQuant + " unit(s) - Price: EUR " + all[i].ChocPrice + ";, Cost: EUR " + all[i].ChocCost); } } else if (line == "2") { Chocolate newChoc = new Chocolate(); Console.Write("Name of the chocolate: "); newChoc.ChocName = Console.ReadLine().Split()[0]; Console.Write("Type: "); newChoc.ChocType = Console.ReadLine().Split()[0]; Console.Write("Insert number of units: "); newChoc.ChocQuant = Int32.Parse(Console.ReadLine().Split()[0]); Console.Write("Insert price and cost (separated by a space): "); string tmp = Console.ReadLine(); newChoc.ChocPrice = Int32.Parse(tmp.Split()[0]); newChoc.ChocCost = Int32.Parse(tmp.Split()[1]); if (client.newChocolate(newChoc.ChocName, newChoc.ChocType, newChoc.ChocQuant, newChoc.ChocPrice, newChoc.ChocCost)) { Console.WriteLine("Chocolate with name " + newChoc.ChocName + " was inserted successfully."); } else { Console.WriteLine("Unfortunately this chocolate could not be added."); } } else if (line == "exit") { Console.WriteLine("exiting the application..."); break; } else { Console.WriteLine("Enter a valid option."); } Console.WriteLine(); Console.WriteLine("Insert an option\n1 - show available chocolates\n2 - insert new chocolate\nexit - finish program"); Console.Write(">"); } }
public void TestMethod1() { Ingredient chocolate = new Chocolate(); String actual = "Chocolate"; String expected = chocolate.GetName(); Assert.AreEqual(expected, actual); }
public void DeleteChocolate(string Name) { using (AccountContext db = new AccountContext()) { Chocolate chocolate = db.Chocolate.Find(Name); db.Chocolate.Remove(chocolate); db.SaveChanges(); } }
public void ChocolateNameTest() { CoffeeMachine coffee_machine = new Chocolate(); string expected = "Шоколад"; string actual; actual = coffee_machine.Name; Assert.AreEqual(expected, actual); }
public void ChocolateCostTest() { CoffeeMachine coffee_machine = new Chocolate(); int expected = 20; int actual; actual = coffee_machine.GetCost(); Assert.AreEqual(expected, actual); }
private void loadProductButton_Click(object sender, EventArgs e) { //let the user pick the file to open ; OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Select a Product Inventory List"; ofd.Filter = "Product Inventory File|*.pil|Text Files|*.txt|All Files|*.*"; ofd.FilterIndex = 2; ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); DialogResult result = ofd.ShowDialog(); if (result != DialogResult.OK) { return; } // All inside a try catch // open a stream reader on productList on the desktop // foreach line in the file product call the constractor that takes a single string //and get a product object back . Add that object to my list and to the display close the file PRODUCT p = null; try { //string filepath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/" + "/productlist.txt"; StreamReader input = new StreamReader(ofd.FileName); while (!input.EndOfStream) { string productType = input.ReadLine(); switch (productType) { case "Computer": p = new Computer(input.ReadLine()); break; case "Chocolate": p = new Chocolate(input.ReadLine()); break; default: MessageBox.Show("Unkown Product"); p = null; break; } string lineFromFile = input.ReadLine(); //PRODUCT p = new PRODUCT(lineFromFile); if (p != null) { productInventory.Add(p); productListListbox.Items.Add(p.ToFormattedString()); } } input.Close(); } catch (Exception excp) { MessageBox.Show($"Error:File did not Load.{excp.Message}"); return; } MessageBox.Show($"Products have been save"); }
public void Run() { Icecream iceCream = new Chocolate(); iceCream = new Fudge(iceCream); iceCream = new Sprinkle(iceCream); Console.WriteLine("Cost of Icecream: " + iceCream.Cost().ToString()); Console.ReadKey(); }
public void cargarChocolate() { Chocolate ch1 = new Chocolate("Hot Chocolate", "Bomba", 60, 09); ListadeChocolate.Add(ch1); Chocolate ch2 = new Chocolate("Marshmellow", "Especial", 65, 10); ListadeChocolate.Add(ch2); }
public static void Eat(Chocolate self) { }
public static bool IsWhite(Chocolate self) { return self.Colour == "white"; }
public static bool IsMilk(Chocolate self) { return self.Colour == "milk"; }
public static bool IsDark(Chocolate self) { return self.Colour == "dark"; }