public 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 { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CountryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public Location Add(Location location) { var addedEntity = context.Locations.Add(location); context.SaveChanges(); return(addedEntity.Entity); }
public ActionResult Create([Bind(Include = "RegionId,RegionName")] Region region) { if (ModelState.IsValid) { db.Regions.Add(region); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(region)); }
public ActionResult Create([Bind(Include = "CityId,CityName,RegionId")] City city) { if (ModelState.IsValid) { db.Cities.Add(city); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RegionId = new SelectList(db.Regions, "RegionId", "RegionName", city.RegionId); return(View(city)); }
public ActionResult LocationRemove(Location location) { using (locationContext = new LocationContext()) { Location toRemove = locationContext.Locations.Find(location.Id); locationContext.Locations.Remove(toRemove); locationContext.SaveChanges(); return(View("~/Views/Admin/Locations.cshtml")); } }
protected override void Seed(LocationContext context) { context.Countries.SeedFromResource("SeedingDataFromCSV.Domain.SeedData.countries.csv", c => c.Code); context.SaveChanges(); context.ProvinceStates.SeedFromResource("SeedingDataFromCSV.Domain.SeedData.provincestates.csv", p => p.Code, new CsvColumnMapping <ProvinceState>("CountryCode", (state, countryCode) => { state.Country = context.Countries.Single(c => c.Code == countryCode); }) ); }
internal bool AddLocation(decimal lat, decimal lng) { context.Locations.Add(new Location { latitude = lat, longitude = lng }); context.SaveChanges(); return(true); }
private async Task <List <LocationSearchResult> > LocationSearchApi(string query) { using (var client = new HttpClient()) { var stream = await client.GetStreamAsync($"https://www.metaweather.com/api/location/search?query={query}"); var locations = await JsonSerializer.DeserializeAsync <List <LocationSearchResult> >(stream); if (locations.Count == 0) { System.Console.WriteLine("Location not found"); return(null); } else { var locationsToBeAdded = locations.Select(u => u.WOEID).Distinct().ToArray(); var locationsInDB = _context.locations.Where(u => locationsToBeAdded.Contains(u.WOEID)) .Select(u => u.WOEID).ToArray(); var locationsNotInDb = locations.Where(u => !locationsInDB.Contains(u.WOEID)); foreach (LocationSearchResult location in locationsNotInDb) { _context.Add(location); _context.SaveChanges(); } } foreach (LocationSearchResult location in locations) { var entity = _context.locations.FirstOrDefault(item => item.WOEID == location.WOEID); if (entity != null) { entity.SearchCount += 1; _context.SaveChanges(); location.SearchCount = entity.SearchCount; } } return(locations); } }
public void SaveChanges(Location.Entities.Location location) { try { _context.Locations.Add(location); _context.SaveChanges(); } catch (DbUpdateException ex) { //log error here; throw; } }
public static void AddLocationsToDataBase(float latitude, float longitude) { var context = new LocationContext(); var location = new Location() { GeoLocation = CreatePoint(latitude, longitude), Latitude = latitude, Longitude = longitude }; context.Locations.Add(location); context.SaveChanges(); }
public ActionResult LocationEdit(Location locationModel) { using (locationContext = new LocationContext()) { if (locationModel.Name == null || locationModel.Address == null || locationModel.UserId <= 0) { ViewBag.FailedAddMessage = "You must fill in all of the spaces and the data should be correct!"; return(View("LocationEdit", new Location())); } else { locationContext.Locations.First(x => x.Id == locationModel.Id).Name = locationModel.Name; locationContext.Locations.First(x => x.Id == locationModel.Id).Address = locationModel.Address; locationContext.Locations.First(x => x.Id == locationModel.Id).UserId = locationModel.UserId; locationContext.SaveChanges(); return(View("~/Views/Admin/Locations.cshtml")); } } }
public ActionResult LocationCreate(Location locationModel) { using (locationContext = new LocationContext()) { if (locationModel.Name == null || locationModel.Address == null) { ViewBag.FailedRegisterMessage = "You must fill in all of the spaces!"; return(View("LocationCreate", new Location())); } else { if (locationContext.Locations.Any(x => x.Address == locationModel.Address)) { ViewBag.DuplicateMessage = "A Location with this address already exists."; return(View("LocationCreate", locationModel)); } locationContext.Locations.Add(locationModel); locationContext.SaveChanges(); } ModelState.Clear(); ViewBag.SuccessMessage = "Success!"; return(View("~/Views/Admin/Locations.cshtml")); } }
public void Commit() { ctx.SaveChanges(); }
//public LocationData Get(long id) //{ // return _LocationContext.Locations // .FirstOrDefault(o => o.LocationId = id); //} public void Add(LocationInfo entity) { _LocationContext.Location.Add(entity); _LocationContext.SaveChanges(); }
public void Save() { db.SaveChanges(); }