コード例 #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"));
     }
 }
コード例 #6
0
 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
ファイル: LocationDa.cs プロジェクト: hangphan91/Web_Test
 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
ファイル: UnitOfWork.cs プロジェクト: nasro10/Location
 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();
 }