public HomeController()
        {
            Console.WriteLine("Initial context");
            //AdRepo = new AdRepo(new AzureDbContext());
            AzureDbContext context = new AzureDbContext();

            CategoryRepo = new CategoryRepo(context);
            

        }
        private void GetCategoryTreeView()
        {
            tvCategory.Nodes.Clear();
            var categories = new CategoryRepo().GetAll(x => x.SupCategoryId == null).OrderBy(x => x.Name).ToList();

            foreach (var category in categories)
            {
                TreeNode node = new TreeNode(category.Name)
                {
                    Tag = category.Id
                };
                tvCategory.Nodes.Add(node);
                if (category.Categories.Count > 0)
                {
                    SetSubNodes(node, category.Categories.OrderBy(x => x.Name).ToList());
                }
            }
            tvCategory.ExpandAll();
        }
        public ActionResult Update(int id = 0)
        {
            ViewBag.CategoryList = GetCategorySelectList();
            var data = new CategoryRepo().GetById(id);

            if (data == null)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Kategori Bulunamadı",
                    ActionName     = "Add",
                    ControllerName = "Category",
                    ErrorCode      = 404
                };
                return(RedirectToAction("Error", "Home"));
            }

            return(View(data));
        }
示例#4
0
        public IHttpActionResult GetAllCategory()
        {
            string error = "";
            List <CategoryModel> catm = CategoryRepo.GetAllCategory(out error);

            // if the erorr is not blank or the category list is null
            if (error != "" || catm == null)
            {
                // if the error is 404
                if (error == ConError.Status.NOTFOUND)
                {
                    return(Content(HttpStatusCode.NotFound, "Category Is Not Found"));
                }
                // if the error is other one
                return(Content(HttpStatusCode.BadRequest, error));
            }
            // if there is no error
            return(Ok(catm));
        }
示例#5
0
        private int?categoryId; //nullable yapıyorum cünkü kontrol edicem seçilipsecilmediğini.
        //treenode dan secim yapışdıktan sonra.
        private void tvCategory_AfterSelect(object sender, TreeViewEventArgs e)
        {
            categoryId = (int)e.Node.Tag;
            var category = new CategoryRepo().GetById(categoryId.Value);

            //seçili kategoriyi veri tabanında çekiyoruz.
            lstUrunler.DataSource = new ProductRepo()
                                    .GetAll(x => x.CategoryId == categoryId)
                                    .OrderBy(x => x.Name)               //secili categorynin products ı geldi.
                                    .Select(x => new ProductViewModel() //objemizi initializ edelim.//productviewmodel tipinde çağırdım.
            {
                Name       = x.Name,
                Id         = x.Id,
                CategoryId = x.CategoryId,
                IsActive   = x.IsActive,
                Price      = x.Price
            })
                                    .ToList();
        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            DialogResult d = MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButtons.YesNo);

            if (d == DialogResult.Yes)
            {
                var category = CategoryRepo.retrieve();
                if (this.cmbCategory != null)
                {
                    this.cmbCategory.Items.Clear();
                    foreach (var itm in category)
                    {
                        this.cmbCategory.Items.Add(itm.CategoryValue);
                    }
                }

                this.Hide();
            }
        }
示例#7
0
        public void RemoveDocument_ReturnNotFoundResult_WhenDocumentNotFound()
        {
            //Arrange
            var dbContext = new DocumentDbContext();

            dbContext.Categories = GetQueryableMockDbSetCategory();
            dbContext.Documents  = GetQueryableMockDbSetDocument();

            var categoryRepo = new CategoryRepo(string.Empty, dbContext);
            var documentRepo = new DocumentRepo(string.Empty, dbContext);
            var controller   = new DocumentController(categoryRepo, documentRepo);

            int testDocumentId = 3;

            //Act
            var result = controller.RemoveDocument(testDocumentId);

            //Assert
            Assert.IsType <NotFoundObjectResult>(result);
        }
示例#8
0
 private void btnEdit_Click(object sender, EventArgs e)
 {
     try
     {
         if (!this.UpdateFillEntity())
         {
             return;
         }
         if (CategoryRepo.Update(this.Category))
         {
             MessageBox.Show("Successfully updated  category");
             this.PopulateGridView();
             this.textBox1.Text = "";
         }
     }
     catch (Exception a)
     {
         MessageBox.Show("Error!" + a.Message);
     }
 }
        public void ShouldDeleteACategoryFromDifferentContext()
        {
            _repo.AddRange(new List <Category>
            {
                new Category {
                    CategoryName = "Foo"
                },
            });
            Assert.Equal(1, _repo.Count);
            Category category = _repo.GetFirst();

            using (CategoryRepo repo = new CategoryRepo())
            {
                int count = repo.Delete(category.Id, category.TimeStamp, false);
                Assert.Equal(0, count);
                count = repo.Context.SaveChanges();
                Assert.Equal(1, count);
                Assert.Equal(0, repo.Count);
            }
        }
        public void ShouldUpdateACategoryEntity()
        {
            var category = new Category {
                CategoryName = "Foo"
            };

            _repo.AddRange(new List <Category>
            {
                category,
            });
            category.CategoryName = "Bar";
            _repo.Update(category, false);
            var count = _repo.SaveChanges();

            Assert.Equal(1, count);
            var repo = new CategoryRepo();
            var cat  = repo.GetFirst();

            Assert.Equal(cat.CategoryName, category.CategoryName);
        }
        private void btnCategoryUpdate_Click(object sender, EventArgs e)
        {
            int index = 0;

            try
            {
                if (txtCategoryValue.Text != "")
                {
                    bool existing = CategoryRepo.checkIfCategoryExists(txtCategoryValue.Text);
                    if (existing)
                    {
                        MessageBox.Show("This category already exists, please give a new name");
                    }
                    else
                    {
                        index = lvCategory.SelectedIndices[0];
                        CategoryRepo.update(Guid.Parse(lvCategory.Items[index].SubItems[1].Text), txtCategoryValue.Text);
                        initCategory();
                        txtCategoryValue.Clear();
                        MessageBox.Show("Category has been updated.");
                        btnCategoryDelete.Enabled = false;
                        btnCategoryUpdate.Enabled = false;
                        btnCategoryAdd.Enabled    = true;
                        txtCategoryValue.Clear();
                    }
                }
                else
                {
                    MessageBox.Show("Update value can not be empty, please try again.");
                    btnCategoryDelete.Enabled = false;
                    btnCategoryUpdate.Enabled = false;
                    btnCategoryAdd.Enabled    = true;
                }
            }
            catch (Exception)
            {
                txtCategoryValue.Clear();
                index = 0;
                MessageBox.Show("Please select an item to update.");
            }
        }
        private void btnCategoryAdd_Click(object sender, EventArgs e)
        {
            bool varMi = false;

            try
            {
                CategoryRepo db       = new CategoryRepo();
                Category     category = new Category();


                foreach (var item in db.GetAll())
                {
                    if (item.CategoryName.ToLower() == txtCategory.Text.ToLower())
                    {
                        varMi = true;
                        break;
                    }
                }

                if (varMi == false)
                {
                    category.CategoryName = txtCategory.Text;
                    db.Insert(category);
                    MessageBox.Show($"{category.CategoryName} Kategorisi Eklendi");

                    System.Threading.Thread.Sleep(500);

                    ProductInsertingDialogForm ProductInsertingDialogForm = new ProductInsertingDialogForm();
                    ProductInsertingDialogForm.Show();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Bu isimde kategoriniz zaten mevcuttur.");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Return all todos that belong to the current user
        /// </summary>
        /// <returns></returns>
        public ActionResult Index(int?categoryID)
        {
            using (CategoryRepo catRepo = new CategoryRepo())
            {
                var categories = catRepo.SelectCatByUserID(User.Identity.GetUserId());


                if (categoryID.HasValue)
                {
                    ViewBag.categoryID = categoryID.Value;
                }
                else
                {
                    ViewBag.categoryID = categories.FirstOrDefault()?.Id;
                }


                // Should return view models to view. Don't have enough time
                return(View(categories));
            }
        }
示例#14
0
        public void Repository_UpdateWithChildren()
        {
            var      advertRepo   = new AdvertRepo(appContext);
            var      categoryRepo = new CategoryRepo(appContext);
            Category category     = categoryRepo.Find(5);
            Advert   advert       = advertRepo.Find(8);

            advert.Detail.Email  = "*****@*****.**";
            advert.Detail.Body   = "4x4 for sale";
            advert.SubmittedDate = new DateTime(2019, 6, 10);
            advert.Category      = category;

            advertRepo.Update(advert);
            appContext.SaveChanges();

            Assert.Equal(new DateTime(2019, 6, 10), appContext.Adverts.Find(8L).SubmittedDate);
            Assert.Equal("4x4 for sale", appContext.Adverts.Find(8L).Detail.Body);
            Assert.Equal("*****@*****.**", appContext.Adverts.Find(8L).Detail.Email);
            Assert.Equal(5, appContext.Adverts.Find(8L).Category.ID);
            Assert.Equal(2, appContext.Adverts.Find(8L).Category.ParentID);
        }
        public ActionResult AddCategory(string categoryName)
        {
            Category category = null;

            if (!String.IsNullOrEmpty(categoryName))
            {
                using (CategoryRepo catRepo = new CategoryRepo())
                {
                    category = catRepo.Insert(new Category()
                    {
                        CategoryName = categoryName,
                        UserId       = User.Identity.GetUserId()
                    });

                    catRepo.Save();
                }
            }

            // Redirect to the dashboard
            return(RedirectToAction("Index", new { categoryID = category?.Id }));
        }
示例#16
0
        public void AddDocument_ReturnNotFoundResult_WhenModelCategoryNotFound()
        {
            //Arrange
            var dbContext = new DocumentDbContext();

            dbContext.Categories = GetQueryableMockDbSetCategory();
            dbContext.Documents  = GetQueryableMockDbSetDocument();

            var categoryRepo = new CategoryRepo(string.Empty, dbContext);
            var documentRepo = new DocumentRepo(string.Empty, dbContext);
            var controller   = new DocumentController(categoryRepo, documentRepo);

            AddDocumentModel addDocumentModel = new AddDocumentModel {
                Title = "Đời sống con người", Description = "Nói về đời sống con người", CategoryId = 3, Cover = "", PublishYear = 2013
            };
            //Act
            var result = controller.AddDocument(addDocumentModel);

            //Assert
            Assert.IsType <NotFoundObjectResult>(result);
        }
示例#17
0
        private void Update_Click(object sender, EventArgs e)
        {
            try
            {
                if (_ct != null)
                {
                    using (var categoryRepo = new CategoryRepo())
                    {
                        var sonuc = categoryRepo.GetById(_ct.Id);
                        sonuc.KdvRate      = nuKDV.Value;
                        sonuc.CategoryName = txtCategory.Text;

                        categoryRepo.Update();
                        MessageBox.Show($"Secilen {_ct.Name} isimli kategori basariyla guncellendi");
                        _selectedCat = null;
                    }
                }
                else if (_pd != null)
                {
                    using (var productRepo = new ProductRepo())
                    {
                        var sonuc = productRepo.GetById(_pd.Id);
                        sonuc.ProductName = txtProduct.Text;
                        sonuc.Barcode     = txtBarcode.Text;
                        sonuc.SellPrice   = decimal.Parse(txtSellPrice.Text) + (decimal.Parse(txtSellPrice.Text) * (sonuc.Category.KdvRate));
                        productRepo.Update();
                        MessageBox.Show($"Secilen {_pd.ProductName} isimli ürün basariyla guncellendi");
                        _selectedProduct = null;
                    }
                }
            }
            catch (DbEntityValidationException ex)
            {
                new EntityHelper().FindError(ex);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#18
0
        public ActionResult EditCatDetails(int id, CategoryModel obj)
        {
            if (Session["UserId"] != null && Session["Accountid"] != null)
            {
                try
                {
                    CategoryRepo CatRepo = new CategoryRepo();

                    CatRepo.UpdateCategory(obj);

                    return(RedirectToAction("GetAllCategory"));
                }
                catch
                {
                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }
        }
 private void btnCategoryAdd_Click(object sender, EventArgs e)
 {
     if (txtCategoryValue.Text != "")
     {
         bool existing = CategoryRepo.checkIfCategoryExists(txtCategoryValue.Text);
         if (existing)
         {
             MessageBox.Show("This category already exists.");
         }
         else
         {
             CategoryRepo.create(txtCategoryValue.Text);
             MessageBox.Show("Category has been created.");
             initCategory();
             txtCategoryValue.Clear();
         }
     }
     else
     {
         MessageBox.Show("Category value can not be empty, please try again.");
     }
 }
示例#20
0
        public StockyDataService()
        {
            if (Helpers.DBIdentification)
            {
                Stocky.DataAcesse.DataBase.DBConnection.Set("LocalHost", "Stocky");
            }
            else
            {
                Stocky.DataAcesse.DataBase.DBConnection.Set(@"7TECH-SVR1", "Stocky_LIVE", "applogin", "728652Hotdog");
            }


            StockRepo       = new StockRepo();
            TransactionRepo = new TransactionRepo();
            AddressRepo     = new AddressRepo();
            CatergoryRepo   = new CategoryRepo();
            PersonRepo      = new PersonRepo();
            UserRepo        = new UserRepo();
            ValueRepo       = new ValueBandRepo();
            VendorRepo      = new VendorRepo();
            ValidationRepo  = new ValidationRepo();
        }
        public void UpdateCategory_ReturnNotFoundResult_WhenCategoryNotFound()
        {
            //Arrange
            var dbContext = new DocumentDbContext();

            dbContext.Categories = GetQueryableMockDbSetCategory();

            var categoryRepo = new CategoryRepo(string.Empty, dbContext);
            var controller   = new CategoryController(categoryRepo);

            UpdateCategoryModel updateCategoryModel = new UpdateCategoryModel()
            {
                Id    = 3,
                Title = "Khoa Học"
            };

            //Act
            var result = controller.UpdateCategory(updateCategoryModel);

            //Assert
            Assert.IsType <NotFoundObjectResult>(result);
        }
        public AccountController(
            UserManager <ApplicationUser> userManager,
            SignInManager <ApplicationUser> signInManager,
            IEmailSender emailSender,
            ILogger <AccountController> logger,
            IHttpContextAccessor httpContextAccessor,
            ApplicationDbContext context,
            IServiceProvider serviceProvider
            )

        {
            _userManager              = userManager;
            _signInManager            = signInManager;
            _emailSender              = emailSender;
            _logger                   = logger;
            this._httpContextAccessor = httpContextAccessor;
            this._context             = context;
            _serviceProvider          = serviceProvider;
            this.cr                   = new CategoryRepo(context);
            this.gr                   = new GoodsRepo(context);
            this.ar                   = new AccountRepo(context);
            this.ag                   = new AccountGoodsRepo(context);
        }
示例#23
0
 public ActionResult DeleteCat(int id)
 {
     if (Session["UserId"] != null && Session["Accountid"] != null)
     {
         try
         {
             CategoryRepo CatRepo = new CategoryRepo();
             if (CatRepo.DeleteCategory(id))
             {
                 ViewBag.AlertMsg = "Category details deleted successfully";
             }
             return(RedirectToAction("GetAllCategory"));
         }
         catch
         {
             return(View());
         }
     }
     else
     {
         return(RedirectToAction("Index", "Login"));
     }
 }
        protected List <SelectListItem> GetCategorySelectList()
        {
            var categories             = new CategoryRepo().GetAll(x => x.SupCategoryID == null).OrderBy(x => x.CategoryName);
            List <SelectListItem> list = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text  = "Üst kategorisi yok",
                    Value = "0"
                }
            };

            foreach (var cat in categories)
            {
                if (cat.Categories.Any())
                {
                    list.Add(new SelectListItem()
                    {
                        Text  = cat.CategoryName,
                        Value = cat.Id.ToString()
                    });
                    list.AddRange(GetSubCategories(cat.Categories.OrderBy(x => x.CategoryName).ToList()));
                }
                else
                {
                    list.Add(new SelectListItem()
                    {
                        Text  = cat.CategoryName,
                        Value = cat.Id.ToString()
                    });
                }
            }


            return(list);
        }
        public void ShouldUpdateACategoryEntity()
        {
            var category = new Category {
                CategoryName = "Foo"
            };

            _repo.AddRange(new List <Category>
            {
                category,
            });
            category.CategoryName = "Bar";
            _repo.Update(category, false);
            var count = _repo.SaveChanges();

            Assert.Equal(1, count);
            using (var context = new StoreContextFactory().CreateDbContext(null))
            {
                using (var repo = new CategoryRepo(context))
                {
                    var cat = repo.Find(category.Id);
                    Assert.Equal(cat.CategoryName, category.CategoryName);
                }
            }
        }
示例#26
0
        private void GetCategoryTreeView()
        {
            //burda kendini çağıran bir fonksiyon (recursive) yazmam lazım.
            //çünkü en üst menüden sonra ne kadar alt menü olcağı belli değil. her seferinde tekrar etmesi lazım.
            tvCategory.Nodes.Clear();
            var categories = new CategoryRepo().GetAll(x => x.SupCategoryId == null).OrderBy(x => x.Name).ToList();//en üst kategoriler gelsin.subcategoryıd leri null çünkü.

            foreach (var category in categories)
            {
                //root u oluşturan mekanizma.
                TreeNode node = new TreeNode(category.Name) //category.Name i nodeaekliyor.//içeceklerin ismini yazdı.
                {
                    Tag = category.Id                       //tag object tipinde oldupu için istefiğim değeri vereblirim.categoryıdyi gömüyorum
                };

                tvCategory.Nodes.Add(node);        //içeceklerin isminien dıstaki root a ekledi.
                if (category.Categories.Count > 0) //içeceklerin içinde 2 alt kategori var. true oldu içeri girdi.
                {
                    SetSubNodes(node, category.Categories.ToList());
                }
            }

            tvCategory.ExpandAll();//hepsini açıyo dallı görünüş.
        }
示例#27
0
        public ActionResult Index(CategoriesPostModel model)
        {
            EcommerceCMSEntities db = new EcommerceCMSEntities();

            //category source
            if (model.CategorySource == 1) //Websites
            {
                ViewBag.Websites = db.Websites.ToList();
            }
            else if (model.CategorySource == 2) //Suppliers
            {
                ViewBag.Suppliers = db.Suppliers.ToList();
            }

            //get categories
            if (model.WebsiteId > 0)
            {
                ViewBag.Categories = CategoryRepo.GetCategoriesFromWebsite(model.WebsiteId, model.ParentCategoryId);
            }
            else if (model.SupplierId > 0)
            {
                ViewBag.Categories = CategoryRepo.GetCategoriesFromSupplier(model.SupplierId);
            }

            //get products
            if (model.WebsiteId > 0 && model.CategoryId > 0)
            {
                ViewBag.Products = ProductRepo.GetProductsFromWebsiteCategory(model.WebsiteId, model.CategoryId);
            }
            else if (model.SupplierId > 0 && model.CategoryId > 0)
            {
                ViewBag.Products = ProductRepo.GetProductsFromSupplierCategory(model.SupplierId, model.CategoryId);
            }

            return(View());
        }
 public CategoryRepoUpdateTests()
 {
     _repo = new CategoryRepo();
     CleanDatabase();
 }
示例#29
0
 public ActionResult Delete(int id)
 {
     return PartialView("_Delete", CategoryRepo.GetCategory(id));
 }
示例#30
0
 public ActionResult Edit(int id)
 {
     return PartialView("_Edit", CategoryRepo.GetCategory(id));
 }
示例#31
0
 public ActionResult List()
 {
     return PartialView("_List", CategoryRepo.All());
 }