Пример #1
0
        public CountryResponse Delete(Guid identifier)
        {
            CountryResponse response = new CountryResponse();

            using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName))
            {
                db.Open();

                SqliteCommand insertCommand = new SqliteCommand();
                insertCommand.Connection = db;

                //Use parameterized query to prevent SQL injection attacks
                insertCommand.CommandText = "DELETE FROM Countries WHERE Identifier = @Identifier";
                insertCommand.Parameters.AddWithValue("@Identifier", identifier);
                try
                {
                    insertCommand.ExecuteNonQuery();
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    return(response);
                }
                db.Close();

                response.Success = true;
                return(response);
            }
        }
Пример #2
0
        private void CanDeserializeCountryResponse(CountryResponse resp)
        {
            Assert.Equal("NA", resp.Continent.Code);
            Assert.Equal(42, resp.Continent.GeoNameId);
            Assert.Equal("North America", resp.Continent.Name);

            Assert.Equal(1, resp.Country.GeoNameId);
            Assert.False(resp.Country.IsInEuropeanUnion);
            Assert.Equal("US", resp.Country.IsoCode);
            Assert.Equal(56, resp.Country.Confidence);
            Assert.Equal("United States", resp.Country.Name);

            Assert.Equal(2, resp.RegisteredCountry.GeoNameId);
            Assert.True(resp.RegisteredCountry.IsInEuropeanUnion);
            Assert.Equal("DE", resp.RegisteredCountry.IsoCode);
            Assert.Equal("Germany", resp.RegisteredCountry.Name);

            Assert.Equal(4, resp.RepresentedCountry.GeoNameId);
            Assert.True(resp.RepresentedCountry.IsInEuropeanUnion);
            Assert.Equal("GB", resp.RepresentedCountry.IsoCode);
            Assert.Equal("United Kingdom", resp.RepresentedCountry.Name);
            Assert.Equal("military", resp.RepresentedCountry.Type);

            Assert.Equal("1.2.3.4", resp.Traits.IPAddress);
        }
        public async Task <CountryResponse> CreateCountry(Country countryModel)
        {
            var userId = await _loginRepository.GetUserIdByAuthToken("");

            var countryExisting = GetCountryByName(countryModel.countryName);

            if (countryExisting != null)
            {
                var response = new CountryResponse {
                    status = false, message = "Country already exists", countryList = null
                };
                return(response);
            }
            else
            {
                var country = new MtnCountry()
                {
                    CountryName = countryModel.countryName,
                    CreatedBy   = userId
                };
                var loginSessionEntry = _context.MtnCountry.Add(country);
                await _context.SaveChangesAsync();

                var countryList = new List <Country>();
                countryList.Add(new Country {
                    countryId = Convert.ToString(country.CountryId), countryName = country.CountryName
                });
                var response = new CountryResponse {
                    status = true, countryList = countryList
                };
                return(response);
            }
        }
Пример #4
0
        public async Task <Response <Applicant> > CreateApplicant(Applicant applicant)
        {
            Applicant            newApplicant = new Applicant();
            Response <Applicant> response     = new Response <Applicant>();

            if (applicant == null)
            {
                throw new ArgumentNullException(nameof(applicant));
            }

            CountryResponse countryResponse = await ValidateCountry(applicant.CountryOfOrigin);

            if (countryResponse != null && countryResponse.Name != null && !string.IsNullOrEmpty(countryResponse.Name))
            {
                newApplicant = await this.applicantRepository.Create(applicant);

                await this.applicantRepository.Save();

                if (newApplicant != null && newApplicant.ID > 0)
                {
                    response.ResponseCode = ResultCode.SUCCESS;
                    response.Description  = "Successful";
                    response.Result       = newApplicant;
                    return(response);
                }
            }

            response.ResponseCode = ResultCode.FAILED;
            response.Description  = "Could not create applicant.";
            return(response);
        }
Пример #5
0
        public static CountryResponse GetCountries()
        {
            uri = new Uri("http://restcountries.eu/");

            var          client  = new RestClient(uri);
            IRestRequest request = new RestRequest("rest/v1/all", Method.GET);

            //send request in json format
            request.RequestFormat = DataFormat.Json;

            // execute the request target
            IRestResponse <Country> response = client.Execute <Country>(request);

            var    content      = response.Content; // raw content as string
            string getcountries = JToken.Parse(content).ToString(Formatting.Indented);

            //deseralise the object into a list format matching the COuntry class.
            var countries = JsonConvert.DeserializeObject <List <Country> >(getcountries);
            //var cArray = countries.ToArray();

            //count = countries.Count;
            var countryResponse = new CountryResponse();

            countryResponse.StatusCode = (int)response.StatusCode;

            //countryResponse.StatusCode = response.StatusCode.ToString();
            countryResponse.Countries = countries;

            return(countryResponse);
        }
Пример #6
0
        public async Task <Response <Applicant> > UpdateApplicant(Applicant applicant)
        {
            Applicant            newApplicant = new Applicant();
            Response <Applicant> response     = new Response <Applicant>();

            CountryResponse countryResponse = await ValidateCountry(applicant.CountryOfOrigin);

            if (countryResponse != null && countryResponse.Name != null && !string.IsNullOrEmpty(countryResponse.Name))
            {
                newApplicant = await this.applicantRepository.Update(applicant);

                await this.applicantRepository.Save();

                if (newApplicant != null && newApplicant.ID > 0)
                {
                    response.ResponseCode = ResultCode.SUCCESS;
                    response.Description  = "Successful";
                    response.Result       = newApplicant;
                    return(response);
                }
            }
            else
            {
                response.ResponseCode = ResultCode.FAILED;
                response.Description  = "The supplied country could not be validated.";
                return(response);
            }

            response.ResponseCode = ResultCode.FAILED;
            response.Description  = "Could not update applicant.";
            return(response);
        }
Пример #7
0
        private void cbCountryWineList_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            CountryResponse selectedCountry = (CountryResponse)cbCountryWineList.SelectedItem;

            SelectedCountryId = selectedCountry.CountryId;
            ShowRegionsWinelist();
        }
Пример #8
0
        public CountryResponse Create(CountryViewModel country)
        {
            CountryResponse response = new CountryResponse();

            using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName))
            {
                db.Open();

                SqliteCommand insertCommand = db.CreateCommand();
                insertCommand.CommandText = SqlCommandInsertPart;

                try
                {
                    insertCommand = AddCreateParameters(insertCommand, country);
                    insertCommand.ExecuteNonQuery();
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    return(response);
                }
                db.Close();

                response.Success = true;
                return(response);
            }
        }
Пример #9
0
        public void CanDeserializeCountryResponse(CountryResponse resp)
        {
            resp.SetLocales(new List <string> {
                "en"
            });

            Assert.That(resp.Continent.Code, Is.EqualTo("NA"));
            Assert.That(resp.Continent.GeoNameId, Is.EqualTo(42));
            Assert.That(resp.Continent.Name, Is.EqualTo("North America"));

            Assert.That(resp.Country.GeoNameId, Is.EqualTo(1));
            Assert.That(resp.Country.IsoCode, Is.EqualTo("US"));
            Assert.That(resp.Country.Confidence, Is.EqualTo(56));
            Assert.That(resp.Country.Name, Is.EqualTo("United States"));

            Assert.That(resp.RegisteredCountry.GeoNameId, Is.EqualTo(2));
            Assert.That(resp.RegisteredCountry.IsoCode, Is.EqualTo("CA"));
            Assert.That(resp.RegisteredCountry.Name, Is.EqualTo("Canada"));

            Assert.That(resp.RepresentedCountry.GeoNameId, Is.EqualTo(4));
            Assert.That(resp.RepresentedCountry.IsoCode, Is.EqualTo("GB"));
            Assert.That(resp.RepresentedCountry.Name, Is.EqualTo("United Kingdom"));
            Assert.That(resp.RepresentedCountry.Type, Is.EqualTo("military"));

            Assert.That(resp.Traits.IPAddress, Is.EqualTo("1.2.3.4"));
        }
Пример #10
0
 public SignUpViewModel()
 {
     TakePicture     = new Command(async() => await TakePictureAsync());
     SelectPicture   = new Command(async() => await SelectPictureAsync());
     CountryResponse = new CountryResponse();
     FinishCommand   = new Command(() => FinishCommandExecute());
     // GetCountry();
 }
Пример #11
0
        private void cbCountryAllWineList_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            CountryResponse selectedCountry = (CountryResponse)cbCountryAllWineList.SelectedItem;

            if (selectedCountry != null)
            {
                SelectedCountryIdAllwinelist = selectedCountry.CountryId;
            }
            ShowRegionsAllWinelist();
        }
        public CountryResponse GetCountries()
        {
            var response = new CountryResponse();

            if (getCountry.countryData == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            response.country = getCountry.countryData;
            response.count   = getCountry.countryData.Count();
            return(response);
        }
Пример #13
0
        private SelectList CountrySelectList()
        {
            ICountryServices country = new CountryServices();

            CountryResponse countriesResponse = country.GetCountries();
            List <Country>  countriesList     = new List <Country>();

            countriesList = countriesResponse.countries;

            var selectList = new SelectList(countriesList, "id", "name");

            return(selectList);
        }
Пример #14
0
        private void ShowRegionsAddNewWine(long selectedCountryId)
        {
            cbOriginRegion.Items.Clear();

            CountryResponse selectedCountry = Metadata.Countries.FirstOrDefault(r => r.CountryId == selectedCountryId);

            if (selectedCountry != null && selectedCountry.Regions.Count() > 0)
            {
                cbOriginRegion.Items.AddRange(selectedCountry.Regions.ToArray());
                cbOriginRegion.SelectedIndex = 0;
            }
            else
            {
                ShowDistrictAddNewWine(0, 0);
            }
        }
Пример #15
0
        private void ShowCountriesAllWinelist()
        {
            cbCountryAllWineList.Items.Clear();


            CountryResponse firstObject = new CountryResponse {
                CountryId = -1, CountryName = "alla länder"
            };

            cbCountryAllWineList.Items.Add(firstObject);

            cbCountryAllWineList.Items.AddRange(Metadata.Countries.ToArray());


            cbCountryAllWineList.SelectedIndex = 0;
        }
Пример #16
0
        private void ShowRegionsAllWinelist()
        {
            CountryResponse selectedCountry = Metadata.Countries.FirstOrDefault(r => r.CountryId == SelectedCountryIdAllwinelist);

            cbRegionAllWineList.Items.Clear();

            RegionResponse firstObject = new RegionResponse {
                RegionId = -1, CountryId = -1, RegionName = "alla regioner"
            };

            cbRegionAllWineList.Items.Add(firstObject);
            if (selectedCountry != null)
            {
                cbRegionAllWineList.Items.AddRange(selectedCountry.Regions.ToArray());
            }
            cbRegionAllWineList.SelectedIndex = 0;
        }
        public CountryResponse GetAllCountries()
        {
            var countries = _context.MtnCountry;
            IEnumerable <Country> countryList = countries.ToList().Select(
                cr => new Country()
            {
                countryId   = Convert.ToString(cr.CountryId),
                countryName = cr.CountryName
            });
            var countryResponse = new CountryResponse()
            {
                status      = true,
                countryList = countryList.ToList()
            };

            return(countryResponse);
        }
Пример #18
0
        public async Task <CountryResponse> ValidateCountry(string countryName)
        {
            CountryResponse response = new CountryResponse();
            string          url      = this.configurationFile.EuRestCountriesUrl.Replace("{{name}}", countryName);
            RestClientCall <CountryResponse> call = new RestClientCall <CountryResponse>();

            try
            {
                response = await call.Get(url);

                return(response);
            }
            catch (Exception er) { }

            response.Name = string.Empty;
            return(response);
        }
        public CountryResponse Create(CountryViewModel co)
        {
            CountryResponse response = new CountryResponse();

            try
            {
                response = WpfApiHandler.SendToApi <CountryViewModel, CountryResponse>(co, "Create");
            }
            catch (Exception ex)
            {
                response.Country = new CountryViewModel();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
Пример #20
0
        public IActionResult Save(CountryResponse countryResponse)
        {
            City   city   = null;
            Region region = null;

            if (!Context.Cities.Any(x => x.Name == countryResponse.Capital))
            {
                city = new City {
                    Name = countryResponse.Capital
                };
            }
            else
            {
                city = Context.Cities.First(x => x.Name == countryResponse.Capital);
            }
            if (!Context.Regions.Any(x => x.Name == countryResponse.Region))
            {
                region = new Region {
                    Name = countryResponse.Region
                };
            }
            else
            {
                region = Context.Regions.First(x => x.Name == countryResponse.Region);
            }

            if (!Context.Countries.Any(x => x.NumericCode == countryResponse.NumericCode))
            {
                Country country = new Country
                {
                    Name        = countryResponse.Name,
                    NumericCode = countryResponse.NumericCode,
                    City        = city,
                    Area        = countryResponse.Area,
                    Population  = countryResponse.Population,
                    Region      = region
                };

                Context.Countries.Add(country);
            }

            Context.SaveChanges();

            return(RedirectToAction("Countries"));
        }
        public dynamic GetActiveCountries()
        {
            try
            {
                CountryRepository countryRepository = new CountryRepository();
                var countriesList = countryRepository.GetActiveCountries();

                if (countriesList != null)
                {
                    Logger.Instance.WriteInLog(LogType.INFO, "Countries successfully obtained");

                    CountryResponse countryResponse = new CountryResponse();
                    countryResponse.countries = new List <Country>();

                    foreach (var countryTemp in countriesList)
                    {
                        Country country = new Country();
                        country.name   = countryTemp.Name;
                        country.id     = countryTemp.Id;
                        country.active = countryTemp.Active;
                        countryResponse.countries.Add(country);
                    }

                    return(JObject.Parse(JsonConvert.SerializeObject(countryResponse)));
                }
                else
                {
                    Logger.Instance.WriteInLog(LogType.WARNING, "Something wrong ocurred while getting the countries");
                    return(JObject.Parse(JsonConvert.SerializeObject(new CountryResponse
                    {
                        countries = new List <Country>(),
                        errors = "Could not get the countries"
                    })));
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.WriteInLog(LogType.ERROR, "An error ocurred while getting the countries", null, ex.Message);
                return(JObject.Parse(JsonConvert.SerializeObject(new CountryResponse
                {
                    countries = new List <Country>(),
                    errors = ex.Message.ToString()
                })));
            }
        }
        public CountryResponse Delete(Guid identifier)
        {
            CountryResponse response = new CountryResponse();

            try
            {
                CountryViewModel co = new CountryViewModel();
                co.Identifier = identifier;
                response      = WpfApiHandler.SendToApi <CountryViewModel, CountryResponse>(co, "Delete");
            }
            catch (Exception ex)
            {
                response.Country = new CountryViewModel();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
Пример #23
0
        public CountryResponse GetCountry()
        {
            CommonRequest obj = new CommonRequest();

            UserDialogs.Instance.ShowLoading("Requesting..");
            userManager.getCountry(obj, () =>
            {
                CountryResponse = userManager.CountryResponse;
                //LstCountry = new ObservableCollection<Models.Country>();
                //foreach (var item in userCountryResponse.country)
                //{
                //    LstCountry.Add(item);
                //}

                UserDialogs.Instance.HideLoading();
            });

            return(CountryResponse);
        }
Пример #24
0
        public CountryResponse Create(CountryViewModel re)
        {
            CountryResponse response = new CountryResponse();

            try
            {
                Country addedCountry = unitOfWork.GetCountryRepository().Create(re.ConvertToCountry());
                unitOfWork.Save();
                response.Country = addedCountry.ConvertToCountryViewModel();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Country = new CountryViewModel();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
        public JsonResult Delete([FromBody] CountryViewModel country)
        {
            CountryResponse response = new CountryResponse();

            try
            {
                response = this.countryService.Delete(country.Identifier);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                Console.WriteLine(ex.Message);
            }

            return(Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Newtonsoft.Json.Formatting.Indented
            }));
        }
Пример #26
0
        public MapCountryPage()
        {
            InitializeComponent();

            _country = JsonConvert.DeserializeObject <CountryResponse>(Settings.Country);

            Pin CountryPin = new Pin
            {
                Type     = PinType.SavedPin,
                Position = new Position(_country.Latlng[0], _country.Latlng[1]),
                Label    = _country.Name,
                Address  = ""
            };

            MapView.MoveToRegion(
                MapSpan.FromCenterAndRadius(
                    new Position(_country.Latlng[0], _country.Latlng[1]), Distance.FromMiles(10)));

            MapView.Pins.Add(CountryPin);
        }
Пример #27
0
        public CountryResponse DeleteAll()
        {
            CountryResponse response = new CountryResponse();

            try
            {
                using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName))
                {
                    db.Open();
                    db.EnableExtensions(true);

                    SqliteCommand insertCommand = new SqliteCommand();
                    insertCommand.Connection = db;

                    //Use parameterized query to prevent SQL injection attacks
                    insertCommand.CommandText = "DELETE FROM Countries";
                    try
                    {
                        insertCommand.ExecuteNonQuery();
                    }
                    catch (SqliteException error)
                    {
                        response.Success = false;
                        response.Message = error.Message;

                        MainWindow.ErrorMessage = error.Message;
                        return(response);
                    }
                    db.Close();
                }
            }
            catch (SqliteException error)
            {
                response.Success = false;
                response.Message = error.Message;
                return(response);
            }

            response.Success = true;
            return(response);
        }
Пример #28
0
        public CountryResponse Map(Country request)
        {
            if (request == null)
            {
                return(null);
            }
            ;

            CountryResponse response = new CountryResponse
            {
                Id           = request.Id,
                Iso3cc       = request.Iso3cc,
                Iso2cc       = request.Iso2cc,
                IsoNumerical = request.IsoNumerical,
                EconomicArea = request.EconomicArea,
                Name         = request.Name,
                Type         = request.Type,
            };

            return(response);
        }
Пример #29
0
        public CountryResponse Detail(int id)
        {
            CountryResponse response = null;

            try
            {
                var detail = _dbContext.Get <t_sys_country>(id);
                if (detail != null)
                {
                    response = new CountryResponse
                    {
                        Id   = detail.id,
                        Name = detail.name
                    };
                }
            }
            catch (Exception ex)
            {
                LogUtils.LogError("CountryService.Detail", ex);
            }
            return(response);
        }
        public async Task <IActionResult> PostMtnCountry([FromBody] Country mtnCountry)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var response = await _countyRepository.CreateCountry(mtnCountry);


                return(new JsonResult(response));
            }
            catch (Exception ex)
            {
                var response = new CountryResponse {
                    status = false, message = "Error occured on page", countryList = null
                };
                return(new JsonResult(response));
            }
        }