コード例 #1
0
        public ActionResult Delete(int id, IFormCollection collection)
        {
            try
            {
                _context.Remove(GetServiceContractById(id));
                _context.SaveChanges();

                return(RedirectToAction(nameof(List)));
            }
            catch
            {
                return(View());
            }
        }
コード例 #2
0
        public ActionResult Delete(int id, IFormCollection collection)
        {
            try
            {
                var c = GetFullyLoadedCustomerById(id);
                if (c.ServiceContracts.Count() > 0)
                {
                    return(View("_CantDeleteDueToContracts"));
                }

                _context.Remove(GetCustomerById(id));
                _context.SaveChanges();

                return(RedirectToAction(nameof(List)));
            }
            catch
            {
                return(View());
            }
        }