protected override async void OnNavigatedTo(NavigationEventArgs e) { var result = await Service.GetAll(); result.ForEach(x => Stewardesses.Add(x)); lastId = Stewardesses.LastOrDefault().Id; }
private async void BtnCreate_OnClick(object sender, RoutedEventArgs e) { Canvas.Visibility = Visibility.Collapsed; if (isCreate) { var stewardess = ReadTextBoxesData(); if (stewardess != null) { try { await Service.Create(stewardess); } catch { Info.Text = "Server error!"; } lastId++; stewardess.Id = lastId; Stewardesses.Add(stewardess); isCreate = false; CreateInfo(); Info.Text = "Choose new action!"; } } else { CreateInfo(); isCreate = true; Info.Text = "Info : Input data and press 'Create' "; } }
private async void BtnUpdate_OnClick(object sender, RoutedEventArgs e) { if (!isCreate) { var stewardessInput = ReadTextBoxesData(); if (stewardessInput != null && _selectedStewardess != null) { try { await Service.Update(stewardessInput, _selectedStewardess.Id); } catch { Info.Text = "Server error!"; } var itemIndex = Stewardesses.ToList().FindIndex(x => x.Id == _selectedStewardess.Id); var item = Stewardesses.ToList().ElementAt(itemIndex); Stewardesses.RemoveAt(itemIndex); item = stewardessInput; item.Id = _selectedStewardess.Id; Stewardesses.Insert(itemIndex, item); TbId.Text = "Stewardess Id :" + item.Id; TbFName.Text = "First name : " + item.FirstName; TbLName.Text = "Last name : " + item.LastName; TbBirth.Text = "Birth : " + item.DateOfBirth; } } }
public async void Delete(object sender, RoutedEventArgs e) { if (SaveButton.Visibility == Visibility.Visible) { SaveButton.Visibility = Visibility.Collapsed; } if (AddButton.Visibility == Visibility.Visible) { AddButton.Visibility = Visibility.Collapsed; } try { if (TextId.IsReadOnly) { TextId.IsReadOnly = false; } await _service.Delete(SelectedStewardesse.Id.ToString()); // refresh listView Stewardesses.Clear(); foreach (var airplaneType in await _service.LoadData()) { Stewardesses.Add(airplaneType); } } catch (Exception) { } }
public async void DeleteStewardess() { if (await service.DeleteEntity(SelectedStewardess.Id)) { Stewardesses.Remove(Stewardesses.FirstOrDefault(c => c.Id == SelectedStewardess.Id)); } }
private async void FillStewardesssCollection() { var temp = await service.GetEntities(); foreach (var item in temp) { Stewardesses.Add(item); } }
public async void UpdateStewardess() { if (await service.UpdateEntity(SelectedStewardess.Id, SelectedStewardess)) { var tempStewardess = Stewardesses.FirstOrDefault(c => c.Id == SelectedStewardess.Id); tempStewardess.FirstName = SelectedStewardess.FirstName; tempStewardess.LastName = SelectedStewardess.LastName; tempStewardess.Birthday = SelectedStewardess.Birthday; } }
private async void BtnDelete_OnClick(object sender, RoutedEventArgs e) { Canvas.Visibility = Visibility.Visible; try { await Service.Delete(_selectedStewardess.Id); } catch { Info.Text = "Server error!"; } Stewardesses.Remove(_selectedStewardess); }
private async void AddStewardess() { try { var result = await _service.AddAsync(SelectedStewardess); Stewardesses.Insert(0, result); } catch (System.InvalidOperationException ex) { await _dialogService.ShowMessage(ex.Message, "Error"); } }
private async void DeleteStewardess() { try { await _service.DeleteAsync(SelectedStewardess.Id); Stewardesses.Remove(SelectedStewardess); } catch (System.InvalidOperationException ex) { await _dialogService.ShowMessage(ex.Message, "Error"); } }
public async Task Seed() { if (!_context.Aircrafts.Any()) { Aircrafts.ForEach(i => _context.Aircrafts.Add(i)); await _context.SaveChangesAsync(); } if (!_context.AircraftTypes.Any()) { AircraftTypes.ForEach(i => _context.AircraftTypes.Add(i)); await _context.SaveChangesAsync(); } if (!_context.Pilots.Any()) { Pilots.ForEach(i => _context.Pilots.Add(i)); await _context.SaveChangesAsync(); } if (!_context.Crews.Any()) { Crews.ForEach(i => _context.Crews.Add(i)); await _context.SaveChangesAsync(); } if (!_context.Stewardesses.Any()) { Stewardesses.ForEach(i => _context.Stewardesses.Add(i)); await _context.SaveChangesAsync(); } if (!_context.Tickets.Any()) { Tickets.ForEach(i => _context.Tickets.Add(i)); await _context.SaveChangesAsync(); } if (!_context.Flights.Any()) { Flights.ForEach(i => _context.Flights.Add(i)); await _context.SaveChangesAsync(); } if (!_context.Departures.Any()) { Departureses.ForEach(i => _context.Departures.Add(i)); await _context.SaveChangesAsync(); } }
public DbSet <TEntity> SetOf <TEntity>() where TEntity : Entity { if (Flights is IEnumerable <TEntity> ) { Tickets.Load(); return(Flights as DbSet <TEntity>); } else if (Depatures is IEnumerable <TEntity> ) { Tickets.Load(); Flights.Load(); Pilots.Load(); Stewardesses.Load(); Crew.Load(); Types.Load(); Planes.Load(); return(Depatures as DbSet <TEntity>); } else if (Crew is IEnumerable <TEntity> ) { Pilots.Load(); Stewardesses.Load(); return(Crew as DbSet <TEntity>); } else if (Stewardesses is IEnumerable <TEntity> ) { return(Stewardesses as DbSet <TEntity>); } else if (Pilots is IEnumerable <TEntity> ) { return(Pilots as DbSet <TEntity>); } else if (Planes is IEnumerable <TEntity> ) { Types.Load(); return(Planes as DbSet <TEntity>); } else if (Types is IEnumerable <TEntity> ) { return(Types as DbSet <TEntity>); } else { Flights.Load(); return(Tickets as DbSet <TEntity>); } }
private async void FillAdditionalCollections() { var pilots = await pilotService.GetEntities(); foreach (var item in pilots) { Pilots.Add(item); } var stewardesses = await stewardessService.GetEntities(); foreach (var item in stewardesses) { Stewardesses.Add(item); } }
protected void SearchAsync() { List <Stewardess> temp = Stewardesses.ToList(); Stewardesses.Clear(); if (string.IsNullOrWhiteSpace(SearchFilter)) { temp.Clear(); UpdateDataAsync(); } else { Stewardesses = new ObservableCollection <Stewardess>(temp.Where(s => s.FirstName.StartsWith(SearchFilter, StringComparison.CurrentCultureIgnoreCase) || s.LastName.StartsWith(SearchFilter, StringComparison.CurrentCultureIgnoreCase)).ToList()); } RaisePropertyChanged(nameof(Stewardesses)); }
public async void LoadData(object sender, RoutedEventArgs e) { if (SaveButton.Visibility == Visibility.Visible) { SaveButton.Visibility = Visibility.Collapsed; } if (AddButton.Visibility == Visibility.Visible) { AddButton.Visibility = Visibility.Collapsed; } Stewardesses.Clear(); foreach (var airplaneType in await _service.LoadData()) { Stewardesses.Add(airplaneType); } }
public async void Add(object sender, RoutedEventArgs e) { SelectedStewardesse.Id = 0; SelectedStewardesse.FirstName = TextFirstName.Text; SelectedStewardesse.LastName = TextLastName.Text; SelectedStewardesse.Birthdate = DateTime.Parse(TextBirthdate.Text); await _service.Create(SelectedStewardesse); AddButton.Visibility = Visibility.Collapsed; TextId.IsReadOnly = false; // refresh listView Stewardesses.Clear(); foreach (var airplaneType in await _service.LoadData()) { Stewardesses.Add(airplaneType); } }
private async void LoadStewardesses() { var result = await StewardessService.GetAll(); result.ForEach(x => Stewardesses.Add(x)); }