Exemple #1
0
        //GET Delete
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var subCategory = await _db.SubCategory.Include(s => s.Category).SingleOrDefaultAsync(m => m.Id == id);

            if (subCategory == null)
            {
                return(NotFound());
            }
            SubCategoryDeleteVM objSCD = new SubCategoryDeleteVM {
                SubCategory = subCategory
            };

            return(View(objSCD));
        }
Exemple #2
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            ViewBag.IsLinkedSubCategory = "";

            var subCategory = await _db.SubCategory.SingleOrDefaultAsync(m => m.Id == id);

            var IsLinkedToMenuItem = await _db.MenuItems.Where(s => s.SubCategoryId.Equals(id)).ToListAsync();

            if (IsLinkedToMenuItem.Count > 0)
            {
                var subCategorywithCat = await _db.SubCategory.Include(s => s.Category).SingleOrDefaultAsync(m => m.Id == id);

                SubCategoryDeleteVM objSCD = new SubCategoryDeleteVM {
                    SubCategory = subCategorywithCat
                };
                objSCD.StatusMessage = "Error : Unable to delete \"" + subCategorywithCat.Name + "\", because it is linked to a Menu Item.";
                return(View(nameof(Delete), objSCD));
            }

            _db.SubCategory.Remove(subCategory);
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }