Commit abec55bf0747f62c8dea1998de444bf99caada58
1 parent
e6477bbf
Finish busStop model rest crud
Showing
4 changed files
with
70 additions
and
35 deletions
Show diff stats
src/Maps/Controllers/BusStopController.cs
| ... | ... | @@ -7,6 +7,7 @@ using MapsDb; |
| 7 | 7 | using MapsDb.Interfaces; |
| 8 | 8 | using MapsDb.DataService; |
| 9 | 9 | using MapsModels.ViewModels; |
| 10 | +using MapsModels.DsModels; | |
| 10 | 11 | using System; |
| 11 | 12 | |
| 12 | 13 | namespace Maps.Controllers |
| ... | ... | @@ -86,26 +87,37 @@ namespace Maps.Controllers |
| 86 | 87 | } |
| 87 | 88 | |
| 88 | 89 | |
| 89 | - // // POST: BusStop/Create | |
| 90 | - // // To protect from overposting attacks, please enable the specific properties you want to bind to, for | |
| 91 | - // // more details see http://go.microsoft.com/fwlink/?LinkId=317598. | |
| 92 | - // [HttpPost] | |
| 93 | - // [ValidateAntiForgeryToken] | |
| 94 | - // public async Task<IActionResult> Create( busStop) | |
| 95 | - // { | |
| 96 | - // if (ModelState.IsValid) | |
| 97 | - // { | |
| 98 | - // _context.Add(busStop); | |
| 99 | - // await _context.SaveChangesAsync(); | |
| 100 | - // return RedirectToAction("Index"); | |
| 101 | - // } | |
| 102 | - // ViewData["RegionId"] = new SelectList(_context.Region, "RegionId", "RegionId", busStop.RegionId); | |
| 103 | - // ViewData["RoadId"] = new SelectList(_context.Road, "RoadId", "RoadId", busStop.RoadId); | |
| 104 | - // ViewData["SettlementId"] = new SelectList(_context.Settlement, "SettlementId", "Name", busStop.SettlementId); | |
| 105 | - // ViewData["StateCommonId"] = new SelectList(_context.StateCommon, "StateCommonId", "StateCommonId", busStop.StateCommonId); | |
| 106 | - // ViewData["SurfaceTypeId"] = new SelectList(_context.SurfaceType, "SurfaceTypeId", "SurfaceTypeId", busStop.SurfaceTypeId); | |
| 107 | - // return View(busStop); | |
| 108 | - // } | |
| 90 | + // POST: BusStop/Create | |
| 91 | + // To protect from overposting attacks, please enable the specific properties you want to bind to, for | |
| 92 | + // more details see http://go.microsoft.com/fwlink/?LinkId=317598. | |
| 93 | + [HttpPost] | |
| 94 | + [ValidateAntiForgeryToken] | |
| 95 | + public async Task<IActionResult> Create(BusStopEditDsM busStop) | |
| 96 | + { | |
| 97 | + if (ModelState.IsValid) | |
| 98 | + { | |
| 99 | + await _busStopDs.SaveAsync(busStop); | |
| 100 | + return Ok(); | |
| 101 | + } else { | |
| 102 | + return NotFound(); | |
| 103 | + } | |
| 104 | + | |
| 105 | + // var SurfaceType = await _surfaceTypeDs.GetSelectListAsync(); | |
| 106 | + // var StateCommon = await _stateCommonDs.GetSelectListAsync(); | |
| 107 | + // var Settlement = await _settlementDs.GetSelectListAsync(); | |
| 108 | + // var Road = await _roadDs.GetSelectListAsync(); | |
| 109 | + // var Region = await _regionDc.GetSelectListAsync(); | |
| 110 | + | |
| 111 | + // CreateBusStopVm vm = new CreateBusStopVm | |
| 112 | + // { | |
| 113 | + // SurfaceTypeSelectListDsM = SurfaceType.ToList(), | |
| 114 | + // StateCommonSelectListDsM = StateCommon.ToList(), | |
| 115 | + // SettlementSelectListDsM = Settlement.ToList(), | |
| 116 | + // RoadSelectListDsM = Road.ToList(), | |
| 117 | + // RegionSelectListDsM = Region.ToList() | |
| 118 | + // }; | |
| 119 | + // return Json(vm); | |
| 120 | + } | |
| 109 | 121 | |
| 110 | 122 | [HttpDelete] |
| 111 | 123 | public async Task<IActionResult> Delete(int? id) |
| ... | ... | @@ -120,7 +132,7 @@ namespace Maps.Controllers |
| 120 | 132 | int busStop = await _busStopDs.DeleteAsync(id); |
| 121 | 133 | return Json(busStop); |
| 122 | 134 | } |
| 123 | - catch (ArgumentNullException e) | |
| 135 | + catch (ArgumentNullException ) | |
| 124 | 136 | { |
| 125 | 137 | return NotFound(); |
| 126 | 138 | } | ... | ... |
src/MapsDb/DataService/BusStopDs.cs
| ... | ... | @@ -5,7 +5,6 @@ using MapsDb.Interfaces; |
| 5 | 5 | using MapsDb.Models; |
| 6 | 6 | using MapsModels.DsModels; |
| 7 | 7 | using Microsoft.EntityFrameworkCore; |
| 8 | - | |
| 9 | 8 | namespace MapsDb.DataService |
| 10 | 9 | { |
| 11 | 10 | public class BusStopDs : IBusStopDs |
| ... | ... | @@ -30,20 +29,36 @@ namespace MapsDb.DataService |
| 30 | 29 | }).ToList(); |
| 31 | 30 | } |
| 32 | 31 | |
| 33 | - public Task SaveAsync(BusStop busStop){ | |
| 34 | - return Task.Factory.StartNew(()=> { Save(busStop); }); | |
| 32 | + public Task SaveAsync(BusStopEditDsM busStop, int? id = null){ | |
| 33 | + return Task.Factory.StartNew(()=> { Save(busStop, id); }); | |
| 35 | 34 | } |
| 36 | - private void Save(BusStop busStop) | |
| 37 | - { | |
| 38 | - var busStopFromDb = _context.BusStop.SingleOrDefault(x => x.BusStopId == busStop.BusStopId);; | |
| 35 | + private void Save(BusStopEditDsM busStop, int? id) | |
| 36 | + { | |
| 37 | + BusStop Bs = new BusStop{ | |
| 38 | + RoadId = busStop.RoadId, | |
| 39 | + RegionId = busStop.RegionId, | |
| 40 | + SettlementId = busStop.SettlementId, | |
| 41 | + LocationLeft = busStop.LocationLeft, | |
| 42 | + LocationRight = busStop.LocationRight, | |
| 43 | + SurfaceTypeId = busStop.SurfaceTypeId, | |
| 44 | + AreaStopAvailability = busStop.AreaStopAvailability, | |
| 45 | + AreaLandAvailability = busStop.AreaLandAvailability, | |
| 46 | + PocketAvailability = busStop.PocketAvailability, | |
| 47 | + ToiletAvailability = busStop.ToiletAvailability, | |
| 48 | + YearBuild = busStop.YearBuild, | |
| 49 | + YearRepair = busStop.YearRepair, | |
| 50 | + StateCommonId = busStop.StateCommonId | |
| 51 | + }; | |
| 52 | + var busStopFromDb = _context.BusStop.SingleOrDefault(x => x.BusStopId == id); | |
| 39 | 53 | if(busStopFromDb != null) |
| 40 | 54 | { |
| 41 | - busStopFromDb = busStop; | |
| 55 | + busStopFromDb = Bs; | |
| 42 | 56 | } |
| 43 | 57 | else |
| 44 | 58 | { |
| 45 | - _context.BusStop.Add(busStop); | |
| 59 | + _context.BusStop.Add(Bs); | |
| 46 | 60 | } |
| 61 | + _context.SaveChanges(); | |
| 47 | 62 | } |
| 48 | 63 | public Task<BusStopDetailsDsM> FindOneDetailsAsync(int Id){ |
| 49 | 64 | return Task.Factory.StartNew(()=> { return FindOneDetails(Id); }); | ... | ... |
src/MapsDb/Interfaces/IBusStopDs.cs
| ... | ... | @@ -7,7 +7,7 @@ namespace MapsDb.Interfaces |
| 7 | 7 | public interface IBusStopDs |
| 8 | 8 | { |
| 9 | 9 | Task<IList<BusStopListDsM>> GetIndexListAsync(); |
| 10 | - Task SaveAsync(BusStop busStop); | |
| 10 | + Task SaveAsync(BusStopEditDsM busStop); | |
| 11 | 11 | Task<BusStopDetailsDsM> FindOneDetailsAsync(int Id); |
| 12 | 12 | Task<int> DeleteAsync(int? Id); |
| 13 | 13 | } | ... | ... |
src/MapsModels/DsModels/BusStopEditDsM.cs
| 1 | 1 | namespace MapsModels.DsModels |
| 2 | 2 | { |
| 3 | - public class BusStopListDsM | |
| 3 | + public class BusStopEditDsM | |
| 4 | 4 | { |
| 5 | - public string Road { get; set; } | |
| 6 | - public string Region { get; set; } | |
| 7 | - public string Settlement { get; set; } | |
| 5 | + public int? RoadId { get; set; } | |
| 6 | + public int? RegionId { get; set; } | |
| 7 | + public int? SettlementId { get; set; } | |
| 8 | 8 | public double? LocationLeft { get; set; } |
| 9 | 9 | public double? LocationRight { get; set; } |
| 10 | - public string StateCommon { get; set; } | |
| 10 | + public int? SurfaceTypeId { get; set; } | |
| 11 | + public int? AreaStopAvailability { get; set; } | |
| 12 | + public int? AreaLandAvailability { get; set; } | |
| 13 | + public int? PocketAvailability { get; set; } | |
| 14 | + public int? ToiletAvailability { get; set; } | |
| 15 | + public int? YearBuild { get; set; } | |
| 16 | + public int? YearRepair { get; set; } | |
| 17 | + public int? StateCommonId { get; set; } | |
| 18 | + | |
| 11 | 19 | } |
| 12 | 20 | } |
| 13 | 21 | \ No newline at end of file | ... | ... |