Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            JSONReadWrite  readWrite  = new JSONReadWrite();
            string         jsonString = readWrite.Read("products.json", "Data");
            List <Product> products   = JsonConvert.DeserializeObject <List <Product> >(jsonString);

            var categories    = products.GroupBy(g => g.Category.CategoryId).Select(s => s.FirstOrDefault().Category).ToList();
            var suppliers     = products.GroupBy(g => g.Supplier.SupplierId).Select(s => s.FirstOrDefault().Supplier).ToList();
            var manufacturers = products.GroupBy(g => g.Manufacturer.ManufacturerId).Select(s => s.FirstOrDefault().Manufacturer).ToList();

            CategoryDropDownList.DataSource    = categories;
            CategoryDropDownList.DataTextField = "CategoryName";
            CategoryDropDownList.ID            = "CategoryId";
            CategoryDropDownList.DataBind();

            SupplierDropDownList.DataSource    = suppliers;
            SupplierDropDownList.DataTextField = "SupplierName";
            SupplierDropDownList.ID            = "SupplierId";
            SupplierDropDownList.DataBind();

            ManufacturerDropDownList.DataSource    = manufacturers;
            ManufacturerDropDownList.DataTextField = "ManufacturerName";
            ManufacturerDropDownList.ID            = "ManufacturerId";
            ManufacturerDropDownList.DataBind();
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = int.TryParse(Request.QueryString["Id"], out int result) ? result : 0;

                using (ProductContext context = new ProductContext())
                {
                    Product product = context.Products.Where(w => w.ProductId == id).FirstOrDefault();

                    if (product == null)
                    {
                        Response.Redirect("/Views/Products/ProductsPage.aspx");
                    }

                    ProductIdField.Value = product.ProductId.ToString();
                    ProductIdField.DataBind();
                    ProductNameTextBox.Text = product.Title;
                    ProductNameTextBox.DataBind();
                    ProductDescriptionTextBox.Text = product.Description;
                    ProductDescriptionTextBox.DataBind();
                    PriceTextBox.Text = product.Price.ToString();
                    PriceTextBox.DataBind();

                    var categories    = context.Categories.ToList();
                    var suppliers     = context.Suppliers.ToList();
                    var manufacturers = context.Manufacturers.ToList();

                    CategoryDropDownList.DataSource    = categories;
                    CategoryDropDownList.SelectedValue = categories.Where(w => w.CategoryId == product.CategoryId).Select(s => s.CategoryName).FirstOrDefault();
                    CategoryDropDownList.DataTextField = "CategoryName";
                    CategoryDropDownList.DataBind();

                    SupplierDropDownList.Items.Add(" ");
                    SupplierDropDownList.DataSource    = suppliers;
                    SupplierDropDownList.SelectedValue = suppliers.Where(w => w.SupplierId == product.SupplierId).Select(s => s.SupplierName).FirstOrDefault();
                    SupplierDropDownList.DataTextField = "SupplierName";
                    SupplierDropDownList.DataBind();

                    ManufacturerDropDownList.DataSource    = manufacturers;
                    ManufacturerDropDownList.SelectedValue = manufacturers.Where(w => w.ManufacturerId == product.ManufacturerId).Select(s => s.ManufacturerName).FirstOrDefault();
                    ManufacturerDropDownList.DataTextField = "ManufacturerName";
                    ManufacturerDropDownList.DataBind();
                }
            }
        }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = int.TryParse(Request.QueryString["Id"], out int result) ? result : 0;

                JSONReadWrite  readWrite  = new JSONReadWrite();
                string         jsonString = readWrite.Read("products.json", "Data");
                List <Product> products   = JsonConvert.DeserializeObject <List <Product> >(jsonString);

                Product product = products.Where(p => p.ProductId == id).FirstOrDefault();

                if (product == null)
                {
                    Response.Redirect("/Views/Products/ProductsPage.aspx");
                }

                ProductIdField.Value           = product.ProductId.ToString();
                ProductNameTextBox.Text        = product.Title;
                ProductDescriptionTextBox.Text = product.Description;
                PriceTextBox.Text = product.Price.ToString();

                var categories    = products.GroupBy(g => g.Category.CategoryId).Select(s => s.FirstOrDefault().Category).ToList();
                var suppliers     = products.GroupBy(g => g.Supplier.SupplierId).Select(s => s.FirstOrDefault().Supplier).ToList();
                var manufacturers = products.GroupBy(g => g.Manufacturer.ManufacturerId).Select(s => s.FirstOrDefault().Manufacturer).ToList();

                CategoryDropDownList.DataSource    = categories;
                CategoryDropDownList.SelectedValue = product.Category.CategoryName;
                CategoryDropDownList.DataTextField = "CategoryName";
                CategoryDropDownList.DataBind();

                SupplierDropDownList.Items.Add(" ");
                SupplierDropDownList.DataSource    = suppliers;
                SupplierDropDownList.SelectedValue = product.Supplier.SupplierName;
                SupplierDropDownList.DataTextField = "SupplierName";
                SupplierDropDownList.DataBind();

                ManufacturerDropDownList.DataSource    = manufacturers;
                ManufacturerDropDownList.SelectedValue = product.Manufacturer.ManufacturerName;
                ManufacturerDropDownList.DataTextField = "ManufacturerName";
                ManufacturerDropDownList.DataBind();
            }
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (ProductContext context = new ProductContext())
            {
                var categories    = context.Categories.ToList();
                var suppliers     = context.Suppliers.ToList();
                var manufacturers = context.Manufacturers.ToList();

                CategoryDropDownList.DataSource    = categories;
                CategoryDropDownList.DataTextField = "CategoryName";
                CategoryDropDownList.ID            = "CategoryId";
                CategoryDropDownList.DataBind();

                SupplierDropDownList.DataSource    = suppliers;
                SupplierDropDownList.DataTextField = "SupplierName";
                SupplierDropDownList.ID            = "SupplierId";
                SupplierDropDownList.DataBind();

                ManufacturerDropDownList.DataSource    = manufacturers;
                ManufacturerDropDownList.DataTextField = "ManufacturerName";
                ManufacturerDropDownList.ID            = "ManufacturerId";
                ManufacturerDropDownList.DataBind();
            }
        }