예제 #1
0
 public Pizza(DoughType doughType, bool isRedPepper, Size size, CheeseType cheeseType, List <string> vegetables)
 {
     this.doughType   = doughType;
     this.isRedPepper = isRedPepper;
     this.size        = size;
     this.cheeseType  = cheeseType;
     this.vegetables  = vegetables;
 }
예제 #2
0
        public ISet <DoughType> GetAllDoughTypesFromDb()
        {
            ISet <DoughType> doughTypes = new HashSet <DoughType>();
            int id = 0;

            while (true)
            {
                id++;
                DoughType doughType = this.GetDoughTypeFromDb(id);
                if (doughType.Id == 0)
                {
                    break;
                }
                doughTypes.Add(doughType);
            }

            return(doughTypes);
        }
예제 #3
0
        public ActionResult CreatePizzaConfirm()
        {
            var            requestForm = Request.Form;
            Regex          numberRegex = new Regex("^([a-zA-ZА-Яа-я]+)([0-9]+)$");
            Dough          dough       = new Dough();
            DoughType      doughType   = new DoughType();
            ISet <Topping> toppings    = new HashSet <Topping>();

            foreach (var key in requestForm.Keys)
            {
                string keyStr = (string)key;
                if (requestForm[keyStr].Contains("true"))
                {
                    string type         = numberRegex.Match(keyStr).Groups[1].ToString();
                    int    ingredientId = int.Parse(numberRegex.Match(keyStr).Groups[2].ToString());
                    switch (type)
                    {
                    case "dough":
                        dough = this.pizzaService.GetDoughFromDb(ingredientId);
                        break;

                    case "doughType":
                        doughType = this.pizzaService.GetDoughTypeFromDb(ingredientId);
                        break;

                    case "topping":
                        Topping topping = this.pizzaService.GetToppingFromDb(ingredientId);
                        toppings.Add(topping);
                        break;
                    }
                }
            }
            Pizza pizza = new Pizza();

            pizza.Name      = "CustomPizza";
            pizza.Dough     = dough;
            pizza.DoughType = doughType;
            pizza.Toppings  = toppings;
            this.pizzaService.SavePizzaToDb(pizza);
            return(RedirectToAction("AddCreatedPizza", "Order", new { id = this.pizzaService.GetLastId() }));
        }
예제 #4
0
        public DoughType GetDoughTypeFromDb(int id)
        {
            DoughType       doughType  = new DoughType();
            MySqlConnection connection = new MySqlConnection(DATABASE_CONNECTION_STRING);

            connection.Open();
            using (connection)
            {
                string query = "SELECT * FROM DoughTypes d WHERE d.Id = " + id + ";";

                MySqlCommand    sqlCommand = new MySqlCommand(query, connection);
                MySqlDataReader reader     = sqlCommand.ExecuteReader();
                while (reader.Read())
                {
                    doughType.Id       = (int)reader["Id"];
                    doughType.Name     = (string)reader["Name"];
                    doughType.Calories = (double)reader["Calories"];
                    doughType.Price    = (decimal)reader["Price"];
                }
            }

            return(doughType);
        }
예제 #5
0
 public Dough(DoughType doughType)
 {
     this.doughType = doughType;
 }
 public BuilderFunctional WithDough(DoughType dough)
 {
     Actions.Add(pizza => pizza.Dough = dough);
     return(this);
 }
 public T WithDough(DoughType dough)
 {
     pizza.Dough = dough;
     return((T)this);
 }