From 1a6c8f646f3afc119bcc9aa85a4e33604944bacc Mon Sep 17 00:00:00 2001 From: yarik Date: Fri, 3 Feb 2017 18:49:20 +0200 Subject: [PATCH] Add/update completed --- src/Maps/Controllers/BusStopController.cs | 15 +++++---------- src/MapsDb/DataService/BusStopDs.cs | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Maps/Controllers/BusStopController.cs b/src/Maps/Controllers/BusStopController.cs index ce8f1c1..4d1720d 100755 --- a/src/Maps/Controllers/BusStopController.cs +++ b/src/Maps/Controllers/BusStopController.cs @@ -86,21 +86,16 @@ namespace Maps.Controllers // GET: BusStop/Create [HttpPost] - public async Task Create(string data) + public async Task Create([FromBody] BusStopEditDsF data) { + await _busStopDs.SaveAsync(data); return Ok(data); } [HttpPost] - public async Task Update(int id, BusStopEditDsF data){ - if (ModelState.IsValid) - { - await _busStopDs.SaveAsync(data,id); - return Ok(); - } else { - return NotFound(); - } - + public async Task Update(int id, [FromBody] BusStopEditDsF data){ + await _busStopDs.SaveAsync(data,id); + return Ok(); } // POST: BusStop/Create diff --git a/src/MapsDb/DataService/BusStopDs.cs b/src/MapsDb/DataService/BusStopDs.cs index b718e4b..f258361 100644 --- a/src/MapsDb/DataService/BusStopDs.cs +++ b/src/MapsDb/DataService/BusStopDs.cs @@ -40,7 +40,7 @@ namespace MapsDb.DataService public Task SaveAsync(BusStopEditDsF busStop, int? id = null){ return Task.Factory.StartNew(()=> { Save(busStop, id); }); } - private void Save(BusStopEditDsF busStop, int? id) + private async void Save(BusStopEditDsF busStop, int? id) { BusStop Bs = new BusStop{ RoadId = busStop.roadId, @@ -57,10 +57,22 @@ namespace MapsDb.DataService YearRepair = busStop.yearRepair, StateCommonId = busStop.stateCommonId }; - var busStopFromDb = _context.BusStop.SingleOrDefault(x => x.BusStopId == id); + var busStopFromDb = _context.BusStop.FirstOrDefault(x => x.BusStopId == id); if(busStopFromDb != null) { - busStopFromDb = Bs; + busStopFromDb.RoadId = busStop.roadId; + busStopFromDb.RegionId = busStop.regionId; + busStopFromDb.SettlementId = busStop.settlementId; + busStopFromDb.LocationLeft = busStop.locationLeft; + busStopFromDb.LocationRight = busStop.locationRight; + busStopFromDb.SurfaceTypeId = busStop.surfaceTypeId; + busStopFromDb.AreaStopAvailability = busStop.areaStopAvailability; + busStopFromDb.AreaLandAvailability = busStop.areaLandAvailability; + busStopFromDb.PocketAvailability = busStop.pocketAvailability; + busStopFromDb.ToiletAvailability = busStop.toiletAvailability; + busStopFromDb.YearBuild = busStop.yearBuild; + busStopFromDb.YearRepair = busStop.yearRepair; + busStopFromDb.StateCommonId = busStop.stateCommonId; } else { -- libgit2 0.21.4