public IActionResult EditCategory(int id)
        {
            var dbCategory = _dbContext.Categories.First(c => c.Id == id);
            var viewModel  = new AdminEditCategoryViewModel
            {
                Id          = dbCategory.Id,
                Name        = dbCategory.Name,
                Description = dbCategory.CategoryDescription,
            };

            return(View(viewModel));
        }
Example #2
0
        public ActionResult Edit(int id)
        {
            var category = this.categories
                           .GetCategoryById(id)
                           .FirstOrDefault();

            var editPostViewModel = new AdminEditCategoryViewModel
            {
                Name     = category.Name,
                IsHidden = category.IsHidden
            };

            return(View(editPostViewModel));
        }
        public IActionResult EditCategory(int categoryid)
        {
            var cat = _categoryService.GetSingle(c => c.CategoryId == categoryid);

            if (cat == null)
            {
                return(NotFound());
            }
            AdminEditCategoryViewModel vm = new AdminEditCategoryViewModel {
                CategoryId   = cat.CategoryId,
                CategoryName = cat.CategoryName
            };

            return(View(vm));
        }
        public async Task <IActionResult> EditCategory(AdminEditCategoryViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var cat = _categoryService.GetSingle(c => c.CategoryId == vm.CategoryId);

                cat.CategoryName = vm.CategoryName;

                await _categoryService.Update(cat);

                return(RedirectToAction("Index", "Admin"));
            }


            return(View(vm));
        }
Example #5
0
        public ActionResult Edit(int id, AdminEditCategoryViewModel viewModel)
        {
            if (viewModel != null && ModelState.IsValid)
            {
                var category = this.categories
                               .GetCategoryById(id)
                               .FirstOrDefault();

                this.categories.Edit(viewModel, category);
                this.TempData["Message"] = string.Format(GlobalConstants.SuccessMessage, " Edited Category.");
                this.ClearCategoryCache();

                return(this.RedirectToAction("Index", "AdminCategories", new { area = "Admin" }));
            }

            this.TempData["Message"] = string.Format(GlobalConstants.FailMessage, " Edited Category.");

            return(this.View(viewModel));
        }
        public IActionResult EditCategory(int id, AdminEditCategoryViewModel viewModel)
        {
            if (viewModel.Name != null)
            {
                var isAlreadyRegisteredName = RegisteredCategoryNames().FirstOrDefault(n => n.ToLower() == viewModel.Name.ToLower());
                if (isAlreadyRegisteredName != null)
                {
                    ModelState.AddModelError("Name", "Detta kategorinamn är redan registrerat.");
                }
            }

            if (ModelState.IsValid)
            {
                var dbCategory = _dbContext.Categories.First(c => c.Id == id);
                dbCategory.Name = viewModel.Name;
                dbCategory.CategoryDescription = viewModel.Description;
                _dbContext.SaveChanges();
                return(RedirectToAction("AllCategories"));
            }
            return(View(viewModel));
        }