Пример #1
0
        public CountryView Get(int id, string curlang)
        {
            IList <Country> res      = _cache.Get("contries") as IList <Country>;
            var             cnt      = res.Where(x => x.ID == id).First();
            var             brd      = cnt.BorderingCountries;
            CountryView     cntvw    = new CountryView();
            IList <string>  brdcount = new List <string>();

            if (brd.Count > 0)
            {
                foreach (string tmp in brd)
                {
                    if (curlang.Equals("en"))
                    {
                        brdcount.Add(res.Where(x => x.Alpha3Code == tmp).Select(s => s.Name).First());
                    }
                    else
                    {
                        brdcount.Add(res.Where(x => x.Alpha3Code == tmp).Select(s => s.Translations).First().FirstOrDefault(kvp => kvp.Key.Contains(curlang)).Value.Replace("\"", String.Empty).Replace("null", "N/A").ToString());
                    }
                }
            }
            cntvw.ID                 = cnt.ID;
            cntvw.Alpha3Code         = cnt.Alpha3Code;
            cntvw.Capital            = cnt.Capital;
            cntvw.Name               = cnt.Name;
            cntvw.BorderingCountries = brdcount;
            return(cntvw);
        }
        public async Task <ActionResult <CountryView> > PostCountryView(CountryView countryView)
        {
            _context.countryViews.Add(countryView);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCountryView", new { id = countryView.CvID }, countryView));
        }
Пример #3
0
        public void Test()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            IDataProvider <CountryInfoEx> provider = new MockDataProviderEx();

            IReadOnlyList <CountryInfoEx> data = provider.GetCountryData();

            Form form = new Form();

            form.Width  = 800;
            form.Height = 600;

            IView view = new CountryView(data);

            TabControl tabControl = new TabControl();

            tabControl.Controls.Add(view.GetPage());

            form.Controls.Add(tabControl);
            tabControl.Dock = DockStyle.Fill;

            Application.Run(form);
        }
        public async Task <IActionResult> PutCountryView(int id, CountryView countryView)
        {
            if (id != countryView.CvID)
            {
                return(BadRequest());
            }

            _context.Entry(countryView).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CountryViewExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #5
0
        public void Edit(CountryView view)
        {
            Country country = UnitOfWork.To <Country>(view);

            UnitOfWork.Update(country);
            UnitOfWork.Commit();
        }
Пример #6
0
        public void Create(CountryView view)
        {
            Country country = UnitOfWork.To <Country>(view);

            UnitOfWork.Insert(country);
            UnitOfWork.Commit();
        }
Пример #7
0
        public List <CountryView> GetCountryBySearchTerm(string term)
        {
            string query = "SELECT * FROM CountryView WHERE Name LIKE '%" + term + "%'";

            connection.ConnectionString = connectionString;

            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();

            SqlDataReader reader = command.ExecuteReader();

            List <CountryView> countries = new List <CountryView>();
            int sl = 1;

            while (reader.Read())
            {
                CountryView countryView = new CountryView();

                //countryView.Id = int.Parse(reader["Id"].ToString());
                countryView.Name         = reader["Name"].ToString();
                countryView.About        = reader["About"].ToString();
                countryView.NoOfCity     = int.Parse(reader["TotalCity"].ToString());
                countryView.NoOfDwellers = int.Parse(reader["TotalDwellers"].ToString());
                countryView.SerialNo     = sl++;
                countries.Add(countryView);
            }

            reader.Close();
            connection.Close();

            return(countries);
        }
Пример #8
0
        internal void Edit()
        {
            CountryView view = new CountryView(this);

            view.ShowDialog();
            CurrentCountry = view.Country;
        }
 public static CountryBll Map(this CountryView country)
 {
     return(new CountryBll
     {
         Id = country.Id,
         Name = country.Name
     });
 }
Пример #10
0
        private void CountryButton_Click(object sender, EventArgs e)
        {
            CountryView       countryView       = new CountryView();
            CountryService    countryService    = new CountryService();
            IList             countryList       = countryService.getAllCountries();
            CountryController countryController = new CountryController(countryView, countryList);

            countryController.LoadView();
            countryView.ShowDialog();
        }
Пример #11
0
        public void Get_ReturnsViewById()
        {
            CountryView actual   = service.Get <CountryView>(country.Id);
            CountryView expected = Mapper.Map <CountryView>(country);

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.Id, actual.Id);

            Assert.True(false, "Not all properties tested");
        }
Пример #12
0
        public ActionResult Edit(CountryView country)
        {
            if (!Validator.CanEdit(country))
            {
                return(View(country));
            }

            Service.Edit(country);

            return(RedirectIfAuthorized("Index"));
        }
Пример #13
0
        public ActionResult Create([Bind(Exclude = "Id")] CountryView country)
        {
            if (!Validator.CanCreate(country))
            {
                return(View(country));
            }

            Service.Create(country);

            return(RedirectIfAuthorized("Index"));
        }
Пример #14
0
        internal void New()
        {
            CurrentCountry = new Country();
            CountryView view = new CountryView(this);

            view.ShowDialog();
            if (view.Accept)
            {
                Countries.Add(view.Country);
            }
        }
Пример #15
0
 private void GetFocusedRowData(int index)
 {
     if (index >= 0 && CountryView.RowCount > 0)
     {
         CountryView.FocusedRowHandle = index;
         btnSave.Enabled     = false;
         btnAddNew.Enabled   = btnModify.Enabled = true;
         txtCountryCode.Text = CountryView.GetRowCellValue(index, CountryManager.CountryDetails.CountryCode.ToString()).ToString();
         txtCountryName.Text = CountryView.GetRowCellValue(index, CountryManager.CountryDetails.CountryName.ToString()).ToString();
     }
 }
Пример #16
0
        public CountriesControllerTests()
        {
            validator = Substitute.For <ICountryValidator>();
            service   = Substitute.For <ICountryService>();

            country = ObjectFactory.CreateCountryView();

            controller = Substitute.ForPartsOf <CountriesController>(validator, service);
            controller.ControllerContext = new ControllerContext {
                RouteData = new RouteData()
            };
        }
Пример #17
0
        internal void Find()
        {
            StringDialog dialog = new StringDialog("A country abbreviation");

            dialog.ShowDialog();
            if (dialog.Accept)
            {
                string abbrev = dialog.YourString;
                CurrentCountry = _countryRepository.GetByAbbreviation(abbrev);
                CountryView view = new CountryView(this);
                view.ShowDialog();
            }
        }
Пример #18
0
        public void Create_Country()
        {
            CountryView view = ObjectFactory.CreateCountryView(1);

            service.Create(view);

            Country     actual   = context.Set <Country>().AsNoTracking().Single(model => model.Id != country.Id);
            CountryView expected = view;

            Assert.Equal(expected.CreationDate, actual.CreationDate);

            Assert.True(false, "Not all properties tested");
        }
Пример #19
0
    public void UpdateCountry(CountryModel src)
    {
        CountryModel CountryModel = this.GetComponent <CountryModel>();
        CountryView  CountryView  = this.GetComponent <CountryView>();

        CountryModel.CurrencyName       = src.CurrencyName;
        CountryModel.Flag               = src.Flag;
        CountryModel.CurrencyMultiplier = src.CurrencyMultiplier;
        CountryModel.CurMoney           = src.CurMoney;

        //Debug.Log(this.name + ":UpdateCountry:" + CountryModel.CurrencyName);
        CountryView.OnUpdateCountry();
    }
Пример #20
0
        public async Task <IActionResult> Create([Bind(properties)] CountryView c)
        {
            await validateId(c.Alpha3Code, ModelState);

            if (!ModelState.IsValid)
            {
                return(View(c));
            }
            var o = CountryFactory.Create(c.Alpha3Code, c.Name, c.Alpha2Code, c.ValidFrom,
                                          c.ValidTo);
            await reporitory.AddObject(o);

            return(RedirectToAction("Index"));
        }
Пример #21
0
        public List <CountryView> GetByCountryName(string countrySearchName)
        {
            connection.ConnectionString = connectionString;
            string query = "SELECT * FROM CountryView WHERE (CountryName LIKE '%'+@countrySearchName+'%')";
            //(CityName LIKE '%'+@citySearchName+'%')";


            SqlCommand command = new SqlCommand(query, connection);

            //command.Parameters.Add("citySearchName", SqlDbType.VarChar);
            //command.Parameters["citySearchName"].Value = citySearchName;
            command.Parameters.Add("countrySearchName", SqlDbType.VarChar);
            command.Parameters["countrySearchName"].Value = countrySearchName;

            List <CountryView> countryList = new List <CountryView>();

            connection.Open();
            SqlDataReader reader      = command.ExecuteReader();
            CountryView   countryView = null;

            while (reader.Read())
            {
                countryView = new CountryView();
                //countryView.Id = (int) reader["id"];
                countryView.Name       = reader["CountryName"].ToString();
                countryView.About      = reader["CountryAbout"].ToString();
                countryView.NoOfCities = Convert.ToInt32(reader["NoOfCities"].ToString());
                if (!reader["NoOfDwellers"].Equals(System.DBNull.Value))
                {
                    countryView.NoOfDwellers = reader.GetInt64(reader.GetOrdinal("NoOfDwellers"));
                }
                else
                {
                    countryView.NoOfDwellers = 0;
                }

                //aBook.Id = (int)reader["id"];
                //aBook.Isbn = reader["Isbn"].ToString();
                //aBook.CountryName = reader["CountryName"].ToString();
                //aBook.Author = reader["Author"].ToString();

                countryList.Add(countryView);
            }
            reader.Close();
            connection.Close();

            return(countryList);
        }
Пример #22
0
        public async Task <IActionResult> Edit([Bind(properties)] CountryView c)
        {
            if (!ModelState.IsValid)
            {
                return(View(c));
            }
            var o = await reporitory.GetObject(c.Alpha3Code);

            o.Data.Name      = c.Name;
            o.Data.Code      = c.Alpha2Code;
            o.Data.ValidFrom = c.ValidFrom ?? DateTime.MinValue;
            o.Data.ValidTo   = c.ValidTo ?? DateTime.MaxValue;
            await reporitory.UpdateObject(o);

            return(RedirectToAction("Index"));
        }
Пример #23
0
        public void Edit_Country()
        {
            CountryView view = ObjectFactory.CreateCountryView(country.Id);

            Assert.True(false, "No update made");

            service.Edit(view);

            Country actual   = context.Set <Country>().AsNoTracking().Single();
            Country expected = country;

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.Id, actual.Id);

            Assert.True(false, "Not all properties tested");
        }
Пример #24
0
 /// <summary>
 /// Initializes a new instance of the MainViewModel class.
 /// </summary>
 public MainViewModel()
 {
     countries = new ObservableCollection <Country>(
         new[]
     {
         new Country()
         {
             Continent = Continent.Africa, DisplayName = "Algeria"
         },
         new Country()
         {
             Continent = Continent.Africa, DisplayName = "Egypt"
         },
         new Country()
         {
             Continent = Continent.Africa, DisplayName = "Chad"
         },
         new Country()
         {
             Continent = Continent.Africa, DisplayName = "Ghana"
         },
         new Country()
         {
             Continent = Continent.America, DisplayName = "Canada"
         },
         new Country()
         {
             Continent = Continent.America, DisplayName = "Greenland"
         },
         new Country()
         {
             Continent = Continent.America, DisplayName = "Haiti"
         }
     });
     CountryView         = (ListCollectionView)CollectionViewSource.GetDefaultView(countries);
     CountryView.Filter += CountryFilter;
     CountryView.Refresh();
     ////if (IsInDesignMode)
     ////{
     ////    // Code runs in Blend --> create design time data.
     ////}
     ////else
     ////{
     ////    // Code runs "for real"
     ////}
 }
Пример #25
0
        public ActionResult Edit(int?countryPK)
        {
            if (countryPK != null)
            {
                ICountriesRepository countriesRepository = new CountriesRepository(db);

                Country country = countriesRepository.GetCountryByPK((int)countryPK);

                CountryView countryView = new CountryView();
                countryView.ConvertFrom(country, countryView);

                return(View(countryView));
            }
            else
            {
                return(RedirectToAction("Index", "Country"));
            }
        }
Пример #26
0
        public ActionResult Edit(CountryView countryView)
        {
            if (ModelState.IsValid)
            {
                ICountriesRepository countriesRepository = new CountriesRepository(db);
                Country country = countriesRepository.GetCountryByPK((int)countryView.CountryPK);

                countryView.ConvertTo(countryView, country);

                countriesRepository.SaveChanges();

                TempData["message"] = LayoutHelper.GetMessage("UPDATE", country.CountryPK);

                return(RedirectToAction("Index", "Country"));
            }
            else
            {
                return(View(countryView));
            }
        }
Пример #27
0
        public static List <CountryView> GetAllCountry()
        {
            connection.ConnectionString = connectionString;
            string query = "SELECT * FROM CountryView ";
            //(CityName LIKE '%'+@citySearchName+'%')";


            SqlCommand command = new SqlCommand(query, connection);


            List <CountryView> countryList = new List <CountryView>();

            connection.Open();
            SqlDataReader reader      = command.ExecuteReader();
            CountryView   countryView = null;

            while (reader.Read())
            {
                countryView = new CountryView();
                //countryView.Id = (int) reader["id"];
                countryView.Name       = reader["CountryName"].ToString();
                countryView.About      = reader["CountryAbout"].ToString();
                countryView.NoOfCities = Convert.ToInt32(reader["NoOfCities"].ToString());
                if (!reader["NoOfDwellers"].Equals(System.DBNull.Value))
                {
                    countryView.NoOfDwellers = reader.GetInt64(reader.GetOrdinal("NoOfDwellers"));
                }
                else
                {
                    countryView.NoOfDwellers = 0;
                }



                countryList.Add(countryView);
            }
            reader.Close();
            connection.Close();

            return(countryList);
        }
Пример #28
0
        internal void Find()
        {
            StringiDalog dialog = new StringiDalog();

            dialog.WhatText = "A country abbreviation";
            dialog.ShowDialog();
            if (dialog.Accept)
            {
                string abbreviation = dialog.YourString;
                var    foundCountry = _countryRepository.GetByAbreviation(abbreviation);
                if (foundCountry != null)
                {
                    CurrentCountry = foundCountry;
                    CountryView view = new CountryView(CurrentCountry);
                    view.Show();
                }
                else
                {
                    FilmMessageBox box = new FilmMessageBox("No known country has abbreviation " + abbreviation);
                    box.Show();
                }
            }
        }
Пример #29
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var provider = new SQLiteDataProvider();

            var cacheSystem = new DatabaseCache();

            cacheSystem.Attach(provider);
            cacheSystem.CheckUpdate();    //check if the data is fresh (yesterday is present in the db)

            var data = provider.GetCountryData();

            MapView     mapView     = new MapView(data);
            IView       globalView  = new GlobalView(data);
            CountryView countryView = new CountryView(data);

            mapView.Subscribe(countryView);

            Application.Run(new MainForm(new List <IView> {
                mapView, globalView, countryView
            }));
        }
Пример #30
0
        public App()
        {
            InitializeComponent();

            MainPage = new CountryView();
        }