private async void reloadBtn_Click(object sender, EventArgs e) { if (_rotationId.HasValue) { var rotation = await _apiService.GetById <Model.Rotation>(_rotationId); From.Value = rotation.From.Date; To.Value = rotation.To.Date; Description.Text = rotation.Description; Available.Checked = rotation.Available; Birthday.Checked = rotation.ForBirthday; var movie = await _moviesApi.GetById <Model.Movie>(rotation.MovieId); var show = await _showsApi.GetById <Model.Show>(rotation.ShowId); Movies.SelectedIndex = Movies.FindStringExact(movie.Title); Shows.SelectedIndex = Shows.FindStringExact(show.Title); } else { From.Value = DateTime.Now; To.Value = DateTime.Now; Description.Text = ""; Available.Checked = false; Birthday.Checked = false; Movies.SelectedIndex = -1; Shows.SelectedIndex = -1; } }
private async void AddEditRotationForm_Load(object sender, EventArgs e) { var shows = await _showsApi.Get <List <Model.Show> >(null); var movies = await _moviesApi.Get <List <Model.Movie> >(null); movies.Sort((a, b) => a.Title.CompareTo(b.Title)); shows.Sort((a, b) => a.Title.CompareTo(b.Title)); Shows.DisplayMember = "Text"; Shows.ValueMember = "Value"; foreach (var show in shows) { Shows.Items.Add(new { Text = show.Title, Value = show.ShowId }); } if (Shows.Items.Count != 0) { Shows.SelectedIndex = 0; } Movies.DisplayMember = "Text"; Movies.ValueMember = "Value"; foreach (var movie in movies) { Movies.Items.Add(new { Text = movie.Title, Value = movie.MovieId }); } if (Movies.Items.Count != 0) { Movies.SelectedIndex = 0; } if (_rotationId.HasValue) { Title.Text = "Edit rotation"; var rotation = await _apiService.GetById <Model.Rotation>(_rotationId); From.Value = rotation.From.Date; To.Value = rotation.To.Date; Description.Text = rotation.Description; Available.Checked = rotation.Available; Birthday.Checked = rotation.ForBirthday; var movie = await _moviesApi.GetById <Model.Movie>(rotation.MovieId); var show = await _showsApi.GetById <Model.Show>(rotation.ShowId); Movies.SelectedIndex = Movies.FindStringExact(movie.Title); Shows.SelectedIndex = Shows.FindStringExact(show.Title); } else { Title.Text = "Add a rotation"; Movies.SelectedIndex = -1; Shows.SelectedIndex = -1; } }