private void DeleteEntry(object obj)
 {
     using (var context = new LedgerContext())
     {
         if (!SelectedItem.Comment.IsInDictionary)
         {
             context.LedgerDictionaries.Attach(SelectedItem.Comment);
             context.LedgerDictionaries.Remove(SelectedItem.Comment);
         }
         if (!SelectedItem.Contractor.IsInDictionary)
         {
             context.LedgerDictionaries.Attach(SelectedItem.Contractor);
             context.LedgerDictionaries.Remove(SelectedItem.Contractor);
         }
         if (!SelectedItem.EconomicEvent.IsInDictionary)
         {
             context.LedgerDictionaries.Attach(SelectedItem.EconomicEvent);
             context.LedgerDictionaries.Remove(SelectedItem.EconomicEvent);
         }
         context.Entries.Attach(SelectedItem);
         context.Entries.Remove(SelectedItem);
         context.SaveChanges();
     }
     GetDataFromDatabase();
 }
 public void AddContractor(object obj)
 {
     using (var database = new LedgerContext())
     {
         database.LedgerDictionaries.Add(Contractor);
         database.SaveChanges();
     }
     CloseWindow();
 }
 public void EditContractor(object obj)
 {
     using (var context = new LedgerContext())
     {
         var contractorInDb = context.LedgerDictionaries.OfType<Contractor>().AsNoTracking().Single(x => x.Id == Contractor.Id);
         if (!Contractor.Equals(contractorInDb))
             context.Entry(Contractor).State = EntityState.Modified;
         context.SaveChanges();
     }
     CloseWindow();
 }
 public void EditEntry(object obj)
 {
     CheckIfAddedNewDictionaryEntry();
     using (var context = new LedgerContext())
     {
         var contractorInDb = context.LedgerDictionaries.OfType<Contractor>().AsNoTracking().Single(x => x.Id == Entry.Contractor.Id);
         if (!Entry.Contractor.Equals(contractorInDb))
             context.Entry(Contractor).State=EntityState.Modified;
         context.Entry(Entry).State=EntityState.Modified;
         context.SaveChanges();
     }
     Close();
 }
 public void AddEntry(object obj)
 {
     CheckIfAddedNewDictionaryEntry();
     using (var database = new LedgerContext())
     {
         database.Entries.Add(Entry);
         database.SaveChanges();
     }
     Close();
 }