private void DeleteUserButton_Click(object sender, RoutedEventArgs e) { var selectedItem = this.lvLicencePlates.SelectedItem; if (selectedItem != null) { LicencePlateEntity licencePlate = selectedItem as LicencePlateEntity; LicencePlateService service = new LicencePlateService(); if (MessageBox.Show("Sei sicuro di voler eliminare \"" + licencePlate.Targa + " \" ?", "Elimina Targa", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { if (service.Delete(licencePlate) == 0) { MessageBox.Show("cancellato!"); this.RefreshData(); } else { MessageBox.Show("NON cancellato!"); } } else { MessageBox.Show("NON cancellato!"); } } }
public static Tar ToTar(this LicencePlateEntity licencePlatesEntity, Tar tar = null) { if (tar == null) { tar = new Tar(); } tar.TarOwnId = licencePlatesEntity.Id; tar.TarVal = licencePlatesEntity.Targa; return(tar); }
public int Add(LicencePlateEntity licencePlates) { try { using (var db = new CroceRossaEntities()) { db.Tar.Add(licencePlates.ToTar()); db.SaveChanges(); return(0); } } catch { return(-1); } }
public int Delete(LicencePlateEntity licencePlates) { try { using (var db = new CroceRossaEntities()) { Tar tar = db.Tar.First(x => x.TarOwnId == licencePlates.Id); if (tar != null) { db.Tar.Remove(tar); db.SaveChanges(); } return(0); } } catch (Exception) { return(-1); } }