Commit 94ffda14065b6ab5d25c52ed714e112165a70cae
1 parent
b9b3b8dd
Delete action
Showing
3 changed files
with
29 additions
and
0 deletions
Show diff stats
src/Maps/Controllers/BusStopController.cs
| @@ -7,6 +7,8 @@ using MapsDb; | @@ -7,6 +7,8 @@ using MapsDb; | ||
| 7 | using MapsDb.Interfaces; | 7 | using MapsDb.Interfaces; |
| 8 | using MapsDb.DataService; | 8 | using MapsDb.DataService; |
| 9 | using MapsModels.ViewModels; | 9 | using MapsModels.ViewModels; |
| 10 | +using System; | ||
| 11 | + | ||
| 10 | namespace Maps.Controllers | 12 | namespace Maps.Controllers |
| 11 | { | 13 | { |
| 12 | public class BusStopController : Controller | 14 | public class BusStopController : Controller |
| @@ -83,6 +85,25 @@ namespace Maps.Controllers | @@ -83,6 +85,25 @@ namespace Maps.Controllers | ||
| 83 | return Json(vm); | 85 | return Json(vm); |
| 84 | } | 86 | } |
| 85 | 87 | ||
| 88 | + [HttpDelete] | ||
| 89 | + public async Task<IActionResult> Delete(int? id) | ||
| 90 | + { | ||
| 91 | + if (id == null) | ||
| 92 | + { | ||
| 93 | + return NotFound(); | ||
| 94 | + } | ||
| 95 | + int busStop; | ||
| 96 | + try | ||
| 97 | + { | ||
| 98 | + busStop = await _busStopDs.DeleteAsync(id); | ||
| 99 | + } | ||
| 100 | + catch (ArgumentNullException e) | ||
| 101 | + { | ||
| 102 | + return NotFound(); | ||
| 103 | + } | ||
| 104 | + return Json(busStop); | ||
| 105 | + } | ||
| 106 | + | ||
| 86 | // // POST: BusStop/Create | 107 | // // POST: BusStop/Create |
| 87 | // // To protect from overposting attacks, please enable the specific properties you want to bind to, for | 108 | // // To protect from overposting attacks, please enable the specific properties you want to bind to, for |
| 88 | // // more details see http://go.microsoft.com/fwlink/?LinkId=317598. | 109 | // // more details see http://go.microsoft.com/fwlink/?LinkId=317598. |
src/MapsDb/DataService/BusStopDs.cs
| @@ -4,6 +4,7 @@ using System.Threading.Tasks; | @@ -4,6 +4,7 @@ using System.Threading.Tasks; | ||
| 4 | using MapsDb.Interfaces; | 4 | using MapsDb.Interfaces; |
| 5 | using MapsDb.Models; | 5 | using MapsDb.Models; |
| 6 | using MapsModels.DsModels; | 6 | using MapsModels.DsModels; |
| 7 | +using Microsoft.EntityFrameworkCore; | ||
| 7 | 8 | ||
| 8 | namespace MapsDb.DataService | 9 | namespace MapsDb.DataService |
| 9 | { | 10 | { |
| @@ -64,5 +65,11 @@ namespace MapsDb.DataService | @@ -64,5 +65,11 @@ namespace MapsDb.DataService | ||
| 64 | YearRepair = x.YearRepair | 65 | YearRepair = x.YearRepair |
| 65 | }).Single(); | 66 | }).Single(); |
| 66 | } | 67 | } |
| 68 | + public async Task<int> DeleteAsync(int? Id) | ||
| 69 | + { | ||
| 70 | + var busStop = await _context.BusStop.SingleOrDefaultAsync(x => x.BusStopId == Id); | ||
| 71 | + _context.BusStop.Remove(busStop); | ||
| 72 | + return await _context.SaveChangesAsync(); | ||
| 73 | + } | ||
| 67 | } | 74 | } |
| 68 | } | 75 | } |
| 69 | \ No newline at end of file | 76 | \ No newline at end of file |
src/MapsDb/Interfaces/IBusStopDs.cs
| @@ -9,5 +9,6 @@ namespace MapsDb.Interfaces | @@ -9,5 +9,6 @@ namespace MapsDb.Interfaces | ||
| 9 | Task<IList<BusStopListDsM>> GetIndexListAsync(); | 9 | Task<IList<BusStopListDsM>> GetIndexListAsync(); |
| 10 | Task SaveAsync(BusStop busStop); | 10 | Task SaveAsync(BusStop busStop); |
| 11 | Task<BusStopDetailsDsM> FindOneDetailsAsync(int Id); | 11 | Task<BusStopDetailsDsM> FindOneDetailsAsync(int Id); |
| 12 | + Task<int> DeleteAsync(int? Id); | ||
| 12 | } | 13 | } |
| 13 | } | 14 | } |
| 14 | \ No newline at end of file | 15 | \ No newline at end of file |