public async Task <ActionResult <CountryMapping> > PostCountryMapping(CountryMapping CountryMapping)
        {
            _context.CountryMapping.Add(CountryMapping);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCountryMapping", new { id = CountryMapping.CountryMappingId }, CountryMapping));
        }
        public async Task <IActionResult> PutCountryMapping(int id, CountryMapping CountryMapping)
        {
            if (id != CountryMapping.CountryMappingId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #3
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            CountryMapping.Configure();
        }
        public Continent GetContinent(int id)
        {
            GeoContext ctx = new GeoContext();

            if (ExistsContinent(id))
            {
                List <CountryMapping> cms = new List <CountryMapping>();
                var c = ctx.Continents
                        .Where(c => c.ContinentId == id)
                        .Join(ctx.CountryMappings,
                              c => new { c.ContinentId },
                              cm => new { cm.ContinentId },
                              (c, cm) => new
                {
                    Name        = c.Name,
                    ContinentId = c.ContinentId,
                    Population  = c.Population,
                    CountryId   = cm.CountryId
                });

                foreach (var cm in c)
                {
                    CountryMapping cmData = new CountryMapping {
                        ContinentId = id, CountryId = cm.CountryId
                    };
                    cms.Add(cmData);
                }

                if (cms.Count == 0)
                {
                    return(ctx.Continents.Where(c => c.ContinentId == id).First());
                }

                Continent continent = new Continent {
                    ContinentId = id, Name = c.First().Name, Population = c.First().Population, CountryMappings = cms
                };

                return(continent);
            }
            else
            {
                throw new GeoException("Continent does not exist in db.");
            }
        }