public void InsertLanguageCountryRelationship(Country country, int index) { string property = "languages"; if (allCountries[index][property].HasValues) { country.CountryLanguageRelations = new List <CountryLanguageRelation>(4); int len = allCountries[index][property].Count(); for (int i = 0; i < len; i++) { string code = GetSafeStringArray(index, property, i); var language = db.CountryLanguages.FirstOrDefault(n => n.Code == code); if (language != null) { var o = new CountryLanguageRelation(); o.CountryLanguageID = language.CountryLanguageID; country.CountryLanguageRelations.Add(o); } else { var ln = new CountryLanguage(); ln.Code = code; ln.Language = "Unknown"; ln.NativeName = "Unknown"; db.CountryLanguages.Add(ln); } } } }
static void Main(string[] args) { Country countryOne = new Country(); Country countryTwo = new Country(); CountryLanguage countryLanguageStruct = new CountryLanguage(); // Assign the struct to the Enum values countryLanguageStruct.FirstLanguage = Language.Spanish.ToString(); countryLanguageStruct.SecondLanguage = Language.English.ToString(); countryOne.PlanetName = "Earth"; countryOne.Continent = Continent.America; countryOne.CountryName = "Mexico"; countryOne.Capital = "Mexico City"; countryOne.Currency = Currency.MXN; // Assign Currency value to Currency value countryOne.CountryLanguage = countryLanguageStruct; countryOne.SayHi(countryOne.CountryName); countryTwo.PlanetName = "Earth"; countryTwo.Continent = Continent.Europe; countryTwo.CountryName = "United Kingdom"; countryTwo.Capital = "London"; countryTwo.Currency = Currency.LB; // Assign Currency value to Currency value countryTwo.CountryLanguage = countryLanguageStruct; countryTwo.SayHi(countryTwo.CountryName); }
public ActionResult Delete(string id, string languageCode) { //Get Item CountryLanguage countryLanguage = new CountryLanguage(); countryLanguage = countryLanguageRepository.GetItem(id, languageCode); //Check Exists if (countryLanguage == null) { ViewData["ActionMethod"] = "DeleteGet"; return(View("RecordDoesNotExistError")); } //AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToReferenceInfo()) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Parent data ViewData["CountryCode"] = id; ViewData["CountryName"] = countryLanguage.Country.CountryName; countryLanguageRepository.EditItemForDisplay(countryLanguage); return(View(countryLanguage)); }
public async Task <ActionResult> SaveLanguage(CountryLanguage countryLanguage) { try { string redirectURL = string.Empty; LocalizationManager objLocalization = new LocalizationManager(); if (countryLanguage.LanguageName.Length > 0) { string[] langs = countryLanguage.LanguageName.Split("##"); string[] countrylang = langs[0].Split(' '); countryLanguage.CultureName = langs[0]; countryLanguage.CultureCode = langs[1]; countryLanguage.Country = countrylang[1]; countryLanguage.Country = countryLanguage.Country.Substring(1, countryLanguage.Country.Length - 2); countryLanguage.Language = countrylang[0]; string[] langcode = langs[1].Split('-'); countryLanguage.CountryCode = langcode[1]; countryLanguage.LanguageCode = langcode[0]; await objLocalization.Add(countryLanguage, GetUsername); } redirectURL = nameof(Index); return(RedirectToAction(redirectURL)); } catch (Exception ex) { ProcessException(ex); return(View("Index")); } }
public async Task <IActionResult> PostCountryLanguage([FromBody] CountryLanguage countryLanguage) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.CountryLanguage.Add(countryLanguage); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (CountryLanguageExists(countryLanguage.CountryCode)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetCountryLanguage", new { id = countryLanguage.CountryCode }, countryLanguage)); }
public async Task <IActionResult> PutCountryLanguage([FromRoute] int id, [FromBody] CountryLanguage countryLanguage) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != countryLanguage.CountryCode) { return(BadRequest()); } _context.Entry(countryLanguage).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CountryLanguageExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void CountryLanguageConstructor_CreatesInstanceOfCountryLanguage_CountryLanguage() { //Arrange CountryLanguage testCountryLanguage = new CountryLanguage("TST", "test-language", true, 4.0f); //Act and Assert Assert.AreEqual(typeof(CountryLanguage), testCountryLanguage.GetType()); }
/// <summary> /// </summary> /// <returns>Return default language English</returns> public static CountryLanguage GetDefaultLanguage() { if (_engLanguage == null) { _engLanguage = GetLanguages().FirstOrDefault(n => n.Code == "en"); } return(_engLanguage); }
public async void UnassignCountryLanguage(int countryId, int languageId) { CountryLanguage countryLanguage = await FindByCountryIdAndLanguageId(countryId, languageId); if (countryLanguage != null) { Remove(countryLanguage); } }
//Delete From DB public void Delete(CountryLanguage countryLanguage) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; db.spDesktopDataAdmin_DeleteCountryLanguage_v1( countryLanguage.CountryCode, countryLanguage.LanguageCode, adminUserGuid, countryLanguage.VersionNumber ); }
//Add to DB public void Add(CountryLanguage countryLanguage) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; db.spDesktopDataAdmin_InsertCountryLanguage_v1( countryLanguage.CountryCode, countryLanguage.LanguageCode, countryLanguage.CountryName, adminUserGuid ); }
public async Task AssignCountryLanguage(int countryId, int languageId) { CountryLanguage countryLanguage = await FindByCountryIdAndLanguageId(countryId, languageId); if (countryLanguage == null) { countryLanguage = new CountryLanguage { CountryId = countryId, LanguageId = languageId }; await AddAsync(countryLanguage); } }
private MenuOptionResult ListLanguages() { // TODO 16: Get the list of languages for this country (GetLanguages) IList <CountryLanguage> languages = countryLanguageDAO.GetLanguages(this.country.Code); SetColor(ConsoleColor.Blue); Console.WriteLine(CountryLanguage.GetHeader()); foreach (CountryLanguage language in languages) { Console.WriteLine(language); } ResetColor(); return(MenuOptionResult.WaitAfterMenuSelection); }
//Add Data From Linked Tables for Display public void EditItemForDisplay(CountryLanguage countryLanguage) { //Add LanguageName if (countryLanguage.LanguageCode != null) { LanguageRepository languageRepository = new LanguageRepository(); Language language = new Language(); language = languageRepository.GetLanguage(countryLanguage.LanguageCode); if (language != null) { countryLanguage.LanguageName = language.LanguageName; } } }
public async Task <CountryLanguageResponse> UnassignCountryLanguageAsync(int countryId, int languageId) { try { CountryLanguage countryLanguage = await _countryLanguageRepository.FindByCountryIdAndLanguageId(countryId, languageId); _countryLanguageRepository.Remove(countryLanguage); await _unitOfWork.CompleteAsync(); return(new CountryLanguageResponse(countryLanguage)); } catch (Exception ex) { return(new CountryLanguageResponse($"An error ocurred while unassigning Language to Country: {ex.Message}")); } }
public void GetLanguage_ReturnsLanguage_String() { //Arrange string inputCountryCode = "TST"; string inputLanguage = "test-Language"; bool inputIsOfficial = true; float inputPercentage = 4.0f; CountryLanguage testCountryLanguage = new CountryLanguage(inputCountryCode, inputLanguage, inputIsOfficial, inputPercentage); //Act string resultLanguage = testCountryLanguage.GetLanguage(); //Assert Assert.AreEqual("test-Language", resultLanguage); }
public ActionResult Delete(string id, string languageCode, FormCollection collection) { //Get Item CountryLanguage countryLanguage = new CountryLanguage(); countryLanguage = countryLanguageRepository.GetItem(id, languageCode); //Check Exists if (countryLanguage == null) { ViewData["ActionMethod"] = "EditPost"; return(View("RecordDoesNotExistError")); } //AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToReferenceInfo()) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Delete Item try { countryLanguage.VersionNumber = Int32.Parse(collection["VersionNumber"]); countryLanguageRepository.Delete(countryLanguage); } catch (SqlException ex) { //Versioning Error - go to standard versionError page if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/CountryLanguage.mvc/Delete?id=" + countryLanguage.CountryCode + "&languageCode=" + countryLanguage.LanguageCode; return(View("VersionError")); } //Generic Error ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } //Return return(RedirectToAction("List", new { id = countryLanguage.CountryCode })); }
public ActionResult Create(CountryLanguage countryLanguage) { Country country = new Country(); country = countryRepository.GetCountry(countryLanguage.CountryCode); //Check Exists if (country == null) { ViewData["ActionMethod"] = "CreatePost"; return(View("RecordDoesNotExistError")); } RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToReferenceInfo()) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Update Model from Form try { UpdateModel(countryLanguage); } catch { string n = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { n += error.ErrorMessage; } } ViewData["Message"] = "ValidationError : " + n; return(View("Error")); } countryLanguageRepository.Add(countryLanguage); return(RedirectToAction("List", new { id = countryLanguage.CountryCode })); }
public bool Update(CountryVM countryVm) { var result = new Country { CountryId = countryVm.Id, Code = countryVm.Code, CountryLanguages = new List <CountryLanguage>() }; var item = new CountryLanguage(); item.CountryId = countryVm.Id; item.Name = countryVm.Name; item.Language = countryVm.Language ?? _userInfo.CurrentLanguage; item.CountryLanguageId = countryVm.LanguageId ?? Guid.NewGuid(); result.CountryLanguages.Add(item); return(_countryDal.Update(result)); }
public void InsertAllLangauges(string locationOfJson) { jsonLanguage = ReadJson(locationOfJson); var jArray = JArray.Parse(jsonLanguage); allLanguages = jArray[0].ToList(); foreach (var language in allLanguages) { string code = ((Newtonsoft.Json.Linq.JProperty)(language)).Name; string languageName = (string)language.First["name"]; string nativeName = (string)language.First["nativeName"]; var ln = new CountryLanguage(); ln.Code = code; ln.Language = languageName; ln.NativeName = nativeName; db.CountryLanguages.Add(ln); } db.SaveChanges(null, "InsertAllLangauges"); Console.WriteLine("Done Language Database adding."); }
public void SetLanguage_UpdatesLanguage_Void() { //Arrange string inputCountryCode = "TST"; string inputLanguage = "test-Language"; bool inputIsOfficial = true; float inputPercentage = 4.0f; CountryLanguage testCountryLanguage = new CountryLanguage(inputCountryCode, inputLanguage, inputIsOfficial, inputPercentage); //Act string inputLanguageUpdate = "test-Language01"; testCountryLanguage.SetLanguage(inputLanguageUpdate); string resultLanguage = testCountryLanguage.GetLanguage(); //Assert Assert.AreEqual("test-Language01", resultLanguage); }
public void SetIsOfficial_UpdatesIsOfficial_Void() { //Arrange string inputCountryCode = "TST"; string inputLanguage = "test-Language"; bool inputIsOfficial = true; float inputPercentage = 4.0f; CountryLanguage testCountryLanguage = new CountryLanguage(inputCountryCode, inputLanguage, inputIsOfficial, inputPercentage); //Act bool inputIsOfficialUpdate = false; testCountryLanguage.SetIsOfficial(inputIsOfficialUpdate); bool resultIsOfficial = testCountryLanguage.GetIsOfficial(); //Assert Assert.AreEqual(false, resultIsOfficial); }
// GET: /Create public ActionResult Create(string id) { //Get Country Country country = new Country(); country = countryRepository.GetCountry(id); //Check Exists if (country == null) { ViewData["ActionMethod"] = "CreateGet"; return(View("RecordDoesNotExistError")); } //AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToReferenceInfo()) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Parent data ViewData["CountryCode"] = id; ViewData["CountryName"] = country.CountryName; //New CountryLanguage CountryLanguage countryLanguage = new CountryLanguage(); countryLanguage.CountryCode = id; countryLanguageRepository.EditItemForDisplay(countryLanguage); //Language SelectList SelectList languageList = new SelectList(countryLanguageRepository.GetUnUsedLanguages(id).ToList(), "LanguageCode", "LanguageName"); ViewData["Languages"] = languageList; //Show Create Form return(View(countryLanguage)); }
public async Task <long> Handle(AddCountryCommand request, CancellationToken cancellationToken) { var currency = _mapper.Map <Currency>(request.Model.Currency); if (request.Model.Currency.Id == null) { _ = await _repository.CreateAsync(currency); } var country = _mapper.Map <Country>(request.Model); country.CurrencyId = currency.Id; var createdEntity = await _repository.CreateAsync(country); var langIds = request.Model.Languages .Where(l => l.Id != 0) .Select(l => l.Id) .ToList(); var languagesToCreate = request.Model.Languages.Where(l => l.Id == 0); if (languagesToCreate.Any()) { var languageEntities = _mapper.Map <IEnumerable <Language> >(languagesToCreate); var ids = await _repository.CreateAsync(languageEntities); langIds.AddRange(ids); } foreach (var langId in langIds) { var countryLanguage = new CountryLanguage { CountryId = createdEntity.Id, LanguageId = langId }; _ = await _repository.CreateAsync(countryLanguage); } return(createdEntity.Id); }
/// <summary> /// /// </summary> /// <returns></returns> internal DataSetReport[] ToArray() { IEnumerable <DataSetReport> results = from cont in Continent.AsEnumerable() join coun in Country.AsEnumerable() on cont.ContinentID equals coun.ContinentID join cl in CountryLanguage.AsEnumerable() on coun.CountryID equals cl.CountryID join lang in Language.AsEnumerable() on cl.LanguageID equals lang.LanguageID join cu in CountryCardProcessorUrls.AsEnumerable() on coun.CountryID equals cu.CountryID join cpu in CardProcessorUrl on cu.CardProcessorUrlID equals cpu.CardProcessorUrlID join cp in CountryPhone.AsEnumerable() on coun.CountryID equals cp.CountryID join cpp in CardProcessorPhone.AsEnumerable() on cp.CardProcessingPhoneID equals cpp.CardProcessorPhoneID join cctd in CountryCardTypeDevice.AsEnumerable() on coun.CountryID equals cctd.CountryID join ct in CardType.AsEnumerable() on cctd.CardTypeID equals ct.CardTypeID join crd in CardReaderDevice.AsEnumerable() on cctd.CardReaderDeviceID equals crd.CardReaderDeviceID select new DataSetReport { ContinentName = cont.Name, CountryName = coun.Name, LanguageName = lang.Name, URLName = cpu.Name, URLValue = cpu.Value, PhoneName = cpp.Name, PhoneValue = cpp.Value, CardTypeName = ct.Name, DeviceName = crd.Name }; return(results.ToArray()); }
// GET: /Delete public ActionResult ViewItem(string id, string languageCode) { //Get Item CountryLanguage countryLanguage = new CountryLanguage(); countryLanguage = countryLanguageRepository.GetItem(id, languageCode); //Check Exists if (countryLanguage == null) { ViewData["ActionMethod"] = "DeleteGet"; return(View("RecordDoesNotExistError")); } //Parent data ViewData["CountryCode"] = id; ViewData["CountryName"] = countryLanguage.Country.CountryName; countryLanguageRepository.EditItemForDisplay(countryLanguage); return(View(countryLanguage)); }
public List <CountryLanguage> GetLanguages(string countryCode) { List <CountryLanguage> languages = new List <CountryLanguage>(); try { // Create a db connection using (SqlConnection conn = new SqlConnection(connectionString)) { // Open the connection conn.Open(); // Create a command for the statement SqlCommand cmd = new SqlCommand(SQL_GETLANGUAGESBYCOUNTRY, conn); cmd.Parameters.AddWithValue("@countryCode", countryCode); // Execute and get a data reader SqlDataReader rdr = cmd.ExecuteReader(); // Loop through the result set and create City objects while (rdr.Read()) { CountryLanguage language = RowToObject(rdr); languages.Add(language); } } } catch { // Log this error // Re-throw so it can be caught up the stack throw; } return(languages); }
public ActionResult Edit(string id, string languageCode, FormCollection formCollection) { //Get Item CountryLanguage countryLanguage = new CountryLanguage(); countryLanguage = countryLanguageRepository.GetItem(id, languageCode); //Check Exists if (countryLanguage == null) { ViewData["ActionMethod"] = "EditPost"; return(View("RecordDoesNotExistError")); } //AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToReferenceInfo()) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Update Item from Form try { UpdateModel(countryLanguage); } catch { string n = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { n += error.ErrorMessage; } } ViewData["Message"] = "ValidationError : " + n; return(View("Error")); } //Update AirlineAdvice try { countryLanguageRepository.Update(countryLanguage); } catch (SqlException ex) { //Versioning Error if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/CountryLanguage.mvc/Edit?id=" + countryLanguage.CountryCode + "&languageCode=" + countryLanguage.LanguageCode; return(View("VersionError")); } //Generic Error ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } return(RedirectToAction("List", new { id = countryLanguage.CountryCode })); }
public async Task <ActionResult> PopulateDatabase() { if (this.context.Countries.Any() == false) { var httpClient = new HttpClient(); var countriesAsString = await httpClient.GetStringAsync("https://restcountries.eu/rest/v2/all"); var countriesAsJson = JsonConvert.DeserializeObject <List <CountryCreateApiBindingModel> >(countriesAsString); foreach (var countryCreateModel in countriesAsJson) { var country = new Country { Name = countryCreateModel.Name, Alpha2Code = countryCreateModel.Alpha2Code, Aplha3Code = countryCreateModel.Aplha3Code, Capital = countryCreateModel.Capital, Region = countryCreateModel.Region, SubRegion = countryCreateModel.SubRegion, Population = countryCreateModel.Population, Demonym = countryCreateModel.Demonym, Area = countryCreateModel.Area, Gini = countryCreateModel.Gini, NativeName = countryCreateModel.NativeName, NumericCode = countryCreateModel.NumericCode, FlagUrl = countryCreateModel.FlagUrl, Cioc = countryCreateModel.Cioc, }; foreach (var internetDomainAsString in countryCreateModel.Domains) { var internetDomain = new InternetDomain { Name = internetDomainAsString, Country = country }; this.context.InternetDomains.Add(internetDomain); } foreach (var callingCodeAsString in countryCreateModel.CallingCodes) { var callingCode = new CallingCode { Name = callingCodeAsString, CountryId = country.Id }; this.context.CallingCodes.Add(callingCode); } foreach (var altSpellingAsString in countryCreateModel.AlternativeSpellings) { var alternativeSpelling = new AlternativeSpelling { Name = altSpellingAsString, Country = country }; this.context.AlternativeSpellings.Add(alternativeSpelling); } if (countryCreateModel.Coordinates.Count == 2) { var coordinates = new Coordinates { Latitude = countryCreateModel.Coordinates[0], Longitude = countryCreateModel.Coordinates[1] }; country.Coordinates = coordinates; } else { var coordinates = new Coordinates { Latitude = 50, Longitude = 50 }; country.Coordinates = coordinates; } foreach (var timeZomeAsString in countryCreateModel.TimeZones) { var timeZone = new Countries.Domain.TimeZone { Name = timeZomeAsString }; if (this.context.TimeZones.Any(tz => tz.Name == timeZone.Name) == false) { this.context.TimeZones.Add(timeZone); var countryTimeZone = new CountryTimeZone { Country = country, TimeZone = timeZone }; this.context.CountryTimeZone.Add(countryTimeZone); } } foreach (var borderAsString in countryCreateModel.Borders) { var border = new Border { Name = borderAsString }; if (this.context.Borders.Any(tz => tz.Name == border.Name) == false) { this.context.Borders.Add(border); var countryBorder = new CountryBorder { Country = country, Border = border }; this.context.CountryBorder.Add(countryBorder); } } foreach (var currencyCreateModel in countryCreateModel.Currencies) { var currency = new Currency { Code = currencyCreateModel.Code, Name = currencyCreateModel.Name, Symbol = currencyCreateModel.Symbol }; if (this.context.Currencies.Any(c => c.Code == currency.Code) == false) { this.context.Currencies.Add(currency); var countryCurrency = new CountryCurrency { Country = country, Currency = currency }; this.context.CountryCurrency.Add(countryCurrency); } } foreach (var languageCreateModel in countryCreateModel.Languages) { var language = new Language { Iso639_1 = languageCreateModel.Iso639_1, Iso639_2 = languageCreateModel.Iso639_2, Name = languageCreateModel.Name, NativeName = languageCreateModel.NativeName, }; if (this.context.Languages.Any(l => l.Name == language.Name) == false) { this.context.Languages.Add(language); var countryLanguage = new CountryLanguage { Country = country, Language = language }; this.context.CountryLanguage.Add(countryLanguage); } } var translations = new Translations { De = countryCreateModel.Translations.De, Es = countryCreateModel.Translations.Es, Fr = countryCreateModel.Translations.Fr, Ja = countryCreateModel.Translations.Ja, It = countryCreateModel.Translations.It, Br = countryCreateModel.Translations.Br, Pt = countryCreateModel.Translations.Pt, Nl = countryCreateModel.Translations.Nl, Hr = countryCreateModel.Translations.Hr, Fa = countryCreateModel.Translations.Fa, }; country.Translations = translations; foreach (var blockCreateModel in countryCreateModel.Blocks) { var regionalBlock = new RegionalBlock { Acronym = blockCreateModel.Acronym, Name = blockCreateModel.Name }; if (this.context.RegionalBlocks.Any(rb => rb.Name == regionalBlock.Name) == false) { this.context.RegionalBlocks.Add(regionalBlock); var countryRegionalBlock = new CountryRegionalBlock { Country = country, RegionalBlock = regionalBlock }; this.context.CountryRegionalBlock.Add(countryRegionalBlock); } } this.context.Countries.Add(country); this.context.SaveChanges(); } return(this.Ok($"Successfully populated table with {this.context.Countries.Count()} countries.")); } return(this.Ok("Database is already populated.")); }
public ActionResult LanguagesList() { List <CountryLanguage> listOfAllLanguages = CountryLanguage.GetAll(); return(View("Languages", listOfAllLanguages)); }