示例#1
0
        public ActionResult AddProduct([Bind(Prefix = "item1")] Product item, FormCollection koleksiyon)
        {
            if (item != null || koleksiyon != null)
            {
                prep.Add(item);

                var kategoriler = koleksiyon["kategoriler"];
                #region Açıklama

                /*
                 * Koleksiyon tüm girdileri taşıdığı yani product nesnesinin de girdilerini taşıdığı ve product nesnesinin zorunlu alanlar olduğu için koleksiyon null gelmiyor. Koleksiyon null gelmese de kategoriler ve özellikler null gelebilir. Çünkü bu alanlar zorunlu alanlardan değil.
                 */
                #endregion

                if (kategoriler != null)
                {
                    foreach (char kategori in kategoriler)
                    {
                        if (kategori != 44)
                        {
                            ProductCategory pc = new ProductCategory();

                            pc.CategoryID = Convert.ToInt32(kategori.ToString());
                            pc.ProductID  = item.ID;
                            pcrep.Add(pc);
                        }
                    }
                }

                var ozellikler = koleksiyon["ozellikler"];

                if (ozellikler != null)
                {
                    foreach (char ozellik in ozellikler)
                    {
                        if (ozellik != 44)
                        {
                            ProductFeature pf = new ProductFeature();

                            pf.FeatureID = Convert.ToInt32(ozellik.ToString());
                            pf.ProductID = item.ID;
                            pfrep.Add(pf);
                        }
                    }
                }
                return(RedirectToAction("Detail", new { id = item.ID }));   //Admin ürün ekledikten sonra özeliklere değer atayabilmesi için detail sayfasına ürünün id'si ile birlikte yönlendirildi
            }
            ViewBag.Hata = "Ürün ekleme sırasında hata oluştu.";
            return(View());
        }
        public async Task <int> Add(string productCategoryTitle)
        {
            await ThrowExceptionIfTitleIsDuplicate(productCategoryTitle);

            var productCategory = new ProductCategory
            {
                Title = productCategoryTitle
            };

            _repository.Add(productCategory);
            await _unitOfWork.CompleteAsync();

            return(productCategory.Id);
        }
示例#3
0
        public void CreateValidProductCategoryRepositoryTest()
        {
            var pc1 = new ProductCategory()
            {
                ProductCategoryId = 1, Name = "Testing category"
            };
            var pc2 = new ProductCategory()
            {
                ProductCategoryId = 2, Name = "category"
            };
            var pc3 = new ProductCategory()
            {
                ProductCategoryId = 3, Name = "Testing"
            };

            // Run the test against one instance of the context
            using (var context = new GamersUnitedContext(GetOption(System.Reflection.MethodBase.GetCurrentMethod().Name)))
            {
                context.Database.EnsureDeleted();

                var repo = new ProductCategoryRepository(context);

                var npc1 = repo.Add(pc1);
                Assert.Equal(1, context.ProductCategory.Count());

                var npc2 = repo.Add(pc2);
                Assert.Equal(2, context.ProductCategory.Count());

                var npc3 = repo.Add(pc3);
                Assert.Equal(3, context.ProductCategory.Count());

                Assert.Equal(pc1.Name, npc1.Name);
                Assert.Equal(pc2.Name, npc2.Name);
                Assert.Equal(pc3.Name, npc3.Name);
            }
        }
示例#4
0
        public void CountOneProductCategoryRepositoryTest()
        {
            var pc = new ProductCategory()
            {
                Name = ""
            };

            using (var context = new GamersUnitedContext(GetOption(System.Reflection.MethodBase.GetCurrentMethod().Name)))
            {
                context.Database.EnsureDeleted();

                var repo = new ProductCategoryRepository(context);
                repo.Add(pc);
                Assert.Equal(1, repo.Count());
            }
        }
示例#5
0
        public void CreateInvalidProductCategoryRepositoryTestExpectArgumentNullException()
        {
            var pc = new ProductCategory()
            {
                ProductCategoryId = 1
            };

            using (var context = new GamersUnitedContext(GetOption(System.Reflection.MethodBase.GetCurrentMethod().Name)))
            {
                context.Database.EnsureDeleted();

                var repo = new ProductCategoryRepository(context);
                Assert.Throws <ArgumentNullException>(() =>
                {
                    repo.Add(pc);
                });
            }
        }
示例#6
0
        public void CreateValidProductCategoryRepositoryTestAutoincrement()
        {
            var pc = new ProductCategory()
            {
                ProductCategoryId = 9999, Name = ""
            };

            // Run the test against one instance of the context
            using (var context = new GamersUnitedContext(GetOption(System.Reflection.MethodBase.GetCurrentMethod().Name)))
            {
                context.Database.EnsureDeleted();

                var repo = new ProductCategoryRepository(context);
                var npc  = repo.Add(pc);

                Assert.NotEqual(pc.ProductCategoryId, npc.ProductCategoryId);
            }
        }
示例#7
0
        public void GetAllProductCategoryRepositoryTest()
        {
            var pcl = new List <ProductCategory> {
                new ProductCategory()
                {
                    Name = "1"
                },
                new ProductCategory()
                {
                    Name = "2"
                },
                new ProductCategory()
                {
                    Name = "3"
                },
                new ProductCategory()
                {
                    Name = "4"
                },
                new ProductCategory()
                {
                    Name = "5"
                }
            };

            using (var context = new GamersUnitedContext(GetOption(System.Reflection.MethodBase.GetCurrentMethod().Name)))
            {
                context.Database.EnsureDeleted();

                var repo = new ProductCategoryRepository(context);
                for (int i = 0; i < pcl.Count; i++)
                {
                    repo.Add(pcl[i]);
                }

                var npcl = repo.GetAll();
                for (int i = 0; i < pcl.Count; i++)
                {
                    Assert.Equal(pcl[i].Name, npcl[i].Name);
                }

                Assert.Equal(5, context.ProductCategory.Count());
            }
        }
示例#8
0
        public void GetInvalidIdProductCategoryRepositoryTest()
        {
            var pc = new ProductCategory()
            {
                Name = "test"
            };

            using (var context = new GamersUnitedContext(GetOption(System.Reflection.MethodBase.GetCurrentMethod().Name)))
            {
                context.Database.EnsureDeleted();

                var repo = new ProductCategoryRepository(context);
                var npc  = repo.Add(pc);

                Assert.Throws <ArgumentOutOfRangeException>(() => {
                    var get = repo.GetById(context.ProductCategory.Count());
                });
            }
        }
示例#9
0
        public void GetValidIdProductCategoryRepositoryTest()
        {
            var pc = new ProductCategory()
            {
                Name = "test"
            };

            using (var context = new GamersUnitedContext(GetOption(System.Reflection.MethodBase.GetCurrentMethod().Name)))
            {
                context.Database.EnsureDeleted();

                var repo = new ProductCategoryRepository(context);
                var npc  = repo.Add(pc);

                var get = repo.GetById(npc.ProductCategoryId);

                Assert.Equal(npc.ProductCategoryId, get.ProductCategoryId);
                Assert.Equal(pc.Name, get.Name);
            }
        }
        private void BtnSave_Click(object sender, EventArgs e)
        {
            TxtCode_Validated(this, null);
            TxtName_Validated(this, null);
            if (!string.IsNullOrEmpty(categoryErrors.GetError(txtCode)) ||
                !string.IsNullOrEmpty(categoryErrors.GetError(txtName)))
            {
                return;
            }

            bool            success;
            bool            isAdding = false;
            ProductCategory category = GetCurrent();

            if (category.Id == 0)
            {
                isAdding = true;
                success  = _repository.Add(AppConfig.CurrentCompany.Id, category) > 0;
            }
            else
            {
                success = _repository.Update(category.Id, category);
            }

            if (success)
            {
                categoriesBindingSource.EndEdit();

                tssLabel.Text         = "Saved successfully!";
                grpCategories.Enabled = true;
                if (isAdding)
                {
                    btnAdd.PerformClick();
                }
            }
            else
            {
                tssLabel.Text = "Error: Error occured while saving.";
            }
            //}
        }
示例#11
0
 public bool Add(ProductCategory productCategory)
 {
     return(_repository.Add(productCategory));
 }
示例#12
0
        private void CopyStoreData(int copyStoreId, int newStoreId)
        {
            StoreDbContext.Configuration.ProxyCreationEnabled = false;


            try
            {
                var items = NavigationRepository.GetNavigationsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    NavigationRepository.Add(s);
                }
                NavigationRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            try
            {
                var items = LocationRepository.GetLocationsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    LocationRepository.Add(s);
                }
                LocationRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            try
            {
                var items = EmailListRepository.GetStoreEmailList(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    EmailListRepository.Add(s);
                }
                EmailListRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            try
            {
                var items = BrandRepository.GetBrandsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    BrandRepository.Add(s);
                }
                BrandRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            try
            {
                var items = ContactRepository.GetContactsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    ContactRepository.Add(s);
                }
                ContactRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            int productCategoryId = 0;

            try
            {
                var items = ProductCategoryRepository.GetProductCategoriesByStoreId(copyStoreId);
                foreach (var productCategory in items)
                {
                    var s = GeneralHelper.DataContractSerialization(productCategory);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    ProductCategoryRepository.Add(s);
                    ProductCategoryRepository.Save();

                    productCategoryId = s.Id;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "ProductCategoryRepository:CopyStore");
            }

            int blogCategoryId = 0;
            int newsCategoryId = 0;

            try
            {
                var items = CategoryRepository.GetCategoriesByStoreId(copyStoreId, StoreConstants.BlogsType);
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    CategoryRepository.Add(s);
                    CategoryRepository.Save();

                    blogCategoryId = s.Id;
                }

                items = CategoryRepository.GetCategoriesByStoreId(copyStoreId, StoreConstants.NewsType);
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    CategoryRepository.Add(s);
                    CategoryRepository.Save();

                    newsCategoryId = s.Id;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }


            try
            {
                var items = ProductRepository.GetProductsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id = 0;
                    s.ProductCategoryId = productCategoryId;
                    s.StoreId           = newStoreId;
                    ProductRepository.Add(s);
                    ProductRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }

            try
            {
                var items = ContentRepository.GetContentsByStoreId(copyStoreId, "", StoreConstants.BlogsType);
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id         = 0;
                    s.StoreId    = newStoreId;
                    s.CategoryId = blogCategoryId;
                    ContentRepository.Add(s);
                    ContentRepository.Save();
                }

                items = ContentRepository.GetContentsByStoreId(copyStoreId, "", StoreConstants.NewsType);
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id         = 0;
                    s.StoreId    = newStoreId;
                    s.CategoryId = newsCategoryId;
                    ContentRepository.Add(s);
                    ContentRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }

            try
            {
                var items = LabelRepository.GetLabelsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    LabelRepository.Add(s);
                    LabelRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }

            try
            {
                var items = ActivityRepository.GetActivitiesByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    ActivityRepository.Add(s);
                    ActivityRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
        }
示例#13
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!");
            }
        }