コード例 #1
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!");
                }
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public int Add(LicencePlateEntity licencePlates)
        {
            try
            {
                using (var db = new CroceRossaEntities())
                {
                    db.Tar.Add(licencePlates.ToTar());
                    db.SaveChanges();

                    return(0);
                }
            }
            catch
            {
                return(-1);
            }
        }
コード例 #4
0
 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);
     }
 }