private void btnDelete_Click(object sender, RoutedEventArgs e) { Athlete athelete = ((FrameworkElement)sender).DataContext as Athlete; if (MessageBox.Show("Are you sure", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { if (athelete != null) { _athleteRepository.DeleteAthlete(athelete); _athleteRepository.Save(); _athleteManager.Athletes.Remove(athelete); _athleteManager.NextBib = _athleteRepository.GetMaxBib() + 1; } } }
public AthletesView() { InitializeComponent(); var mainWindow = (MainWindow)Application.Current.MainWindow; _rfidManager = mainWindow.RfidManager; _athleteManager = mainWindow.AthleteManager; btnStopAssign.IsEnabled = false; this.DataContext = _athleteManager; btnAssign.DataContext = _rfidManager; _athleteRepository = new AthleteRepository(); _athleteRepository.Save(); dgAthletes.ItemsSource = _athleteManager.Athletes; _athleteManager.NextBib = _athleteRepository.GetMaxBib() + 1; // _athleteManager. }
private void btnAssign_Click(object sender, RoutedEventArgs e) { int maxBib = _athleteRepository.GetMaxBib(); // OrderBy(x=>x.Bib).FirstOrDefault(x => string.IsNullOrEmpty(x.TagId)); }
private void AssignTag(Split split) { Athlete nextAthlete; //_athleteRepository.GetAll(); if (Athletes.Any()) { if (Athletes.Any(x => x.TagId == split.Epc && x.Bib > 0)) { var athelete = Athletes.FirstOrDefault(x => x.TagId == split.Epc); Message = $"Tag {split.Epc} already assigned to {athelete.Bib} {athelete.FirstName} {athelete.LastName}"; return; } if (AutoAssign) { int maxBib = _athleteRepository.GetMaxBib(); NextBib = ++maxBib; } nextAthlete = Athletes.SingleOrDefault(x => x.Bib == NextBib && string.IsNullOrEmpty(x.TagId)); if (nextAthlete != null) { nextAthlete.TagId = split.Epc; _athleteRepository.Edit(nextAthlete, nextAthlete.Id); _athleteRepository.Save(); } else { nextAthlete = Athletes.FirstOrDefault(x => x.Bib == 0); if (nextAthlete != null) { nextAthlete.Bib = NextBib; nextAthlete.TagId = split.Epc; _athleteRepository.Edit(nextAthlete, nextAthlete.Id); _athleteRepository.Save(); Message = $"Tag {split.Epc} assigned to { nextAthlete.Bib}"; } else if (Athletes.Any(x => x.Bib == NextBib) == false) { nextAthlete = new Athlete { Bib = NextBib, TagId = split.Epc }; _athleteRepository.Add(nextAthlete); _athleteRepository.Save(); Application.Current.Dispatcher.Invoke((Action)(() => { Athletes.Insert(0, nextAthlete); })); Message = $"Tag {split.Epc} assigned to { nextAthlete.Bib}"; } return; } } else { if (Athletes.Any(x => x.Bib == NextBib)) { var athelete = Athletes.FirstOrDefault(x => x.Bib == NextBib); Message = $"Tag {split.Epc} already assigned to {athelete.Bib} {athelete.FirstName} {athelete.LastName}"; return; } nextAthlete = new Athlete { Bib = NextBib, TagId = split.Epc }; Application.Current.Dispatcher.Invoke((Action)(() => { Athletes.Insert(0, nextAthlete); })); _athleteRepository.Add(nextAthlete); _athleteRepository.Save(); Message = $"Tag {split.Epc} assigned to {nextAthlete.Bib} with no athlete name"; } if (AutoAssign) { NextBib++; } }