private void SetupCountrySpinner(AppCompatSpinner countrySpinner, MediaCountry selectedCountry) { var countries = AniListEnum.GetEnumValues <MediaCountry>(); var displayCountries = countries.Select(x => x.DisplayValue).ToList(); countrySpinner.Adapter = new ArrayAdapter <string>(Activity, Resource.Layout.View_SpinnerDropDownItem, displayCountries); if (selectedCountry != null) { countrySpinner.SetSelection(countries.FindIndex(x => x.Value == selectedCountry.Value)); } }
public IActionResult PostCountry(MediaCountry obj) { if (obj == null) { return(BadRequest()); } _context.MediaCountries.Add(obj); _context.SaveChanges(); var model = new MediaCountry { CountryID = obj.CountryID, MediaID = obj.MediaID }; return(Ok(model)); }
private async void BtnAdd_Click(object sender, EventArgs e) { try { int.Parse(txtBudget.Text); double.Parse(txtBoxOffice.Text); } catch { MessageBox.Show("Both the budget and box office amount must be numbers!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtTitle.Text == "" || txtSynopsis.Text == "" || txtDirector.Text == "" || txtBoxOffice.Text == "" || txtBudget.Text == "") { MessageBox.Show("Please enter all the required fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (dropCountry.SelectedIndex == -1 || dropLanguage.SelectedIndex == -1 || dropGenre.SelectedIndex == -1 || dropStudio.SelectedIndex == -1) { MessageBox.Show("Make sure you assigned the country, studio, genre and a language to the movie you're adding!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int width = NewCoverImage.Width; int height = NewCoverImage.Height; if (!((width == 300 && height == 450) || (width == 512 && height == 768) || (width == 800 && height == 1200))) { MessageBox.Show("The film cover's resolution is disallowed! Please try another image.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var model = new MediaInputModel { Title = txtTitle.Text, Synopsis = txtSynopsis.Text, Director = txtDirector.Text, ReleaseDate = dateRelease.Value, Budget = int.Parse(txtBudget.Text), WorldwideGross = double.Parse(txtBoxOffice.Text), GenreID = dropGenre.SelectedIndex + 1, CountryID = dropCountry.SelectedIndex + 1, LanguageID = dropLanguage.SelectedIndex + 1, StudioID = dropStudio.SelectedIndex + 1, RatingID = 1 // G default rating }; var returns = await _mediaService.Insert <Media>(model); // Genre MediaGenre mediaGenre = new MediaGenre { MediaID = returns.MediaID, GenreID = model.GenreID }; await $"{Properties.Settings.Default.APIUrl}/MediaContent/Genres" .WithBasicAuth(APIService.Username, APIService.Password) .PostJsonAsync(mediaGenre); // Country MediaCountry mediaCountry = new MediaCountry { MediaID = returns.MediaID, CountryID = model.CountryID }; await $"{Properties.Settings.Default.APIUrl}/MediaContent/Countries" .WithBasicAuth(APIService.Username, APIService.Password) .PostJsonAsync(mediaCountry); // Language MediaLanguage mediaLanguage = new MediaLanguage { MediaID = returns.MediaID, LanguageID = model.LanguageID }; await $"{Properties.Settings.Default.APIUrl}/MediaContent/Languages" .WithBasicAuth(APIService.Username, APIService.Password) .PostJsonAsync(mediaLanguage); // Copy newly added avatar to Assets/Avatars string coverLocation = await $"{Properties.Settings.Default.APIUrl}/info/covers".GetStringAsync(); string fileName = ""; try { fileName = Path.GetFileName(Cover.FileName); } catch { fileName = "Default.png"; } if (fileName != "Default.png" && fileName != "") { System.IO.File.Copy(Cover.FileName, $@"{coverLocation}\{fileName}"); } else if (fileName == "") { fileName = "Default.png"; } model.CoverLocation = $"/Assets/Covers/{fileName}"; Models.Image cover = new Models.Image { Location = model.CoverLocation, MediaID = returns.MediaID }; var imgReturns = await _imagesService.Insert <Models.Image>(cover); MessageBox.Show("Media added successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); }