public List <CountryModel> GetCountryData() { var countryDetails = new CountryDetail(); var countryData = countryDetails.GetCountryData(); return(countryData); }
public CountryDetail GetCountry(string countryCode) { //owner? // https://docs.microsoft.com/en-us/dotnet/api/system.web.httpcontext.user?view=netframework-4.8 // https://docs.microsoft.com/en-us/dotnet/api/system.security.claims.claim?view=netcore-3.1 var user = User.Identity.Name; int id = -1; foreach (var claim in User.Claims) { if (claim.Type == "sub") { id = int.Parse(claim.Value); } } System.Diagnostics.Debug.WriteLine("".PadRight(20, '-') + " from GetCounty " + "".PadRight(20, '-')); System.Diagnostics.Debug.WriteLine("User: "******"User id: " + id); Country country = countryDAO.GetCountry(countryCode); CountryDetail countryDetail = new CountryDetail(country); //get news NewsAPIService newsAPIService = new NewsAPIService(); countryDetail = newsAPIService.GetCountry(countryDetail); return(countryDetail); }
private void TryLogin() { CountryDetail country = (CountryDetail)cbCountryID.SelectedItem; if (country == null) { this.ShowExclamation("Please select country first."); } else { Program.IsAdmin = (string.Compare(textBoxUsername.Text, "rosen") == 0) && (string.Compare(textBoxPassword.Text, "rosen") == 0); int countryId = country.Number; if (Program.IsAdmin) { Program.currentUser = new CurrentUser(0, textBoxUsername.Text, countryId); ServiceDataAccess.Instance.LogOperation(OperationHistory.Login, Program.SessionId, 0, 0, 0, 0, 0, ""); this.DialogResult = DialogResult.OK; StateSaver.Default.Set("textBoxUsername.Text", this.textBoxUsername.Text); } else { var auth = new AuthenticationSoapClient(); string result = auth.AuthenticateUser(countryId, textBoxUsername.Text, textBoxPassword.Text); if (!string.IsNullOrEmpty(result)) { var header = new AuthenticationRef.AuthenticationHeader(); var userId = auth.RetrieveUser(header, countryId, textBoxUsername.Text); Program.currentUser = new CurrentUser(userId, textBoxUsername.Text, countryId); ServiceDataAccess.Instance.LogOperation(OperationHistory.Login, Program.SessionId, 0, 0, 0, 0, 0, ""); this.DialogResult = DialogResult.OK; StateSaver.Default.Set("textBoxUsername.Text", this.textBoxUsername.Text); } else { //Speeker.SpeakAsynchSf("Invalid user id or password, please try again."); this.ShowExclamation("Invalid user id or password, please try again."); textBoxPassword.Text = ""; textBoxPassword.Focus(); } } } }
public CountryDetail GetCountry(string countryCode) { Country country = countryDao.GetCountry(countryCode); CountryDetail countryDetail = new CountryDetail(country); //get news NewsAPIService newsAPIService = new NewsAPIService(); countryDetail = newsAPIService.GetCountry(countryDetail); return(countryDetail); }
public CountryDetail GetCountry(CountryDetail detail) { RestRequest request = new RestRequest(API_START + detail.Name + API_END); IRestResponse <News> response = client.Get <News>(request); if (response.ResponseStatus != ResponseStatus.Completed) { throw new Exception("Error occurred - unable to reach server."); } else if (!response.IsSuccessful) { throw new Exception("Error occurred - received non-success response: " + (int)response.StatusCode); } else { try { //add news stories News news = response.Data; foreach (Article article in news.Articles) { string temp = ""; temp = (article.Title != null) ? temp + article.Title : temp; temp += " - "; temp = (article.Author != null) ? temp + article.Author : temp; temp += " - "; int length = 200; if (article.Content != null && article.Content.Length < 200) { length = article.Content.Length; } temp = (article.Content != null) ? temp + article.Content.Substring(0, length) : temp; detail.Stories.Add(temp); } } catch (Exception ex) { throw new Exception("Error occurred - getting news stories " + ex.Message); } return(detail); } }
private void TryLogin() { CountryDetail country = (CountryDetail)cbCountryID.SelectedItem; if (country == null) { this.ShowExclamation("Please select country first."); } else { Program.IsAdmin = (string.Compare(textBoxUsername.Text, "rosen") == 0) && (string.Compare(textBoxPassword.Text, "rosen") == 0); int countryId = country.Number; if (Program.IsAdmin) { SaveCurrentUser(0, countryId, false); } else { var auth = new Authentication.Authentication(); string result = auth.AuthenticateUser(countryId, textBoxUsername.Text, textBoxPassword.Text); if (!string.IsNullOrEmpty(result)) { var userId = auth.RetrieveUser(countryId, textBoxUsername.Text); SaveCurrentUser(userId, countryId, false); } else { var security = new Security(); bool result2 = security.DomainValidate("fintrax", textBoxUsername.Text, textBoxPassword.Text); if (result2) { SaveCurrentUser(-100, countryId, true); } else { Speeker.SpeakAsynchSf("Invalid user id or password, please try again."); this.ShowExclamation("Invalid user id or password, please try again."); textBoxPassword.Text = ""; textBoxPassword.Focus(); } } } } }
public CountryDetail GetCountryAccumData(string countryCode) { if (dataStore == null || dataStore.Accumulated == null) { throw new FieldAccessException( "Data cannot be accessed, since it was not loaded yet.\n" + "Please call DataLoader.LoadAllData() first."); } CountryDetail countrydata = dataStore.Accumulated.Countries.Find(item => item.CountryCode == countryCode); if (countrydata == null) { throw new ArgumentException( $"Countrycode {countryCode} was not found in the currently loaded dataset!"); } return(countrydata); }
private void GetCountry() { try { string countryCode = ConsoleHelper.GetString("Enter the country code that you want to retrieve:"); CountryDetail country = countryAPIService.GetCountry(countryCode); Console.WriteLine("Code: " + country.Code); Console.WriteLine("Name: " + country.Name); Console.WriteLine("Continent: " + country.Continent); Console.WriteLine("Region: " + country.Region); Console.WriteLine("Surface area: " + country.SurfaceArea); Console.WriteLine("Independence year: " + country.IndependenceYear); Console.WriteLine("Population: " + country.Population); Console.WriteLine("Life expectancy: " + country.LifeExpectancy); //<-- nullable property, it can have a value that is a double or NULL if there is no value Console.WriteLine("GNP: " + country.GNP); //<-- nullable property, it can have a value that is a decimal or NULL if there is no value Console.WriteLine("Local name: " + country.LocalName); Console.WriteLine("Government form: " + country.GovernmentForm); Console.WriteLine("Head of state: " + country.HeadOfState); Console.WriteLine("Capital ID : " + country.CapitalId); //<-- nullable property, it can have a value that is a int or NULL if there is no value Console.WriteLine("Codes: " + country.Code2); Console.WriteLine(); foreach (string item in country.Stories) { Console.WriteLine(item); Console.WriteLine(); } Console.WriteLine(); Console.WriteLine(); } catch { Console.WriteLine("Unable to process request."); Console.WriteLine(); } }