public IActionResult Create(CountryCreateViewModel c) { if (c is null) { throw new System.ArgumentNullException(nameof(c)); } if (ModelState.IsValid) { var langids = _langrepo.GetAll().Where(l => l.Name == "English").ToList(); int englishid = langids[0].LanguageId; if (c.LanguageId == englishid) { Countries cou = new Countries() { Name = c.Name, IsActive = c.IsActive }; int r = _countryrepo.Create(cou); return(RedirectToAction("Index")); } else { CountryLanguages clangs = new CountryLanguages() { Name = c.Name, LanguageId = c.LanguageId, CountryId = c.EnglishCountryID }; int i = _countrylang.Create(clangs); return(RedirectToAction("Index")); } } return(View()); }
public IActionResult Edit(CountryEditViewModel cem) { if (cem is null) { throw new System.ArgumentNullException(nameof(cem)); } int i; if (ModelState.IsValid) { if (cem.Language == "English") { Countries co = new Countries(); co.Name = cem.Country; co.CountryId = cem.CountryID; i = _countryrepo.Update(co); } else { CountryLanguages cl = new CountryLanguages() { CountryLanguageId = cem.CountryLanguageID, Name = cem.Country, CountryId = cem.CountryID, LanguageId = cem.LanguageId }; i = _countrylang.Update(cl); } if (i > 0) { return(RedirectToAction("Index")); } } return(View()); }
static void Main(string[] args) { Country countryOneInstance = new Country(); Country countryTwoInstance = new Country(); CountryLanguages countryLanguages = new CountryLanguages(); countryLanguages.FirstLanguage = Language.Bosnian.ToString(); countryLanguages.SecondLanguage = Language.Urdu.ToString(); countryOneInstance.CountryLanguages = countryLanguages; countryOneInstance.PlanetName = "Earth"; countryOneInstance.CountryName = "Germany"; countryOneInstance.Currency = Currencies.BAM; countryOneInstance.Continents = Continents.Americas; countryOneInstance.SayHi(); countryOneInstance.SayHi(countryOneInstance.CountryName); Console.WriteLine($"Planet {countryOneInstance.PlanetName} and country {countryOneInstance.CountryName} and currency {countryOneInstance.Currency}"); }
private static void Main(string[] args) { Country countryOneInstance = new Country(); Country countryTwoInstance = new Country(); CountryLanguages countryLanguages = new CountryLanguages(); countryLanguages.FirstLanguage = Languages.English.ToString(); countryLanguages.SecondLanguage = Languages.French.ToString(); countryOneInstance.CountryLanguages = countryLanguages; countryOneInstance.PlanetName = "Earth"; countryOneInstance.CountryName = "Canada"; countryOneInstance.Currency = Currencies.CAD; countryOneInstance.Continents = Continents.NorthAmerica; countryOneInstance.SayHi(); countryOneInstance.SayHi(countryOneInstance.CountryName); Console.WriteLine($"Planet {countryOneInstance.PlanetName} and country is {countryOneInstance.CountryName} and currency is {countryOneInstance.Currency}"); }
public IActionResult Delete( string languagename, int countryid, int clang) { if (languagename == "English") { Countries c = new Countries(); c.CountryId = countryid; int i = _countryrepo.Delete(c); return(RedirectToAction("Index")); } else { CountryLanguages cl = new CountryLanguages(); cl.CountryLanguageId = clang; int i = _countrylang.Delete(cl); return(RedirectToAction("Index")); } }
static void Main(string[] args) { Country countryOne = new Country(); Country countryTwo = new Country(); CountryLanguages countryLanguages = new CountryLanguages(); countryLanguages.FirstLanguage = Languages.Italian.ToString(); countryLanguages.SecondLanguage = Languages.English.ToString(); countryOne.CountryLanguage = countryLanguages; countryOne.PlanetName = "Earth"; countryOne.CountryName = "Italy"; countryOne.Currency = Currencies.EUR; countryOne.Continents = Continents.Europe; countryOne.SayHi(); countryOne.SayHi(countryOne.CountryName); Console.WriteLine($"Planet {countryOne.PlanetName} \nCountry is {countryOne.CountryName}"); Console.WriteLine($"The languages spoken are {countryOne.CountryLanguage.FirstLanguage} and {countryOne.CountryLanguage.SecondLanguage}, \nand the currency is {countryOne.Currency}"); }
static void Main(string[] args) { Country countryOne = new Country(); Country countryTwo = new Country(); CountryLanguages countryLanguages = new CountryLanguages(); countryLanguages.FirstLanguage = languages.English.ToString(); countryLanguages.SecondLanguage = languages.French.ToString(); countryOne.CountryLanguages = countryLanguages; countryOne.PlanetName = "earth"; countryOne.CountryNames = "Canada"; countryOne.Currency = Currencies.CAD.ToString(); countryOne.ContinentsName = Continents.NORTH_AMERICA; countryOne.sayHi(countryOne.PlanetName); countryOne.sayHi( countryOne.CountryNames, countryOne.Currency, countryLanguages.FirstLanguage, countryLanguages.SecondLanguage); }
public static void WriteQueriesToFiles() { Directory.CreateDirectory(SeedFolderPath); using (var currencyFile = new StreamWriter(CurrencyFilePath)) { currencyFile.WriteLine(SetIdentityInsert(nameof(Currency), true)); currencyFile.WriteLine(CurrencyInsertClause); Currencies.ForEach(currency => currencyFile.WriteLine(currency.Id == 1 ? FormatCurrencyValues(currency) : $"union all {FormatCurrencyValues(currency)}")); currencyFile.WriteLine(SetIdentityInsert(nameof(Currency), false)); } using (var languageFile = new StreamWriter(LanguageFilePath)) { languageFile.WriteLine(SetIdentityInsert(nameof(Language), true)); languageFile.WriteLine(LanguageInsertClause); Languages.ForEach(language => languageFile.WriteLine(language.Id == 1 ? FormatLanguageValues(language) : $"union all {FormatLanguageValues(language)}")); languageFile.WriteLine(SetIdentityInsert(nameof(Language), false)); } using (var countryFile = new StreamWriter(CountryFilePath)) { countryFile.WriteLine(SetIdentityInsert(nameof(Country), true)); countryFile.WriteLine(CountryInsertClause); Countries.ForEach(country => countryFile.WriteLine(country.Id == 1 ? FormatCountryValues(country) : $"union all {FormatCountryValues(country)}")); countryFile.WriteLine(SetIdentityInsert(nameof(Country), false)); } using (var countryLanguageFile = new StreamWriter(CountryLanguageFilePath)) { countryLanguageFile.WriteLine(CountryLanguageInsertClause); CountryLanguages.Select((countrylanguage, index) => new { countrylanguage, index }).ToList().ForEach(x => countryLanguageFile.WriteLine( x.index == 0 ? FormatCountryLanguageValues(x.countrylanguage) : $"union all {FormatCountryLanguageValues(x.countrylanguage)}")); } using (var stateFile = new StreamWriter(StateFilePath)) { stateFile.WriteLine(SetIdentityInsert(nameof(State), true)); stateFile.WriteLine(StateInsertClause); States.ForEach(state => stateFile.WriteLine(state.Id == 1 ? FormatStateValues(state) : $"union all {FormatStateValues(state)}")); stateFile.WriteLine(SetIdentityInsert(nameof(State), false)); } using (var provinceFile = new StreamWriter(ProvinceFilePath)) { provinceFile.WriteLine(SetIdentityInsert(nameof(Province), true)); provinceFile.WriteLine(ProvinceInsertClause); Provinces.ForEach(province => provinceFile.WriteLine(province.Id == 1 ? FormatProvinceValues(province) : $"union all {FormatProvinceValues(province)}")); provinceFile.WriteLine(SetIdentityInsert(nameof(Province), false)); } using (var communityFile = new StreamWriter(CommunityFilePath)) { communityFile.WriteLine(SetIdentityInsert(nameof(Community), true)); communityFile.WriteLine(CommunityInsertClause); Communities.ForEach(community => communityFile.WriteLine(community.Id == 1 ? FormatCommunityValues(community) : $"union all {FormatCommunityValues(community)}")); communityFile.WriteLine(SetIdentityInsert(nameof(Community), false)); } using (var placeFile = new StreamWriter(PlaceFilePath)) { placeFile.WriteLine(SetIdentityInsert(nameof(Place), true)); placeFile.WriteLine(PlaceInsertClause); Places.ForEach(place => placeFile.WriteLine(place.Id == 1 ? FormatPlaceValues(place) : $"union all {FormatPlaceValues(place)}")); placeFile.WriteLine(SetIdentityInsert(nameof(Place), false)); } }