Exemplo n.º 1
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            Product product = new Product();

            product.ProductName = txtProductName.Text;
            product.Description = txtProductDescription.Text;
            productRepository.Add(product);

            foreach (CheckBox item in flpCategory.Controls)
            {
                if (item.Checked)
                {
                    ProductCategory productCategory = new ProductCategory();
                    productCategory.CategoryID = Convert.ToInt32(item.Tag);
                    productCategory.ProductID  = product.ID;
                    productCategoryRepository.Add(productCategory);
                }
            }
            UncheckAllItems(flpCategory);

            foreach (CheckBox item in flpAttribute.Controls)
            {
                if (item.Checked)
                {
                    ProductDetail productDetail = new ProductDetail();
                    productDetail.EntityAttributeID = Convert.ToInt32(item.Tag);
                    productDetail.ProductID         = product.ID;
                    productDetailRepository.Add(productDetail);
                }
            }
            UncheckAllItems(flpAttribute);

            ClearTextBoxes();
        }
Exemplo n.º 2
0
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            if (product != null)
            {
                productRepository.Update(product);

                //Daha önce kayıtlı olan, şu an uncheck olan categorileri, productcategory'den sil.
                foreach (CheckBox c in flpCategory.Controls)
                {
                    int ID = Convert.ToInt32(c.Tag);
                    if (productCategories.Contains(productCategoryRepository.FirstOrDefault(x => x.CategoryID == ID && x.ProductID == product.ID)))
                    {
                        if (!c.Checked)
                        {
                            productCategoryRepository.Delete(productCategoryRepository.FirstOrDefault(x => x.CategoryID == ID && x.ProductID == product.ID));
                        }
                    }
                }

                //Daha önce kayıtlı olan, şu an uncheck olan attributeleri, productdetail'den sil.
                foreach (CheckBox c in flpAttribute.Controls)
                {
                    int ID = Convert.ToInt32(c.Tag);
                    if (productDetails.Contains(productDetailRepository.FirstOrDefault(x => x.EntityAttributeID == ID && x.ProductID == product.ID)))
                    {
                        if (!c.Checked)
                        {
                            productDetailRepository.Delete(productDetailRepository.FirstOrDefault(x => x.EntityAttributeID == ID && x.ProductID == product.ID));
                        }
                    }
                }


                //Yeni seçilen attributeları, productDetail'e ekle.
                foreach (CheckBox c in flpAttribute.Controls)
                {
                    int ID = Convert.ToInt32(c.Tag);
                    if (!productDetails.Contains(productDetailRepository.FirstOrDefault(x => x.EntityAttributeID == ID && x.ProductID == product.ID)))
                    {
                        if (c.Checked)
                        {
                            ProductDetail productDetail = new ProductDetail();
                            productDetail.EntityAttributeID = Convert.ToInt32(c.Tag);
                            productDetail.ProductID         = product.ID;
                            productDetailRepository.Add(productDetail);
                        }
                    }
                }

                //Yeni seçilen kategorileri, productcategory'e ekle.
                foreach (CheckBox c in flpCategory.Controls)
                {
                    int ID = Convert.ToInt32(c.Tag);
                    if (!productCategories.Contains(productCategoryRepository.FirstOrDefault(x => x.CategoryID == ID && x.ProductID == product.ID)))
                    {
                        if (c.Checked)
                        {
                            ProductCategory productCategory = new ProductCategory();
                            productCategory.CategoryID = Convert.ToInt32(c.Tag);
                            productCategory.ProductID  = product.ID;
                            productCategoryRepository.Add(productCategory);
                        }
                    }
                }

                UncheckAllItems(flpAttribute);
                UncheckAllItems(flpCategory);

                ListBoxLoad();
            }
            else
            {
                MessageBox.Show("Ürün Seçiniz!");
            }
        }