Example #1
0
        public void Initialize(string csvFilePath)
        {
            CsvReader reader = new CsvReader(csvFilePath);

            this.AllCountries = reader.ReadAllCountries().OrderBy(x => x.Name).ToList();

            this.AllCountriesByKey = AllCountries.ToDictionary(x => x.Code, StringComparer.OrdinalIgnoreCase); // add statndart comparator to ignore case

            this.AllCountriesCCByKey = AllCountries.ToDictionary(x => x.CountryCode);

            this.AllCountriesByKeySorted = new SortedDictionary <string, Country>(AllCountriesByKey);

            this.AllCountriesByKeySortedList = new SortedList <string, Country>(AllCountriesByKey);
        }
Example #2
0
    private void BindDataCountriesToDDL()
    {
        var dictlist = new Dictionary <string, string>();

        foreach (string s in GeolocationUtils.GeoCountData.Keys)
        {
            dictlist.Add(s, s + " (" + GeolocationUtils.GeoCountData[s] + ")");
        }

        AllCountries.DataSource     = dictlist;
        AllCountries.DataTextField  = "Value";
        AllCountries.DataValueField = "Key";
        AllCountries.DataBind();
    }
Example #3
0
 public async void Search()
 {
     if (SearchText != String.Empty)
     {
         AllCountries =
             new ObservableCollection <Country>(
                 AllCountries
                 .Where(x => x.ID.Contains(_searchText) || x.CurrencyID.Contains(SearchText))
                 .ToList());
     }
     else
     {
         await LoadCountries();
     }
 }
Example #4
0
 public PlayerViewModel(Player player, IEnumerable <Country> countries) : this(player, true)
 {
     this.SelectedCountries = new bool[countries.Count()];
     foreach (Country tempCountry in countries)
     {
         AllCountries.Add(new CountryViewModel(tempCountry));
         bool tempBool = false;
         foreach (CountryPlayer tempCountryPlayer in player.CountryPlayers)
         {
             if (tempCountryPlayer.CountryId == tempCountry.CountryId)
             {
                 tempBool = true;
             }
         }
         SelectedCountries[AllCountries.Count - 1] = tempBool;
     }
 }
Example #5
0
    private void BindDataCountriesToDDL()
    {
        var dictlist = GeolocationUtils.GetCountriesData();

        if (PageRequest == RequestType.Edit)
        {
            var geolocated = new Dictionary <string, string>();

            var ad = new PtcAdvert(Convert.ToInt32(ViewState["editid"]));
            if (ad.IsGeolocatedByCountry)
            {
                var countries = ad.GeolocatedCC.Split(',');
                foreach (var country in countries)
                {
                    if (string.IsNullOrEmpty(country))
                    {
                        continue;
                    }

                    var countryName = CountryManager.GetCountryName(country);
                    dictlist.Remove(countryName);

                    var geolocatedCountry = GeolocationUtils.GetCountryData(countryName);
                    geolocated.Add(geolocatedCountry.Item1, geolocatedCountry.Item2);
                }
                GeoCountries.DataSource     = geolocated;
                GeoCountries.DataTextField  = "Value";
                GeoCountries.DataValueField = "Key";
                GeoCountries.DataBind();
            }
        }
        AllCountries.DataSource     = dictlist;
        AllCountries.DataTextField  = "Value";
        AllCountries.DataValueField = "Key";
        AllCountries.DataBind();
    }
Example #6
0
        static CountryDatabase()
        {
            CountriesByAlpha2Code = AllCountries.ToDictionary(c => c.Alpha2Code, c => c);

            CountriesByAlpha3Code = AllCountries.ToDictionary(c => c.Alpha3Code, c => c);
        }
        public void Run()
        {
            CsvReader reader = new CsvReader(@".\Resources\PopByLargest.csv");

            this.AllCountries = reader.ReadAllCountries().OrderBy(x => x.Name).ToList();
            var dict = AllCountries.ToDictionary(x => x.Code);

            this.AllCountriesByKey = dict;

            Console.WriteLine("-----------------ADD-------------------------");
            Country selectedCountry  = AllCountries[4];
            Country selectedCountry1 = AllCountries[14];
            Country selectedCountry2 = AllCountries[24];
            Country selectedCountry3 = AllCountries[34];

            //Add at the end of LL
            this.ItineraryBuilder.AddLast(selectedCountry);
            var change = new ItineraryChange(ChangeType.Append, this.ItineraryBuilder.Count, selectedCountry);

            this.ChangeLog.Push(change);

            this.ItineraryBuilder.AddLast(selectedCountry1);
            var change1 = new ItineraryChange(ChangeType.Append, this.ItineraryBuilder.Count, selectedCountry1);

            this.ChangeLog.Push(change1);

            this.ItineraryBuilder.AddLast(selectedCountry2);
            var change2 = new ItineraryChange(ChangeType.Append, this.ItineraryBuilder.Count, selectedCountry2);

            this.ChangeLog.Push(change2);

            this.ItineraryBuilder.AddLast(selectedCountry3);
            var change3 = new ItineraryChange(ChangeType.Append, this.ItineraryBuilder.Count, selectedCountry3);

            this.ChangeLog.Push(change3);

            foreach (var item in this.ItineraryBuilder)
            {
                Console.WriteLine($"{item.Code}:{item.Name}");
            }
            Console.WriteLine("---stack----");
            foreach (var item in ChangeLog)
            {
                Console.WriteLine(item);
            }


            Console.WriteLine("-----------------REMOVE-------------------------");
            int selectedIndex = 1;
            var nodeToRemove  = this.ItineraryBuilder.GetNthNode(selectedIndex);

            this.ItineraryBuilder.Remove(nodeToRemove);
            var change4 = new ItineraryChange(ChangeType.Remove, selectedIndex, nodeToRemove.Value);

            this.ChangeLog.Push(change4);
            foreach (var item in this.ItineraryBuilder)
            {
                Console.WriteLine($"{item.Code}:{item.Name}");
            }
            Console.WriteLine("---stack----");
            foreach (var item in ChangeLog)
            {
                Console.WriteLine(item);
            }


            Console.WriteLine("----------------------INSERT------------------------------");
            int selectedIndex1 = 1;

            this.AllCountriesByKey.TryGetValue(new CountryCode("USA"), out Country result);
            var insertBeforeNode = this.ItineraryBuilder.GetNthNode(selectedIndex1);

            this.ItineraryBuilder.AddBefore(insertBeforeNode, result);
            var change5 = new ItineraryChange(ChangeType.Insert, selectedIndex1, insertBeforeNode.Value);

            this.ChangeLog.Push(change5);
            foreach (var item in this.ItineraryBuilder)
            {
                Console.WriteLine($"{item.Code}:{item.Name}");
            }
            Console.WriteLine("---stack----");
            foreach (var item in ChangeLog)
            {
                Console.WriteLine(item);
            }


            Console.WriteLine("---------------------UNDO-------------------------------");
            ItineraryChange lastChange = this.ChangeLog.Pop();

            ChangeUndoer.Undo(this.ItineraryBuilder, lastChange);
            ItineraryChange lastChange2 = this.ChangeLog.Pop();

            ChangeUndoer.Undo(this.ItineraryBuilder, lastChange2);
            ItineraryChange lastChange3 = this.ChangeLog.Pop();

            ChangeUndoer.Undo(this.ItineraryBuilder, lastChange3);
            ChangeUndoer.Undo(this.ItineraryBuilder, this.ChangeLog.Pop());

            foreach (var item in this.ItineraryBuilder)
            {
                Console.WriteLine($"{item.Code}:{item.Name}");
            }
            Console.WriteLine("---stack----");
            foreach (var item in ChangeLog)
            {
                Console.WriteLine(item);
            }
        }
Example #8
0
 public static void AddCountry(Country c)
 {
     AllCountries.Add(c);
     AppDb.Countries.Add(c);
     AppDb.SaveChanges();
 }
        public void Run()
        {
            CsvReader reader = new CsvReader(@".\Resources\PopByLargest.csv");

            this.AllCountries      = reader.ReadAllCountries().OrderBy(x => x.Name).ToList();
            this.AllCountriesByKey = AllCountries.ToDictionary(x => x.Code);//List to Dictionary

            //SEARCH COUNTRY
            Console.WriteLine("-------------SEARCH COUNTRY (USA)------------------");
            //Country result1 = AllCountries.Find(x => x.Code == "USA");//O(N)
            this.AllCountriesByKey.TryGetValue("USA", out Country result);//O(1) //prefer   //case sensitive
            Console.WriteLine(result);

            //the search is case sensitive
            //Country result1 = AllCountries.Find(x => x.Code.ToUpper() == "usa".ToUpper());
            //like above, for list it is possible to use to upper
            //for DICTIONARY : if you want the dictionary to compare its KEYS in a way that its different from normal, you have to tell upfront at initialization time.
            //Reason is, inorder to give you the super efficient lookup, the dictionary needs to take into account how you want to lookup the keys when it's decides how to store its values internally.
            //it is done by passing the dectionary an "EQUALITY COMPARER"
            //EQUALITY COMPARER >Object that knows how to test for equality.
            //EQUALITY COMPARER implements IEqualityComparer<T>

            this.AllCountriesByKey = AllCountries.ToDictionary(x => x.Code, StringComparer.OrdinalIgnoreCase);
            Console.WriteLine("-------------SEARCH COUNTRY (usa) case insensitive------------------");
            this.AllCountriesByKey.TryGetValue("usa", out Country result2);//case insensitive
            Console.WriteLine(result);

            Console.WriteLine("------------------------------------------");
            this.AllCountries      = reader.ReadAllCountries().OrderBy(x => x.Name).ToList();
            this.AllCountriesByKey = AllCountries.ToDictionary(x => x.Code);
            //The order of the values in the dictionary is unspecified
            //you can't rely on the dictionary enumeration order
            //order works here since the list of sorted.so dictionary showed same order.
            //But there is no guarantee that it(order) is always be true with dictionary.since dictionary doesn't have any intrinsic order.
            //Relying on Dictionary order while enumerating is "not recommended".
            //Remedy: use SORTED DICTIONARY

            //-------------------------------------------------------------------------------------------------------
            //SortedDictionary<TKey,TValue>
            //Keyed access to items
            //automatically sorts items as it added to dictionary
            //Guaranteed sorted order when enumerating
            this.AllCountries = reader.ReadAllCountries().OrderBy(x => x.Name).ToList();
            var dict = AllCountries.ToDictionary(x => x.Code, StringComparer.OrdinalIgnoreCase); //List to Dictionary

            this.AllCountriesByKey1 = new SortedDictionary <string, Country>(dict);              //Dictionary to Sorted Dictionary
            //SortedDictionary sorts dictionary by KEY
            foreach (var item in AllCountriesByKey1)
            {//This enumeration is sorted by KEY
                Console.WriteLine($"{item.Key} : {item.Value}");
            }


            //----------------------------------------------------------------------------
            //this.AllCountriesByKey1=new SortedDictionary<string, Country>(dict);
            //OR
            //this.AllCountriesByKey1 = new SortedList<string, Country>(dict);

            //SORTEDLIST  is functionally exactly same as SORTEDdICTIONARY
            //difference in performance characteristics
            //SORTEDLIST uses less memory but scales worse for inserting and removing items
            //SORTEDdICTIONARY modifications scales better. O(logN) vs O(N)

            //always prefer SORTEDdICTIONARY

            //---------------------CUSTOM TYPE-----------CountryCode-------------
            Console.WriteLine("---------------------CUSTOM TYPE-----------CountryCode-------------");
            CsvReader1 reader1 = new CsvReader1(@".\Resources\PopByLargest.csv");

            this.AllCountries1 = reader1.ReadAllCountries().OrderBy(x => x.Name).ToList();
            var dict1 = AllCountries1.ToDictionary(x => x.Code);//StringComparer can't be used as Code is not string.it is CountryCode custom type

            this.AllCountriesByKey3 = dict1;
            this.AllCountriesByKey3.TryGetValue(new CountryCode("usa"), out Country1 country1);
            Console.WriteLine(country1); //empty
                                         //since it doesn't know how to compare "CountryCodes"  //since CountryCode is ref type is compare references.  //string is also a ref type but microsofts overridden that comparition to compare value
                                         //country1 works only if Equals,GetHashcode is implemented for "CountryCode"

            //Dictionary key can be any type. //generally string is used
            //to use customtype as key, you must override Equals & GetHashcode
        }
 /// <summary>
 /// Gets countries and airports from xml-file
 /// </summary>
 /// <returns> AllCountries with countries and airports </returns>
 public AllCountries DeserializeCountries(string path)
 {
     return(AllCountries.DeserialiseCountries(path));
 }
Example #11
0
        public SignUpPageViewModel(IAccountService accountService, Func <int, ConfirmationCodeEntryViewModel> createConfirmationCodeEntryViewModel, IDataFlow dataFlow, IViewService viewService, Func <IPhoneService> phoneService, IDeviceInfo deviceInfo, IConnectivity connectivity, IAppInfo appInfo)
        {
            this.accountService = accountService;
            this.createConfirmationCodeEntryViewModel = createConfirmationCodeEntryViewModel;
            this.dataFlow     = dataFlow;
            this.viewService  = viewService;
            this.phoneService = phoneService;
            this.deviceInfo   = deviceInfo;
            this.connectivity = connectivity;
            this.appInfo      = appInfo;
            SignUpCommand     = new XCommand(async() => await SignUp(), CanSignUp);

            BusinessName = new Property <string>("Buiness Name").RequiredString("Business Name is required");
            FirstName    = new Property <string>("First Name").RequiredString("First Name is required");
            LastName     = new Property <string>("Last Name").RequiredString("Last Name is required");
            Country      = new Property <CountryDetails>("Country").Required("Choose a country");
            MobileNumber = new Property <string>("Mobile Number").RequiredString("Mobile Number is required").RequiredFormat(@"^(\d|\s|-)*$", "Please just enter digits");
            EmailAddress = new Property <string>("Email Address").RequiredString("Email address is required");

            SignUpCommand.SetDependency(this, FirstName, LastName, MobileNumber, EmailAddress);

            AllCountries = CountriesData.List.OrderBy(c => c.CountryName).ToArray();
            var countryCode = GetCountryCode();
            var country     = AllCountries.SingleOrDefault(c => c.DialingCode == countryCode) ?? AllCountries.SingleOrDefault(c => c.CountryCode == "AU");

            Country.InitializeValue(country);
        }
 public Country GetCountryById(int countryId)
 {
     return(AllCountries.FirstOrDefault(p => p.CountryId == countryId));
 }
Example #13
0
 public IEnumerable <ProvinceModel> GetAllProvinces()
 {
     return(BuildProvinceCollection(AllCountries.Where(x => x.Provinces.Any())));
 }
        public void Run()
        {
            CsvReader1 reader = new CsvReader1(@".\Resources\PopByLargest.csv");

            this.AllCountries = reader.ReadAllCountries().OrderBy(x => x.Name).ToList();
            var dict = AllCountries.ToDictionary(x => x.Code);

            this.AllCountriesByKey = dict;

            //--------ADD----------
            Country1 selectedCountry = AllCountries[4];

            //Add at the end of LL
            this.ItineraryBuilder.AddLast(selectedCountry);  //O(1)
            this.ItineraryBuilder.AddLast(AllCountries[14]); //O(1)
            this.ItineraryBuilder.AddLast(AllCountries[24]); //O(1)
            this.ItineraryBuilder.AddLast(AllCountries[34]); //O(1)
            foreach (var item in this.ItineraryBuilder)
            {
                Console.WriteLine($"{item.Code}:{item.Name}");
            }

            Console.WriteLine("----------------------REMOVE------------------------------");
            var nodeToRemove = this.ItineraryBuilder.GetNthNode(1);

            this.ItineraryBuilder.Remove(nodeToRemove);
            foreach (var item in this.ItineraryBuilder)
            {
                Console.WriteLine($"{item.Code}:{item.Name}");
            }

            Console.WriteLine("----------------------INSERT------------------------------");
            this.AllCountriesByKey.TryGetValue(new CountryCode("USA"), out Country1 result);
            var insertBeforeNode = this.ItineraryBuilder.GetNthNode(1);

            this.ItineraryBuilder.AddBefore(insertBeforeNode, result);
            foreach (var item in this.ItineraryBuilder)
            {
                Console.WriteLine($"{item.Code}:{item.Name}");
            }

            Console.WriteLine("----------------------INSERT likedlist to array------------------------------");
            string tourName = "MyTour";

            Country1[] itinerary = this.ItineraryBuilder.ToArray();
            try
            {
                Tour tour = new Tour(tourName, itinerary);
                this.AllTours.Add(tourName, tour);//sorteddictionary throws exception if tourName already exists.(enforce unique names)
            }
            catch (Exception)
            {
                Console.WriteLine("cannot save tour");
            }
            this.ItineraryBuilder.Clear();//clear linked list

            foreach (var item in this.AllTours)
            {
                Console.WriteLine($"{item.Key}:");
                foreach (var value in this.AllTours[item.Key].Itinerary)
                {
                    Console.WriteLine(value);
                }
            }
        }
Example #15
0
        public bool IsCodeValid(string code, int id)
        {
            var result = AllCountries.Any(x => x.Code == code && x.Id != id);

            return(result);
        }
Example #16
0
 public Country Get(int Id)
 {
     return(AllCountries.SingleOrDefault(x => x.Id == Id));
 }