public IActionResult Delete(int Id)
 {
     if (db != null)
     {
         if (db.Transactions != null)
         {
             var transaction = db.Transactions.First(transaction => transaction.TransactionId == Id);
             try
             {
                 db.Transactions.Remove(transaction);
                 db.SaveChanges();
             }
             catch (Exception e)
             {
                 Debug.WriteLine($"Error {e.Message}. Stack trace: {e.StackTrace}");
             }
             return(RedirectToAction("Index"));
         }
         else
         {
             throw new NullReferenceException("Transactions set does not exsist in current TransactionContext");
         }
     }
     else
     {
         throw new NullReferenceException("Transactions database context does not exist");
     }
 }
Example #2
0
        public IActionResult Delete(int id)
        {
            var manager = db.Managers.FirstOrDefault(x => x.ManagerId == id);

            if (manager != null)
            {
                try
                {
                    db.Managers.Remove(manager);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"Error {e.Message}. Stack trace: {e.StackTrace}");
                }
            }
            return(RedirectToAction("Index"));
        }