Пример #1
0
        public IActionResult UpdateQuote(NewQuotesViewModel quote)
        {
            if (ModelState.IsValid)
            {
                double quotePrice = 200;

                double sqInSize = (Double)(quote.deskWidth * quote.deskLength);
                quotePrice += (sqInSize) / 1000;
                quotePrice += (Double)(quote.drawers * 50);

                double materialFee = 0;
                //material price comes from database
                string materialPrice = "SELECT price FROM Material WHERE description = '" + quote.material + "';";

                MySqlConnection myConnection = new MySqlConnection(connecitonString);
                MySqlCommand    myCommand    = new MySqlCommand(materialPrice, myConnection);
                myConnection.Open();
                MySqlDataReader myReader;
                myReader = myCommand.ExecuteReader();
                // Always call Read before accessing data.
                while (myReader.Read())
                {
                    materialFee = Double.Parse(myReader["price"].ToString());
                    quotePrice += materialFee;
                }
                myConnection.Close();

                //add in shipping cost
                double shippingFee = 0;
                switch (quote.shippingDays)
                {
                case 14:
                    //no additional cose
                    break;

                case 3:
                    if (sqInSize < 1000)
                    {
                        shippingFee = 60;
                        quotePrice += 60;
                    }
                    else if (sqInSize >= 1000 && sqInSize < 2000)
                    {
                        shippingFee = 70;
                        quotePrice += 70;
                    }
                    else
                    {
                        shippingFee = 80;
                        quotePrice += 80;
                    }
                    break;

                case 5:
                    if (sqInSize < 1000)
                    {
                        shippingFee = 40;
                        quotePrice += 40;
                    }
                    else if (sqInSize >= 1000 && sqInSize < 2000)
                    {
                        shippingFee = 50;
                        quotePrice += 50;
                    }
                    else
                    {
                        shippingFee = 60;
                        quotePrice += 60;
                    }
                    break;

                case 7:
                    if (sqInSize < 1000)
                    {
                        shippingFee = 30;
                        quotePrice += 30;
                    }
                    else if (sqInSize >= 1000 && sqInSize < 2000)
                    {
                        shippingFee = 30;
                        quotePrice += 35;
                    }
                    else
                    {
                        shippingFee = 40;
                        quotePrice += 40;
                    }
                    break;
                }

                quotePrice = Math.Round(quotePrice, 2);

                MySqlConnection mySqlConnection = new MySqlConnection(connecitonString);
                MySqlCommand    mySqlCommand    = new MySqlCommand("update_quote", myConnection);
                mySqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
                mySqlCommand.Parameters.AddWithValue("pv_quoteId", quote.Id);
                mySqlCommand.Parameters.AddWithValue("pv_firstName", quote.FirstName);
                mySqlCommand.Parameters.AddWithValue("pv_lastName", quote.LastName);
                mySqlCommand.Parameters.AddWithValue("pv_shippingDays", quote.shippingDays);
                mySqlCommand.Parameters.AddWithValue("pv_shippingPrice", shippingFee);
                mySqlCommand.Parameters.AddWithValue("pv_quoteAmount", quotePrice);
                mySqlCommand.Parameters.AddWithValue("pv_description", quote.material);  //mat des
                mySqlCommand.Parameters.AddWithValue("pv_deskWidth", quote.deskWidth);
                mySqlCommand.Parameters.AddWithValue("pv_deskLength", quote.deskLength);
                mySqlCommand.Parameters.AddWithValue("pv_drawers", quote.drawers);

                myConnection.Open();
                // MySqlDataReader myReader;
                myReader = mySqlCommand.ExecuteReader();
                myConnection.Close();

                return(RedirectToAction("Index"));
            }
            else
            {
                List <Material> myMaterials  = new List <Material>();
                string          sql          = "SELECT * FROM Material ORDER BY price;";
                MySqlConnection myConnection = new MySqlConnection(connecitonString);
                MySqlCommand    myCommand    = new MySqlCommand(sql, myConnection);
                myConnection.Open();
                MySqlDataReader myReader;
                myReader = myCommand.ExecuteReader();
                // Always call Read before accessing data.
                while (myReader.Read())
                {
                    myMaterials.Add(
                        new Material
                    {
                        Id          = Int32.Parse(myReader["materialID"].ToString()),
                        Description = myReader["description"].ToString(),
                        Price       = Double.Parse(myReader["price"].ToString())
                    });
                }


                //Quote quotes = new Quote
                //{
                //    Id = quote.Id,
                //    FirstName = quote.FirstName,
                //    LastName = quote.LastName,
                //    DeskWidth = (Double)quote.deskWidth,
                //    DeskLength = (Double)quote.deskLength,
                //    Drawers = quote.drawers,
                //    Material = quote.material,
                //    ShippingDays = quote.shippingDays


                //};

                //EditQuoteViewModel viewModel = new EditQuoteViewModel
                //{
                //    quote = quotes,
                //    material = myMaterials
                //};
                //return View(viewModel);

                return(View());
            }
        }
Пример #2
0
        public IActionResult NewQuote(NewQuotesViewModel newQuote)
        {
            if (ModelState.IsValid)
            {
                //calculate total quote price



                double quotePrice = 200;

                double sqInSize = (Double)(newQuote.deskWidth * newQuote.deskLength);
                quotePrice += (sqInSize) / 1000;
                quotePrice += (Double)(newQuote.drawers * 50);

                double materialFee = 0;
                //material price comes from database
                string materialPrice = "SELECT price FROM Material WHERE description = '" + newQuote.material + "';";

                MySqlConnection myConnection = new MySqlConnection(connecitonString);
                MySqlCommand    myCommand    = new MySqlCommand(materialPrice, myConnection);
                myConnection.Open();
                MySqlDataReader myReader;
                myReader = myCommand.ExecuteReader();
                // Always call Read before accessing data.
                while (myReader.Read())
                {
                    materialFee = Double.Parse(myReader["price"].ToString());
                    quotePrice += materialFee;
                }
                myConnection.Close();

                //add in shipping cost
                double shippingFee = 0;
                switch (newQuote.shippingDays)
                {
                case 14:
                    //no additional cose
                    break;

                case 3:
                    if (sqInSize < 1000)
                    {
                        shippingFee = 60;
                        quotePrice += 60;
                    }
                    else if (sqInSize >= 1000 && sqInSize < 2000)
                    {
                        shippingFee = 70;
                        quotePrice += 70;
                    }
                    else
                    {
                        shippingFee = 80;
                        quotePrice += 80;
                    }
                    break;

                case 5:
                    if (sqInSize < 1000)
                    {
                        shippingFee = 40;
                        quotePrice += 40;
                    }
                    else if (sqInSize >= 1000 && sqInSize < 2000)
                    {
                        shippingFee = 50;
                        quotePrice += 50;
                    }
                    else
                    {
                        shippingFee = 60;
                        quotePrice += 60;
                    }
                    break;

                case 7:
                    if (sqInSize < 1000)
                    {
                        shippingFee = 30;
                        quotePrice += 30;
                    }
                    else if (sqInSize >= 1000 && sqInSize < 2000)
                    {
                        shippingFee = 30;
                        quotePrice += 35;
                    }
                    else
                    {
                        shippingFee = 40;
                        quotePrice += 40;
                    }
                    break;
                }

                quotePrice = Math.Round(quotePrice, 2);


                myConnection = new MySqlConnection(connecitonString);
                MySqlCommand mySqlCommand = new MySqlCommand("insert_quote", myConnection);
                mySqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
                mySqlCommand.Parameters.AddWithValue("pv_firstName", newQuote.FirstName);
                mySqlCommand.Parameters.AddWithValue("pv_lastName", newQuote.LastName);
                mySqlCommand.Parameters.AddWithValue("pv_shippingDays", newQuote.shippingDays);
                mySqlCommand.Parameters.AddWithValue("pv_shippingPrice", shippingFee);
                mySqlCommand.Parameters.AddWithValue("pv_quoteAmount", quotePrice);
                mySqlCommand.Parameters.AddWithValue("pv_description", newQuote.material); //mat des
                mySqlCommand.Parameters.AddWithValue("pv_price", materialFee);             //mat cost
                mySqlCommand.Parameters.AddWithValue("pv_deskWidth", newQuote.deskWidth);
                mySqlCommand.Parameters.AddWithValue("pv_deskLength", newQuote.deskLength);
                mySqlCommand.Parameters.AddWithValue("pv_drawers", newQuote.drawers);

                myConnection.Open();
                //MySqlDataReader myReader;
                myReader = mySqlCommand.ExecuteReader();
                myConnection.Close();

                //string tmp = firstName + " " + lastName + " " + deskWidth + " " + deskLength + " " + material + " " + shippingDays;

                //return tmp;
                return(RedirectToAction("Index"));
            }
            else
            {
                List <Material> myMaterials  = new List <Material>();
                string          sql          = "SELECT * FROM Material ORDER BY price;";
                MySqlConnection myConnection = new MySqlConnection(connecitonString);
                MySqlCommand    myCommand    = new MySqlCommand(sql, myConnection);
                myConnection.Open();
                MySqlDataReader myReader;
                myReader = myCommand.ExecuteReader();
                // Always call Read before accessing data.
                while (myReader.Read())
                {
                    myMaterials.Add(
                        new Material
                    {
                        Id          = Int32.Parse(myReader["materialID"].ToString()),
                        Description = myReader["description"].ToString(),
                        Price       = Double.Parse(myReader["price"].ToString())
                    });
                }

                MaterialsViewModel vm = new MaterialsViewModel {
                    material = myMaterials
                };

                NewQuotesViewModelResponce vm2 = new NewQuotesViewModelResponce
                {
                    responceVM  = newQuote,
                    materialsVM = vm
                };

                return(View("NewQuoteWithErrors", vm2));
            }
        }