コード例 #1
0
ファイル: AdminController.cs プロジェクト: michalkoh/Enginex
        public async Task <IActionResult> DeleteCategory(CategoryDeleteViewModel categoryModel)
        {
            await Mediator.Send(categoryModel.ToCommand());

            ConfirmationMessage("Kategória bola zmazaná.");
            this.logger.Information($"The category '{categoryModel.Name}' has been successfully deleted.");
            return(RedirectToAction(nameof(Categories)));
        }
コード例 #2
0
        public static CategoryDeleteViewModel ConvertCategorysToCategoryDeleteViewModel(Category category)
        {
            CategoryDeleteViewModel categoryDeleteViewModel = new CategoryDeleteViewModel();

            categoryDeleteViewModel.Id      = category.Id;
            categoryDeleteViewModel.Name    = category.Name;
            categoryDeleteViewModel.SlugUrl = category.SlugUrl;


            return(categoryDeleteViewModel);
        }
コード例 #3
0
        public IActionResult Delete(CategoryDeleteViewModel VM)
        {
            Category categoryToDelete = _catService.GetSingle(x => x.CategoryId == VM.CategoryId);

            UpdateHampersInUse(categoryToDelete, false);

            categoryToDelete.InUse = false;
            _catService.Update(categoryToDelete);

            return(RedirectToAction("Manage", "Category"));
        }
コード例 #4
0
        public async Task <IActionResult> Delete(CategoryDeleteViewModel input)
        {
            var categoryId = await this.categoriesService.DeleteAsync(input.Id);

            if (categoryId == null)
            {
                return(this.NotFound());
            }

            this.TempData["InfoMessage"] = "Category deleted successfully!";
            return(this.RedirectToAction(nameof(this.Index)));
        }
コード例 #5
0
        public IActionResult Delete(int CategoryId)
        {
            Category categoryToDelete = _catService.GetSingle(x => x.CategoryId == CategoryId);

            CategoryDeleteViewModel VM = new CategoryDeleteViewModel
            {
                CategoryId   = CategoryId,
                CategoryName = categoryToDelete.CategoryName
            };

            return(View(VM));
        }
コード例 #6
0
        // GET: CategoryController/Delete/5
        public ActionResult Delete(int id)
        {
            Category    category = _categoryRepo.GetCategoryById(id);
            List <Post> posts    = _postRepository.GetPostsByCategoryId(category.Id);

            CategoryDeleteViewModel vm = new CategoryDeleteViewModel()
            {
                Posts    = posts,
                Category = category
            };

            return(View(vm));
        }
コード例 #7
0
        // GET: Categories/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Category category = await db.Categories.FindAsync(id);

            if (category == null)
            {
                return(HttpNotFound());
            }

            CategoryDeleteViewModel categoryEditViewModel = ClassCategoryConverter.ConvertCategorysToCategoryDeleteViewModel(category);

            return(View(categoryEditViewModel));
        }
コード例 #8
0
        public IActionResult Delete(CategoryDeleteViewModel model)
        {
            var category = this.categoriesData.GetById(model.Id);

            if (category == null)
            {
                this.TempData.AddErrorMessage($"Category with Id {model.Id} does not exist");
                return(this.RedirectToAction("Index", "Categories", new { area = "Products" }));
            }

            foreach (var child in category.Children)
            {
                this.categoriesData.Delete(child);
            }

            this.categoriesData.Delete(category);

            return(this.RedirectToAction("Index", "Categories", new { area = "Products" }));
        }
コード例 #9
0
        public async Task <ActionResult> Delete(CategoryDeleteViewModel model)
        {
            if (ModelState.IsValid)
            {
                var category = await db.CourseCategories.FindAsync(model.Id);

                if (category == null)
                {
                    return(View("Error"));
                }
                db.CourseCategories.Remove(category);
                var courses = await db.Courses.Where(c => c.Category.Id == category.Id).ToListAsync();

                db.Courses.RemoveRange(courses);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", "Category"));
            }
            return(View(model));
        }
コード例 #10
0
        public IActionResult DeleteCategory(CategoryDeleteViewModel model)
        {
            if (db.Product.Any(p => p.CategoryId == model.Id))
            {
                return(RedirectToAction("Categories", "Admin"));
            }

            var category = db.Category.FirstOrDefault(c => c.Id == model.Id);

            if (category == null)
            {
                return(null);
            }

            //Find all categories to delete
            List <Category> allCategories = new List <Category>();

            allCategories.Add(category);
            for (int i = 0; i < allCategories.Count; i++)
            {
                Category        certainCat  = allCategories[i];
                List <Category> tempCatList = db.Category.Where(c => c.Parent_id == certainCat.Id).ToList();
                allCategories.AddRange(tempCatList);
            }

            //Delete categories
            foreach (var c in allCategories)
            {
                Product product = db.Product.FirstOrDefault(p => p.CategoryId == c.Id);
                //if(product != null) Debug.WriteLine(product.Title);
                //means that category or its subcat is assigned to some item(s)
                if (product != null)
                {
                    return(null);
                }
            }
            db.Category.RemoveRange(allCategories);
            db.SaveChanges();

            return(RedirectToAction("Categories", "Admin"));
        }
コード例 #11
0
        public async Task <IActionResult> Delete(CategoryDeleteViewModel viewModel)
        {
            await this.categoriesService.DeleteAsync(viewModel.Id);

            return(this.RedirectToAction(nameof(Web.Controllers.CategoriesController.All), new { area = string.Empty }));
        }