public async Task <IActionResult> PutCountry(short id, Country country)
        {
            if (id != country.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IHttpActionResult> PutCountry(int id, Country country)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != country.ID)
            {
                return(BadRequest());
            }

            db.Entry(country).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> Create([Bind("country_id,name")] Country country)
        {
            if (ModelState.IsValid)
            {
                _context.Add(country);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(country));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,info_hotline,world_category,year_formed")] Country country)
        {
            if (_context.Countries.Any(x => x.Name == country.Name))
            {
                ModelState.AddModelError("Name", "Name already in use!");
            }

            if (ModelState.IsValid)
            {
                _context.Add(country);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(country));
        }
示例#5
0
 public async Task UpdateActivity(Activity Activity)
 {
     using (var db = new CountryContext())
     {
         db.Activity.Update(Activity);
         await db.SaveChangesAsync();
     }
 }
 public async Task UpdateCountry(Country country)
 {
     using (var db = new CountryContext())
     {
         db.Country.Update(country);
         await db.SaveChangesAsync();
     }
 }
        public async Task AddCountry(Country country)
        {
            using (var db = new CountryContext())
            {
                await db.Country.AddAsync(country);

                await db.SaveChangesAsync();
            }
        }
示例#8
0
        public async Task AddActivity(Activity Activity, string countryISOCode)
        {
            using (var db = new CountryContext())
            {
                Activity.UniqId = GenereteUniqId(countryISOCode, Activity.ActivityName);
                await db.Activity.AddAsync(Activity);

                await db.SaveChangesAsync();
            }
        }
        public async Task <ActionResult <string> > AddCountries([FromBody] Country country, CancellationToken cancellationToken)
        {
            if (country == null)
            {
                return(BadRequest("country is null"));
            }

            await countryContext.AddAsync(country);

            await countryContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

            await cache.RemoveAsync("countries", cancellationToken).ConfigureAwait(false);

            return(Ok("OK!"));
        }
示例#10
0
        public async Task <bool> DeleteActivity(int ActivityId)
        {
            using (var db = new CountryContext())
            {
                var ActivityForDelete = await db.Activity.FirstOrDefaultAsync(_ => _.ActivityId == ActivityId);

                if (ActivityForDelete == null)
                {
                    return(false);
                }

                db.Activity.Remove(ActivityForDelete);
                await db.SaveChangesAsync();

                return(true);
            }
        }
示例#11
0
        public async Task <bool> DeleteCountry(int countryId)
        {
            using (var db = new CountryContext())
            {
                var countryForDelete = await db.Country.FirstOrDefaultAsync(_ => _.CountryId == countryId);

                if (countryForDelete == null)
                {
                    return(false);
                }

                db.Country.Remove(countryForDelete);
                await db.SaveChangesAsync();

                return(true);
            }
        }
示例#12
0
        public async Task <Country> AddCountryAsync(Country country)
        {
            if (country == null)
            {
                throw new ArgumentNullException($"cannot add a 'country' that is null");
            }

            try
            {
                await _context.countries
                .AddAsync(country);

                await _context.SaveChangesAsync();
            }
            catch (Exception)
            {
                throw;
            }

            return(await GetCountryAsync(country.geoname_id));
        }