public void Save() { if (CheckData()) { AuthorityService service = new AuthorityService(); if ((this.DataContext as AuthorityEntity).Id == -1 && !CheckDoppione()) { if (service.Add(this.DataContext as AuthorityEntity) == 0) { MessageBox.Show("Salvato!"); this.DataContext = new AuthorityEntity(); } else { MessageBox.Show("Errore durante il salvataggio!"); } } else { if (service.Update(this.DataContext as AuthorityEntity) == 0) { MessageBox.Show("Salvato!"); } else { MessageBox.Show("Errore durante il salvataggio!"); } } } }