Ejemplo n.º 1
0
        // GET: ProductController/Create
        public ActionResult Create()
        {
            //passing all the product characteristics to view to create dropdown menus
            ProductCharacteristics productCharacteristics = new ProductCharacteristics();

            DisplayDbData.DisplayProductCharacteristics(productCharacteristics);
            ViewBag.ProductCharacteristics = productCharacteristics;
            return(View(new Product()));
        }
        //Method to retrieve an object of lists with the product characteristics
        public static void DisplayProductCharacteristics(ProductCharacteristics productCharacteristics)
        {
            using (SqlConnection sqlConnection = new SqlConnection(Config.ConnString))
            {
                sqlConnection.Open();

                using (SqlCommand cmd = new SqlCommand("SELECT * FROM P_Categories", sqlConnection))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            productCharacteristics.Category.Add(reader.GetValue(reader.GetOrdinal("Category")).ToString());
                        }
                    }
                }
                using (SqlCommand cmd = new SqlCommand("SELECT * FROM P_Conditions", sqlConnection))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            productCharacteristics.Condition.Add(reader.GetValue(reader.GetOrdinal("Condition")).ToString());
                        }
                    }
                }
                using (SqlCommand cmd = new SqlCommand("SELECT * FROM P_Platforms", sqlConnection))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            productCharacteristics.Platform.Add(reader.GetValue(reader.GetOrdinal("Platform")).ToString());
                        }
                    }
                }
                using (SqlCommand cmd = new SqlCommand("SELECT * FROM P_Types", sqlConnection))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            productCharacteristics.ProductType.Add(reader.GetValue(reader.GetOrdinal("ProductType")).ToString());
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        // GET: ProductController/Edit/
        public ActionResult Edit(int Id)
        {
            try
            {
                var product = DisplayDbData.GetProductById(new Product(), Id);
                ProductCharacteristics productCharacteristics = new ProductCharacteristics();
                DisplayDbData.DisplayProductCharacteristics(productCharacteristics);
                ViewBag.ProductCharacteristics = productCharacteristics;
                return(View(product));
            }
            catch (Exception)
            {
                ViewBag.Message = "Product not found";
                return(RedirectToAction(nameof(Index)));

                throw;
            }
        }