コード例 #1
0
        public async Task <ActionResult> CategoryDelete(int categoryId)
        {
            IEnumerable <ProductImage> images;
            IEnumerable <OrderDetail>  details;
            IEnumerable <Review>       reviews;

            var products = _product.FindAllAsync(x => x.CategoryId == categoryId);

            foreach (var product in await products)
            {
                images = await _productImage.FindAllAsync(x => x.ProductId == product.ProductId);

                foreach (var item in images)
                {
                    await _productImage.DeleteAsync(item);
                }

                reviews = await _review.FindAllAsync(x => x.ProductId == product.ProductId);

                foreach (var item in reviews)
                {
                    await _review.DeleteAsync(item);
                }

                details = await _orderDetail.FindAllAsync(x => x.ProductId == product.ProductId);

                foreach (var item in details)
                {
                    await _orderDetail.DeleteAsync(item);
                }

                await _product.DeleteAsync(product);
            }
            await _category.DeleteByIdAsync(categoryId);

            return(Redirect("/trang-quan-tri/quan-ly-danh-muc"));
        }