public IActionResult Add()
        {
            var vm = new SubcategoryFormModel
            {
                CategoryItems = _categoryRepository.FindAll().ToList()
            };

            return(View(vm));
        }
        public IActionResult Edit(SubcategoryFormModel model, IFormFile upload)
        {
            if (ModelState.IsValid)
            {
                var subcategory = _subcategoryRepository.GetSubcategory(model.Id);

                subcategory = SaveImage(upload, subcategory);
                _subcategoryRepository.Save(subcategory);

                return(RedirectToAction("Index", model.CategoryId));
            }

            model.CategoryItems = _categoryRepository.FindAll().ToList();
            return(View(model));
        }
        public IActionResult Add(SubcategoryFormModel model, IFormFile upload)
        {
            if (ModelState.IsValid)
            {
                var subcategory = new Subcategory()
                {
                    Category       = _categoryRepository.GetCategory(model.CategoryId),
                    CategoryId     = model.CategoryId,
                    CommonName     = model.CommonName,
                    Description    = model.Description,
                    ScientificName = model.ScientificName,
                    Slug           = model.Slug,
                };
                subcategory = SaveImage(upload, subcategory);

                _subcategoryRepository.Save(subcategory);

                return(RedirectToAction("Index", model.CategoryId));
            }
            return(View(model));
        }