public void Save()
 {
     if (CheckData())
     {
         LicencePlateService service = new LicencePlateService();
         if ((this.DataContext as LicencePlateEntity).Id == -1 && !CheckDoppione())
         {
             if (service.Add(this.DataContext as LicencePlateEntity) == 0)
             {
                 MessageBox.Show("Salvato!");
                 this.DataContext = new LicencePlateEntity();
             }
             else
             {
                 MessageBox.Show("Errore durante il salvataggio!");
             }
         }
         else
         {
             if (service.Update(this.DataContext as LicencePlateEntity) == 0)
             {
                 MessageBox.Show("Salvato!");
             }
             else
             {
                 MessageBox.Show("Errore durante il salvataggio!");
             }
         }
     }
 }
Exemple #2
0
        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!");
                }
            }
        }
Exemple #3
0
        public void RefreshData()
        {
            LicencePlateService service = new LicencePlateService();

            licencePlates = new ObservableCollection <LicencePlateEntity>(service.GetAllLicencePlates());
            this.lvLicencePlates.ItemsSource = licencePlates;
        }
        private bool CheckDoppione()
        {
            string licencePlate = (this.DataContext as LicencePlateEntity).Targa.ToLower();


            LicencePlateService       service = new LicencePlateService();
            List <LicencePlateEntity> targhe  = service.GetAllLicencePlates();

            if (targhe.Any(x => x.Targa.ToLower().Equals(licencePlate)))
            {
                return(true);
            }

            return(false);
        }