public ActionResult Grabar(int id, Evento evento)
 {
     if (ModelState.IsValid)
     {
         db.Entry(evento).State = EntityState.Modified;
         try
         {
             db.SaveChanges();
         }
         catch (DbUpdateConcurrencyException)  // TODO: Manejar el error
         {
             if (!EventoExists(id))
             {
                 //return NotFound();
             }
             else
             {
                 throw;
             }
         }
         return(new JsonNetResult {
             Data = evento, Formatting = Formatting.None
         });
     }
     return(null);
 }
Exemple #2
0
        public void AddCity(int continentId, int countryId, City city, int? capital)
        {
            GeoContext ctx = new GeoContext();
            if (!ctx.Cities.Any(n => n.Name == city.Name))
            {
                Country country = ctx.Countries.Where(c => c.CountryId == countryId).First();
                Continent continent = ctx.Continents.Where(c => c.ContinentId == continentId).First();

                if (capital == 1)
                {
                    city.CityMappings = new List<CityMapping>
                    { new CityMapping { City = city, IsCapital = true, Country = ctx.Countries.Single(c => c.CountryId == countryId) } };
                }
                else
                {
                    city.CityMappings = new List<CityMapping>
                    { new CityMapping { City = city, Country = ctx.Countries.Single(c => c.CountryId == countryId) } };
                }

                country.Population += city.Population;
                continent.Population += city.Population;

                ctx.Countries.Update(country);
                ctx.Continents.Update(continent);
                ctx.Cities.Add(city);
                ctx.SaveChanges();
            }
            else throw new GeoException("City already added to db.");
        }
Exemple #3
0
        public void UpdateCity(int continentId, int countryId, City city)
        {
            GeoContext ctx = new GeoContext();
            if (ctx.Cities.Any(n => n.Name == city.Name))
            {
                GeoContext popContext = new GeoContext();
                int oldCityPopulation = popContext.Cities.Where(c => c.CityId == city.CityId).First().Population;
                Continent continent = ctx.Continents.Where(c => c.ContinentId == continentId).First();
                Country country = ctx.Countries.Where(c => c.CountryId == countryId).First();

                if (oldCityPopulation > city.Population)
                {
                    continent.Population -= city.Population;
                    country.Population -= city.Population;
                }

                else
                {
                    continent.Population += city.Population;
                    country.Population += city.Population;
                }

                ctx.Continents.Update(continent);
                ctx.Countries.Update(country);
                ctx.Cities.Update(city);
                ctx.SaveChanges();
            }
            else throw new GeoException("City does not exist in db.");
        }
        /// <summary>
        /// Add site to existing city
        /// </summary>
        /// <param name="context"></param>
        /// <param name="cityId"></param>
        /// <param name="site"></param>
        /// <param name="eventSender"></param>
        /// <returns></returns>
        public async Task <Site> AddSite([Service] GeoContext context, int cityId, string site, [Service] ITopicEventSender eventSender)
        {
            City cityItem = context.Cities.Include(c => c.Sites).FirstOrDefault(c => c.Id == cityId);

            if (cityItem == null)
            {
                throw new System.Exception("City not found.");
            }

            Site siteitem = cityItem.Sites.FirstOrDefault(s => s.Name == site);

            if (siteitem != null)
            {
                throw new System.Exception("Site already exists.");
            }

            Site newSite = new() { Name = site };

            cityItem.Sites.Add(newSite);
            context.SaveChanges();

            await eventSender.SendAsync(
                nameof(Subscription.OnSiteAddedAsync),
                newSite.Id).ConfigureAwait(false);

            return(newSite);
        }
    }
Exemple #5
0
        /// <summary>
        /// Add New City to Existing Country
        /// </summary>
        /// <param name="context"></param>
        /// <param name="country"></param>
        /// <param name="city"></param>
        /// <param name="eventSender">reference to GraphQL EventSender</param>
        /// <returns></returns>
        public async Task <City> AddCity([Service] GeoContext context, string country, string city, [Service] ITopicEventSender eventSender)
        {
            Country countryItem = context.Countries.Include(c => c.Cities).FirstOrDefault(c => c.Name == country);

            if (countryItem == null)
            {
                throw new System.Exception("Country not found.");
            }

            City cityitem = countryItem.Cities.FirstOrDefault(c => c.Name == city);

            if (cityitem != null)
            {
                throw new System.Exception("City already exists.");
            }

            City newCity = new() { Name = city };

            countryItem.Cities.Add(newCity);
            context.SaveChanges();
            await eventSender.SendAsync(
                nameof(Subscription.OnCityAddedAsync),
                newCity.Id).ConfigureAwait(false);

            return(newCity);
        }
    }
        public void RemoveContinent(int id)
        {
            GeoContext ctx = new GeoContext();

            if (ExistsContinent(id))
            {
                ctx.Continents.Remove(ctx.Continents.Single(c => c.ContinentId == id));
                ctx.SaveChanges();
            }
            else
            {
                throw new GeoException("Continent does not exist in db.");
            }
        }
        public void UpdateContinent(Continent continent)
        {
            GeoContext ctx = new GeoContext();

            if (ExistsContinent(continent.ContinentId))
            {
                ctx.Continents.Update(continent);
                ctx.SaveChanges();
            }
            else
            {
                throw new GeoException("Continent does not exist in db.");
            }
        }
        public void UpdateCountry(Country country)
        {
            GeoContext ctx = new GeoContext();

            if (ExistsCountry(country.CountryId))
            {
                ctx.Countries.Update(country);
                ctx.SaveChanges();
            }
            else
            {
                throw new GeoException("Country does not exist in db.");
            }
        }
        public void AddContinent(Continent continent)
        {
            GeoContext ctx = new GeoContext();

            if (!ctx.Continents.Any(c => c.Name == continent.Name))
            {
                ctx.Continents.Add(continent);
                ctx.SaveChanges();
            }
            else
            {
                throw new GeoException("Continent already added to db.");
            }
        }
Exemple #10
0
        public void UpdateRiver(River river)
        {
            GeoContext ctx = new GeoContext();

            if (ExistsRiver(river.RiverId))
            {
                ctx.Rivers.Update(river);
                ctx.SaveChanges();
            }
            else
            {
                throw new GeoException("River does not exist in db.");
            }
        }
        public void RemoveCountry(int continentId, int countryId)
        {
            GeoContext ctx = new GeoContext();

            if (ExistsCountry(countryId))
            {
                ctx.Countries.Remove(ctx.Countries.Single(c => c.CountryId == countryId));
                ctx.SaveChanges();
            }
            else
            {
                throw new GeoException("Country does not exist in db.");
            }
        }
Exemple #12
0
        public void RemoveRiver(int id)
        {
            GeoContext ctx = new GeoContext();

            if (ExistsRiver(id))
            {
                ctx.Rivers.Remove(ctx.Rivers.Single(r => r.RiverId == id));
                ctx.SaveChanges();
            }
            else
            {
                throw new GeoException("River does not exist in db.");
            }
        }
Exemple #13
0
        public void Post([FromBody] LocalViewModel value)
        {
            var local = new Local
            {
                Nome = value.Nome
            };

            ctx.Add(local);
            ctx.SaveChanges();
            var update = $"Update Locais set Ponto = geography::STGeomFromText('POINT ('+@lng+' '+@lat+')', 4326) WHERE id = @id";

            ctx.Database.ExecuteSqlCommand(update,
                                           new SqlParameter("id", local.Id),
                                           new SqlParameter("lng", value.Location.Lng.ToString()),
                                           new SqlParameter("lat", value.Location.Lat.ToString())
                                           );
        }
Exemple #14
0
        public void RemoveCity(int continentId, int countryId, int cityId)
        {
            GeoContext ctx = new GeoContext();
            if (ctx.Cities.Any(c => c.CityId == cityId))
            {
                City city = ctx.Cities.Where(c => c.CityId == cityId).First();
                Country country = ctx.Countries.Where(c => c.CountryId == countryId).First();
                Continent continent = ctx.Continents.Where(c => c.ContinentId == continentId).First();

                country.Population -= city.Population;
                continent.Population -= city.Population;

                ctx.Continents.Update(continent);
                ctx.Countries.Update(country);
                ctx.Cities.Remove(city);
                ctx.SaveChanges();
            }
            else throw new GeoException("City does not exist in db.");
        }
        public void AddCountry(Country country, int id)
        {
            GeoContext ctx = new GeoContext();

            if (!ctx.Countries.Any(c => c.Name == country.Name))
            {
                country.CountryMappings = new List <CountryMapping>
                {
                    new CountryMapping {
                        Country = country, Continent = ctx.Continents.Single(c => c.ContinentId == id)
                    }
                };

                ctx.Countries.Add(country);
                ctx.SaveChanges();
            }
            else
            {
                throw new GeoException("Country already added to db.");
            }
        }
Exemple #16
0
        public void AddRiver(River river, int id)
        {
            GeoContext ctx = new GeoContext();

            if (!ctx.Rivers.Any(r => r.Name == river.Name))
            {
                river.RiverMappings = new List <RiverMapping>
                {
                    new RiverMapping {
                        River = river, Country = ctx.Countries.Single(c => c.CountryId == id)
                    }
                };

                ctx.Rivers.Add(river);
                ctx.SaveChanges();
            }
            else
            {
                throw new GeoException("River already added to db.");
            }
        }
        public void Add([FromBody] BlockDto data)
        {
            var existing = _db
                           .Blocks
                           .SingleOrDefault(b => b.Dimension == data.Dimension &&
                                            data.PosX == b.PosX &&
                                            data.PosY == b.PosY &&
                                            data.PosZ == b.PosZ);

            var block = existing ?? new Block();

            block.Dimension = data.Dimension;
            block.Ore       = data.Ore;
            block.PosX      = data.PosX;
            block.PosY      = data.PosY;
            block.PosZ      = data.PosZ;
            if (block.Id == Guid.Empty)
            {
                _db.Blocks.Add(block);
            }
            _db.SaveChanges();
        }
 public IActionResult Create([FromBody] City model)
 {
     _context.Cities.Add(model);
     _context.SaveChanges();
     return(CreatedAtRoute("GetCity", new { id = model.Id }, model));
 }
 public void SaveChanges()
 {
     _context.SaveChanges();
 }
        public void Initialize()
        {
            ClearInfos();

            new VeinBuilder(40, 60)
            .Dimensions(Dimension.Overworld)
            .Ores(Ore.Apatite, Ore.Phosphorus, Ore.Phosphate)
            .SaveTo(_db);

            new VeinBuilder(50, 90)
            .Dimensions(Dimension.Overworld, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Bauxite, Ore.Aluminium, Ore.Ilmenite)
            .SaveTo(_db);

            new VeinBuilder(5, 30)
            .Dimensions(Dimension.Overworld, Dimension.End, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Beryllium, Ore.Emerald, Ore.Thorium)
            .SaveTo(_db);

            new VeinBuilder(40, 120)
            .Dimensions(Dimension.Overworld, Dimension.End, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Tin, Ore.Cassiterite)
            .SaveTo(_db);

            new VeinBuilder(50, 80)
            .Dimensions(Dimension.Overworld)
            .Ores(Ore.Coal, Ore.Lignite)
            .SaveTo(_db);

            new VeinBuilder(10, 30)
            .Dimensions(Dimension.Overworld, Dimension.Nether, Dimension.Moon, Dimension.Mars)
            .Ores(Ore.Chalcopyrite, Ore.Iron, Ore.Pyrite, Ore.Copper)
            .SaveTo(_db);

            new VeinBuilder(5, 20)
            .Dimensions(Dimension.Overworld, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Graphite, Ore.Diamond, Ore.Coal)
            .SaveTo(_db);

            new VeinBuilder(30, 60)
            .Dimensions(Dimension.Overworld, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Galena, Ore.Silver, Ore.Lead)
            .SaveTo(_db);

            new VeinBuilder(60, 80)
            .Dimensions(Dimension.Overworld, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Magnetite, Ore.VanadiumMagnetite, Ore.Gold)
            .SaveTo(_db);

            new VeinBuilder(10, 40)
            .Dimensions(Dimension.Overworld, Dimension.Nether, Dimension.Moon, Dimension.Mars)
            .Ores(Ore.BrownLimonite, Ore.YellowLimonite, Ore.BandedIron, Ore.Malachite)
            .SaveTo(_db);

            new VeinBuilder(20, 50)
            .Dimensions(Dimension.Overworld, Dimension.Nether, Dimension.End, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Lazurite, Ore.Sodalite, Ore.Lapis, Ore.Calcite)
            .SaveTo(_db);

            new VeinBuilder(50, 130)
            .Dimensions(Dimension.Overworld)
            .Ores(Ore.Lignite, Ore.Coal)
            .SaveTo(_db);

            new VeinBuilder(50, 120)
            .Dimensions(Dimension.Overworld, Dimension.Nether, Dimension.Moon, Dimension.Mars)
            .Ores(Ore.Magnetite, Ore.Iron, Ore.VanadiumMagnetite)
            .SaveTo(_db);

            new VeinBuilder(20, 30)
            .Dimensions(Dimension.Overworld, Dimension.End, Dimension.Moon, Dimension.Asteroids)
            .Ores(Ore.Grossular, Ore.Spessartine, Ore.Pyrolusite, Ore.Tantalite, Ore.Manganese)
            .SaveTo(_db);

            new VeinBuilder(20, 50)
            .Dimensions(Dimension.Overworld, Dimension.End, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Wulfenite, Ore.Molybdenite, Ore.Molybdenum, Ore.Powellite)
            .SaveTo(_db);

            new VeinBuilder(20, 40)
            .Dimensions(Dimension.Overworld, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Bastnasite, Ore.Monazite, Ore.Neodymium)
            .SaveTo(_db);

            new VeinBuilder(60, 120)
            .Dimensions(Dimension.Asteroids)
            .Ores(Ore.Naquadah, Ore.EnrichedNaquadah)
            .SaveTo(_db);

            new VeinBuilder(40, 80)
            .Dimensions(Dimension.Nether)
            .Ores(Ore.NetherQuartz)
            .SaveTo(_db);

            new VeinBuilder(10, 40)
            .Dimensions(Dimension.Overworld, Dimension.Nether, Dimension.End, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Garnierite, Ore.Nickel, Ore.Cobaltite, Ore.Pentlandite)
            .SaveTo(_db);

            new VeinBuilder(10, 40)
            .Dimensions(Dimension.Overworld, Dimension.Nether, Dimension.End, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Bentonite, Ore.Magnesite, Ore.Olivine, Ore.Glauconite)
            .SaveTo(_db);

            new VeinBuilder(10, 40)
            .Dimensions(Dimension.Overworld, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Pitchblende, Ore.Uraninite, Ore.Uranium238)
            .SaveTo(_db);

            new VeinBuilder(40, 50)
            .Dimensions(Dimension.Overworld, Dimension.End, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Sheldonite, Ore.Palladium, Ore.Platinum, Ore.Iridium)
            .SaveTo(_db);

            new VeinBuilder(20, 30)
            .Dimensions(Dimension.Overworld, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Uraninite, Ore.Uranium238)
            .SaveTo(_db);

            new VeinBuilder(40, 80)
            .Dimensions(Dimension.Overworld, Dimension.End, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Quartzite, Ore.Barite, Ore.CertusQuartz, Ore.Quartz)
            .SaveTo(_db);

            new VeinBuilder(10, 40)
            .Dimensions(Dimension.Overworld, Dimension.Nether, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Redstone, Ore.Ruby, Ore.Cinnabar)
            .SaveTo(_db);

            new VeinBuilder(50, 60)
            .Dimensions(Dimension.Overworld, Dimension.Moon)
            .Ores(Ore.RockSalt, Ore.Salt, Ore.Lepidolite, Ore.Spodumene)
            .SaveTo(_db);

            new VeinBuilder(10, 40)
            .Dimensions(Dimension.Overworld, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Almandine, Ore.Pyrope, Ore.Sapphire, Ore.GreenSapphire)
            .SaveTo(_db);

            new VeinBuilder(10, 40)
            .Dimensions(Dimension.Overworld, Dimension.Moon, Dimension.Mars)
            .Ores(Ore.Soapstone, Ore.Talc, Ore.Glauconite, Ore.Pentlandite)
            .SaveTo(_db);

            new VeinBuilder(5, 20)
            .Dimensions(Dimension.Nether, Dimension.Mars)
            .Ores(Ore.Sulflur, Ore.Pyrite, Ore.Sphalerite)
            .SaveTo(_db);

            new VeinBuilder(60, 120)
            .Dimensions(Dimension.Overworld, Dimension.Nether, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Tetrahedrite, Ore.Copper, Ore.Stibnite)
            .SaveTo(_db);

            new VeinBuilder(20, 50)
            .Dimensions(Dimension.Overworld, Dimension.End, Dimension.Moon, Dimension.Mars, Dimension.Asteroids)
            .Ores(Ore.Scheelite, Ore.Tungstate, Ore.Lithium)
            .SaveTo(_db);

            new VeinBuilder(50, 80)
            .Dimensions(Dimension.Overworld)
            .Ores(Ore.OilSands)
            .SaveTo(_db);

            _db.SaveChanges();
        }