private void DeleteUserButton_Click(object sender, RoutedEventArgs e) { var selectedItem = this.lvAssociations.SelectedItem; if (selectedItem != null) { CarLicencePlateAssociationEntity association = selectedItem as CarLicencePlateAssociationEntity; CarLicPlateAssociationService service = new CarLicPlateAssociationService(); if (MessageBox.Show("Sei sicuro di voler eliminare \"" + association.CarName + " " + association.LicencePlate + " \" ?", "Elimina Associazione", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { if (service.Delete(association) == 0) { MessageBox.Show("cancellato!"); this.RefreshData(); } else { MessageBox.Show("NON cancellato!"); } } else { MessageBox.Show("NON cancellato!"); } } }
public static CarLicencePlateAssociationEntity toCarLicencePlateAssociationEntity(this CarTar carTar) { CarLicencePlateAssociationEntity association = new CarLicencePlateAssociationEntity(); association.CarId = carTar.CarId; association.Id = carTar.CarTarOwnId; association.IsEnabled = carTar.CarTarEnb; association.LicencePlateId = carTar.TarId; return(association); }
public static CarTar toCarTar(this CarLicencePlateAssociationEntity association, CarTar carTar = null) { if (carTar == null) { carTar = new CarTar(); } carTar.CarId = association.CarId; carTar.CarTarOwnId = association.Id; carTar.CarTarEnb = association.IsEnabled; carTar.TarId = association.LicencePlateId; return(carTar); }
private void disableConcurrentRecords(int id) { CarLicencePlateAssociationEntity dt = this.DataContext as CarLicencePlateAssociationEntity; if (dt.IsEnabled == true) { using (var db = new InserimentoDatiCroceRossa.DbModel.CroceRossaEntities()) { List <int> concurrentIds = db.CarTar.Where(x => (x.CarId == dt.CarId || x.TarId == dt.LicencePlateId) && x.CarTarOwnId != id && x.CarTarEnb == true).Select(y => y.CarTarOwnId).ToList(); concurrentIds.ForEach(item => { db.CarTar.First(x => x.CarTarOwnId == item).CarTarEnb = false; }); db.SaveChanges(); } } }
public int Add(CarLicencePlateAssociationEntity entity) { try { using (var db = new CroceRossaEntities()) { CarTar carTar = entity.toCarTar(); db.CarTar.Add(carTar); db.SaveChanges(); return(carTar.CarTarOwnId); } } catch { return(-1); } }
public int Delete(CarLicencePlateAssociationEntity entity) { try { using (var db = new CroceRossaEntities()) { CarTar carTar = db.CarTar.First(x => x.CarTarOwnId == entity.Id); if (carTar != null) { db.CarTar.Remove(carTar); db.SaveChanges(); } return(0); } } catch (Exception) { return(-1); } }
public CarLicencePlateAssociationEntity GetAssociationById(int id) { CarLicencePlateAssociationEntity association = new CarLicencePlateAssociationEntity(); using (var db = new CroceRossaEntities()) { association = db.CarTar.FirstOrDefault(x => x.CarTarOwnId == id).toCarLicencePlateAssociationEntity(); if (association.Id != -1) { if (association.CarId != -1) { association.CarName = db.Car.FirstOrDefault(x => x.CarOwnId == association.CarId).CarNam; } if (association.LicencePlateId != -1) { association.LicencePlate = db.Tar.FirstOrDefault(x => x.TarOwnId == association.LicencePlateId).TarVal; } } } return(association); }