private void OlympiadTreeView_MouseDoubleClick(object sender, MouseButtonEventArgs e) { GetPropForSelectedService service = new GetPropForSelectedService(); DateTime currOlympDate = new DateTime(); foreach (var o in service.GetOlympiads()) { string bufName; string gettingOlympName; bufName = ((sender as TreeView).SelectedItem as TreeViewItem).Header.ToString(); gettingOlympName = $"{o.Type.Name} olympiad in {o.Country.Name} {String.Format("{0:y}", o.Date)}"; if (bufName == gettingOlympName) { currOlympDate = o.Date; } } if (CurrentOlympaid != null) { if (CurrentOlympaid.Date == currOlympDate) { return; } } CurrentOlympaid = service.GetOlympiads().FirstOrDefault(x => x.Date == currOlympDate); MainStackPanel.Visibility = Visibility.Visible; InitContentUI(); }
private void Add_Click(object sender, RoutedEventArgs e) { if (DatePicker.DisplayDate == null) { MessageBox.Show("Date can`t be null."); return; } Olympiad newType = new Olympiad(); GetPropForSelectedService getService = new GetPropForSelectedService(); newType.Date = DatePicker.SelectedDate.Value; newType.Type = getService.GetOlympTypes().FirstOrDefault(x => x.Name == (OlympTypeComboBox.SelectedItem as OlympType).Name); newType.Country = getService.GetCountry().FirstOrDefault(x => x.Name == (CountryComboBox.SelectedValue as Country).Name); foreach (var o in getService.GetOlympiads()) { if (o.Date == newType.Date) { MessageBox.Show($"Olympiads in {o.Date.ToString("0:d")} alredy exists."); } } AddingService addService = new AddingService(); addService.AddOlympiad(newType); MessageBox.Show("Olympiad adding"); }
public void DeleteItem(int id) { Olympiad olympiadToDelete = new Olympiad() { OlympiadID = id }; _database.Olympiads.Delete(olympiadToDelete.OlympiadID); _database.Save(); }
public OlympiadDTO GetItem(int?id) { Olympiad item = _database.Olympiads.Get(id); return(new OlympiadDTO { OlympiadID = item.OlympiadID, OlympiadName = item.OlympiadName, OlympiadLevel = item.OlympiadLevel, OlympiadStartDate = item.OlympiadStartDate, OlympiadEndDate = item.OlympiadEndDate, OlympiadDirection = item.OlympiadDirection, OlympiadType = item.OlympiadType, UniversityID = item.UniversityID }); }
public void UpdateItem(OlympiadDTO item) { Olympiad olympiad = new Olympiad { OlympiadID = item.OlympiadID, OlympiadName = item.OlympiadName, OlympiadLevel = item.OlympiadLevel, OlympiadStartDate = item.OlympiadStartDate, OlympiadEndDate = item.OlympiadEndDate, OlympiadDirection = item.OlympiadDirection, OlympiadType = item.OlympiadType, UniversityID = item.UniversityID }; _database.Olympiads.Update(olympiad); _database.Save(); }
public Task UpdateOlympiad(Olympiad olympiad) { var foundOlympiad = GetOlympiad(olympiad.Id).Result; if (foundOlympiad == null) { AddOlympiad(olympiad); } else { if (foundOlympiad != olympiad) { _olympiads.Remove(foundOlympiad); _olympiads.Add(olympiad); } } return(Task.CompletedTask); }
private bool AddOlympiadCommandCanExecute(object arg) { if (string.IsNullOrEmpty(NewOlympiadYear) || string.IsNullOrEmpty(NewOlympiadCity) || NewOlympiadCountry == null) { return(false); } try { var year = int.Parse(NewOlympiadYear); if (!Olympiad.IsValidYear(year) || db.Olympiads.ToList().Any(o => o.Year == year)) { return(false); } } catch (Exception) { return(false); } return(true); }
private void AddOlympiadCommandExecute(object obj) { string imagePath = string.IsNullOrEmpty(NewOlympiadImage) ? @"C:\Users\ibrah\source\repos\Olympics\Olympics\Images\Olympiads\Default.png" : NewOlympiadImage; var olymp = new Olympiad( int.Parse(NewOlympiadYear), IsSummerOlympiad ? Season.Summer : Season.Winter, NewOlympiadCountry, NewOlympiadCity, imagePath); db.Olympiads.Add(olymp); db.SaveChanges(); FillOlympiads(); NewOlympiadYear = string.Empty; NewOlympiadCity = string.Empty; NewOlympiadImage = string.Empty; NewOlympiadCountry = null; IsSummerOlympiad = true; systemClass.ShowMessageBox("Info", "Olympiad has been added!"); }
public void AddOlympiad(Olympiad olympiad) { db.Olympiads.Add(olympiad); db.SaveChanges(); }
public Task RemoveOlympiad(Olympiad olympiad) { _olympiads.Remove(olympiad); return(Task.CompletedTask); }
public Task AddOlympiad(Olympiad olympiad) { _olympiads.Add(olympiad); return(Task.CompletedTask); }