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 | 7 | using MapsDb.Interfaces; |
| 8 | 8 | using MapsDb.DataService; |
| 9 | 9 | using MapsModels.ViewModels; |
| 10 | +using System; | |
| 11 | + | |
| 10 | 12 | namespace Maps.Controllers |
| 11 | 13 | { |
| 12 | 14 | public class BusStopController : Controller |
| ... | ... | @@ -83,6 +85,25 @@ namespace Maps.Controllers |
| 83 | 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 | 107 | // // POST: BusStop/Create |
| 87 | 108 | // // To protect from overposting attacks, please enable the specific properties you want to bind to, for |
| 88 | 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 | 4 | using MapsDb.Interfaces; |
| 5 | 5 | using MapsDb.Models; |
| 6 | 6 | using MapsModels.DsModels; |
| 7 | +using Microsoft.EntityFrameworkCore; | |
| 7 | 8 | |
| 8 | 9 | namespace MapsDb.DataService |
| 9 | 10 | { |
| ... | ... | @@ -64,5 +65,11 @@ namespace MapsDb.DataService |
| 64 | 65 | YearRepair = x.YearRepair |
| 65 | 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 | 76 | \ No newline at end of file | ... | ... |
src/MapsDb/Interfaces/IBusStopDs.cs