//[ValidateAntiForgeryToken]
        public JsonResult DeleteProduct([FromBody] Product del)

        {
            var product = _context.Product.Find(del.Pid);

            _context.Entry(product).Collection(c => c.ProductSold).Load();
            if (product.ProductSold.Count > 0)
            {
                foreach (var productSold in product.ProductSold)
                {
                    _context.ProductSold.Remove(productSold);
                }
            }
            _context.Product.Remove(product);
            _context.SaveChanges();
            return(Json(product));
        }
        //[ValidateAntiForgeryToken]
        public JsonResult DeleteStore([FromBody] Store del)

        {
            var store = _context.Store.Find(del.Sid);

            _context.Entry(store).Collection(c => c.ProductSold).Load();
            if (store.ProductSold.Count > 0)
            {
                foreach (var productSold in store.ProductSold)
                {
                    _context.ProductSold.Remove(productSold);
                }
            }
            _context.Store.Remove(store);
            _context.SaveChanges();
            return(Json(store));
        }
Example #3
0
        //[ValidateAntiForgeryToken]
        public JsonResult DeleteCustomer([FromBody] Customer del)
        {
            var customer = _context.Customer.Find(del.Id);

            _context.Entry(customer).Collection(c => c.ProductSold).Load();
            if (customer.ProductSold.Count > 0)
            {
                foreach (var productSold in customer.ProductSold)
                {
                    _context.ProductSold.Remove(productSold);
                }
            }
            _context.Customer.Remove(customer);
            _context.SaveChanges();

            return(Json("Customer Removed Successfully"));
        }