diff --git a/src/Maps/Controllers/BusStopController.cs b/src/Maps/Controllers/BusStopController.cs index 15682b6..8c547b3 100755 --- a/src/Maps/Controllers/BusStopController.cs +++ b/src/Maps/Controllers/BusStopController.cs @@ -7,6 +7,7 @@ using MapsDb; using MapsDb.Interfaces; using MapsDb.DataService; using MapsModels.ViewModels; +using MapsModels.DsModels; using System; namespace Maps.Controllers @@ -86,26 +87,37 @@ namespace Maps.Controllers } - // // POST: BusStop/Create - // // To protect from overposting attacks, please enable the specific properties you want to bind to, for - // // more details see http://go.microsoft.com/fwlink/?LinkId=317598. - // [HttpPost] - // [ValidateAntiForgeryToken] - // public async Task Create( busStop) - // { - // if (ModelState.IsValid) - // { - // _context.Add(busStop); - // await _context.SaveChangesAsync(); - // return RedirectToAction("Index"); - // } - // ViewData["RegionId"] = new SelectList(_context.Region, "RegionId", "RegionId", busStop.RegionId); - // ViewData["RoadId"] = new SelectList(_context.Road, "RoadId", "RoadId", busStop.RoadId); - // ViewData["SettlementId"] = new SelectList(_context.Settlement, "SettlementId", "Name", busStop.SettlementId); - // ViewData["StateCommonId"] = new SelectList(_context.StateCommon, "StateCommonId", "StateCommonId", busStop.StateCommonId); - // ViewData["SurfaceTypeId"] = new SelectList(_context.SurfaceType, "SurfaceTypeId", "SurfaceTypeId", busStop.SurfaceTypeId); - // return View(busStop); - // } + // POST: BusStop/Create + // To protect from overposting attacks, please enable the specific properties you want to bind to, for + // more details see http://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(BusStopEditDsM busStop) + { + if (ModelState.IsValid) + { + await _busStopDs.SaveAsync(busStop); + return Ok(); + } else { + return NotFound(); + } + + // var SurfaceType = await _surfaceTypeDs.GetSelectListAsync(); + // var StateCommon = await _stateCommonDs.GetSelectListAsync(); + // var Settlement = await _settlementDs.GetSelectListAsync(); + // var Road = await _roadDs.GetSelectListAsync(); + // var Region = await _regionDc.GetSelectListAsync(); + + // CreateBusStopVm vm = new CreateBusStopVm + // { + // SurfaceTypeSelectListDsM = SurfaceType.ToList(), + // StateCommonSelectListDsM = StateCommon.ToList(), + // SettlementSelectListDsM = Settlement.ToList(), + // RoadSelectListDsM = Road.ToList(), + // RegionSelectListDsM = Region.ToList() + // }; + // return Json(vm); + } [HttpDelete] public async Task Delete(int? id) @@ -120,7 +132,7 @@ namespace Maps.Controllers int busStop = await _busStopDs.DeleteAsync(id); return Json(busStop); } - catch (ArgumentNullException e) + catch (ArgumentNullException ) { return NotFound(); } diff --git a/src/MapsDb/DataService/BusStopDs.cs b/src/MapsDb/DataService/BusStopDs.cs index 0ffd5ad..28f8710 100644 --- a/src/MapsDb/DataService/BusStopDs.cs +++ b/src/MapsDb/DataService/BusStopDs.cs @@ -5,7 +5,6 @@ using MapsDb.Interfaces; using MapsDb.Models; using MapsModels.DsModels; using Microsoft.EntityFrameworkCore; - namespace MapsDb.DataService { public class BusStopDs : IBusStopDs @@ -30,20 +29,36 @@ namespace MapsDb.DataService }).ToList(); } - public Task SaveAsync(BusStop busStop){ - return Task.Factory.StartNew(()=> { Save(busStop); }); + public Task SaveAsync(BusStopEditDsM busStop, int? id = null){ + return Task.Factory.StartNew(()=> { Save(busStop, id); }); } - private void Save(BusStop busStop) - { - var busStopFromDb = _context.BusStop.SingleOrDefault(x => x.BusStopId == busStop.BusStopId);; + private void Save(BusStopEditDsM busStop, int? id) + { + BusStop Bs = new BusStop{ + RoadId = busStop.RoadId, + RegionId = busStop.RegionId, + SettlementId = busStop.SettlementId, + LocationLeft = busStop.LocationLeft, + LocationRight = busStop.LocationRight, + SurfaceTypeId = busStop.SurfaceTypeId, + AreaStopAvailability = busStop.AreaStopAvailability, + AreaLandAvailability = busStop.AreaLandAvailability, + PocketAvailability = busStop.PocketAvailability, + ToiletAvailability = busStop.ToiletAvailability, + YearBuild = busStop.YearBuild, + YearRepair = busStop.YearRepair, + StateCommonId = busStop.StateCommonId + }; + var busStopFromDb = _context.BusStop.SingleOrDefault(x => x.BusStopId == id); if(busStopFromDb != null) { - busStopFromDb = busStop; + busStopFromDb = Bs; } else { - _context.BusStop.Add(busStop); + _context.BusStop.Add(Bs); } + _context.SaveChanges(); } public Task FindOneDetailsAsync(int Id){ return Task.Factory.StartNew(()=> { return FindOneDetails(Id); }); diff --git a/src/MapsDb/Interfaces/IBusStopDs.cs b/src/MapsDb/Interfaces/IBusStopDs.cs index 531e66e..a045a0d 100644 --- a/src/MapsDb/Interfaces/IBusStopDs.cs +++ b/src/MapsDb/Interfaces/IBusStopDs.cs @@ -7,7 +7,7 @@ namespace MapsDb.Interfaces public interface IBusStopDs { Task> GetIndexListAsync(); - Task SaveAsync(BusStop busStop); + Task SaveAsync(BusStopEditDsM busStop); Task FindOneDetailsAsync(int Id); Task DeleteAsync(int? Id); } diff --git a/src/MapsModels/DsModels/BusStopEditDsM.cs b/src/MapsModels/DsModels/BusStopEditDsM.cs index 1b4c1e8..48fbe63 100644 --- a/src/MapsModels/DsModels/BusStopEditDsM.cs +++ b/src/MapsModels/DsModels/BusStopEditDsM.cs @@ -1,12 +1,20 @@ namespace MapsModels.DsModels { - public class BusStopListDsM + public class BusStopEditDsM { - public string Road { get; set; } - public string Region { get; set; } - public string Settlement { get; set; } + public int? RoadId { get; set; } + public int? RegionId { get; set; } + public int? SettlementId { get; set; } public double? LocationLeft { get; set; } public double? LocationRight { get; set; } - public string StateCommon { get; set; } + public int? SurfaceTypeId { get; set; } + public int? AreaStopAvailability { get; set; } + public int? AreaLandAvailability { get; set; } + public int? PocketAvailability { get; set; } + public int? ToiletAvailability { get; set; } + public int? YearBuild { get; set; } + public int? YearRepair { get; set; } + public int? StateCommonId { get; set; } + } } \ No newline at end of file -- libgit2 0.21.4