Пример #1
0
        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));
        }
Пример #2
0
        public Location Add(Location location)
        {
            var addedEntity = context.Locations.Add(location);

            context.SaveChanges();

            return(addedEntity.Entity);
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "RegionId,RegionName")] Region region)
        {
            if (ModelState.IsValid)
            {
                db.Regions.Add(region);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(region));
        }
Пример #4
0
        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));
        }
Пример #5
0
 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);
     })
                                             );
 }
Пример #7
0
        internal bool AddLocation(decimal lat, decimal lng)
        {
            context.Locations.Add(new Location
            {
                latitude  = lat,
                longitude = lng
            });

            context.SaveChanges();
            return(true);
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
 public void SaveChanges(Location.Entities.Location location)
 {
     try
     {
         _context.Locations.Add(location);
         _context.SaveChanges();
     }
     catch (DbUpdateException ex)
     {
         //log error here;
         throw;
     }
 }
Пример #10
0
        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();
        }
Пример #11
0
 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"));
         }
     }
 }
Пример #12
0
 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"));
     }
 }
Пример #13
0
 public void Commit()
 {
     ctx.SaveChanges();
 }
Пример #14
0
 //public LocationData Get(long id)
 //{
 //    return _LocationContext.Locations
 //          .FirstOrDefault(o => o.LocationId = id);
 //}
 public void Add(LocationInfo entity)
 {
     _LocationContext.Location.Add(entity);
     _LocationContext.SaveChanges();
 }
Пример #15
0
 public void Save()
 {
     db.SaveChanges();
 }