Exemplo n.º 1
0
        public void Post([FromBody] Country ujOrszag)
        {
            CountriesContext context = new CountriesContext();

            context.Countries.Add(ujOrszag);
            context.SaveChanges();
        }
Exemplo n.º 2
0
 public async Task <Country> GetCountryAsync(CountriesContext context, int id)
 {
     return(await context.Set <Country>()
            .Include(country => country.Capital)
            .Include(country => country.Region)
            .FirstOrDefaultAsync(country => country.Id == id));
 }
Exemplo n.º 3
0
        public int M4() //Tetszőleges metódusnév
        {
            CountriesContext context = new CountriesContext();
            int orszagokSzama        = context.Countries.Count();

            return(orszagokSzama);
        }
Exemplo n.º 4
0
        public async Task SaveCountryAsync(CountryViewModel countryViewModel)
        {
            var capitalId = await SaveCapitalAsync(countryViewModel.Capital).ConfigureAwait(false);

            var regionId = await SaveRegionAsync(countryViewModel.Region).ConfigureAwait(false);

            using (var context = new CountriesContext())
            {
                var savedCountry = await countriesRepository.GetAll(context)
                                   .FirstOrDefaultAsync(country => country.NumericCode == countryViewModel.NumericCode)
                                   .ConfigureAwait(false);

                if (savedCountry == null)
                {
                    await countriesRepository
                    .AddAsync(context, MapViewModelToCountry(countryViewModel, capitalId, regionId))
                    .ConfigureAwait(false);
                }
                else
                {
                    await countriesRepository
                    .UpdateAsync(context, savedCountry.Id,
                                 country => MapViewModelToCountry(countryViewModel, capitalId, regionId))
                    .ConfigureAwait(false);
                }
            }
        }
Exemplo n.º 5
0
 public async Task <Country[]> GetAllCountriesAsync(CountriesContext context)
 {
     return(await context.Set <Country>()
            .Include(country => country.Capital)
            .Include(country => country.Region)
            .ToArrayAsync());
 }
Exemplo n.º 6
0
        public string Get(int id)
        {
            CountriesContext context = new CountriesContext();
            var keresettOrszag       = (from x in context.Countries
                                        where x.CountriesSk == id
                                        select x.Name).FirstOrDefault();

            return(keresettOrszag);
        }
Exemplo n.º 7
0
        public Country GetCountry(string name)
        {
            using (var db = new CountriesContext())
            {
                var country = db.Country.FirstOrDefault(c => c.Name == name);

                return(country);
            }
        }
Exemplo n.º 8
0
        public void Delete(int id)
        {
            CountriesContext context = new CountriesContext();
            var torlendoOrszag       = (from y in context.Countries
                                        where y.CountriesSk == id
                                        select y).FirstOrDefault();

            context.Remove(torlendoOrszag);
            context.SaveChanges();
        }
Exemplo n.º 9
0
        public async Task <CountryViewModel[]> GetCountriesAsync()
        {
            using (var context = new CountriesContext())
            {
                var countries = await countriesRepository.GetAllCountriesAsync(context).ConfigureAwait(false);

                var countriesViewModels = new List <CountryViewModel>();
                foreach (var country in countries)
                {
                    countriesViewModels.Add(MapCountryToViewModel(country));
                }

                return(countriesViewModels.ToArray());
            }
        }
Exemplo n.º 10
0
        private async Task <int> SaveCapitalAsync(string capitalName)
        {
            using (var context = new CountriesContext())
            {
                var capital = await citiesRepository.GetAll(context)
                              .FirstOrDefaultAsync(city => city.Name == capitalName)
                              .ConfigureAwait(false);

                if (capital == null)
                {
                    capital = new City()
                    {
                        Name = capitalName
                    };
                    await citiesRepository.AddAsync(context, capital).ConfigureAwait(false);
                }

                await context.SaveChangesAsync().ConfigureAwait(false);

                return(capital.Id);
            }
        }
Exemplo n.º 11
0
        private async Task <int> SaveRegionAsync(string regionName)
        {
            using (var context = new CountriesContext())
            {
                var region = await regionsRepository.GetAll(context)
                             .FirstOrDefaultAsync(reg => reg.Name == regionName)
                             .ConfigureAwait(false);

                if (region == null)
                {
                    region = new Region()
                    {
                        Name = regionName
                    };
                    await regionsRepository.AddAsync(context, region).ConfigureAwait(false);
                }

                await context.SaveChangesAsync().ConfigureAwait(false);

                return(region.Id);
            }
        }
Exemplo n.º 12
0
    public CountriesContext countries()
    {
        CountriesContext _localctx = new CountriesContext(Context, State);

        EnterRule(_localctx, 0, RULE_countries);
        int _la;

        try {
            EnterOuterAlt(_localctx, 1);
            {
                State = 5;
                ErrorHandler.Sync(this);
                _la = TokenStream.LA(1);
                do
                {
                    {
                        {
                            State = 4; country();
                        }
                    }
                    State = 7;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.LA(1);
                } while (_la == COUNTRY);
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
Exemplo n.º 13
0
        public IEnumerable <Country> Get()
        {
            CountriesContext context = new CountriesContext();

            return(context.Countries.ToList());
        }