Blame view

src/Maps/Controllers/BusStopController.cs 3.4 KB
32912d0b   Administrator   first commit
1
2
3
4
5
6
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.AspNetCore.Mvc.Rendering;
  using Microsoft.EntityFrameworkCore;
  using MapsDb;
b9b3b8dd   Administrator   add deteils and c...
7
  using MapsDb.Interfaces;
32912d0b   Administrator   first commit
8
9
  using MapsDb.DataService;
  using MapsModels.ViewModels;
abec55bf   Administrator   Finish busStop mo...
10
  using MapsModels.DsModels;
94ffda14   Yarik   Delete action
11
12
  using System;
  
32912d0b   Administrator   first commit
13
14
15
16
17
  namespace Maps.Controllers
  {
      public class BusStopController : Controller
      {
          private readonly IBusStopDs _busStopDs;
b9b3b8dd   Administrator   add deteils and c...
18
19
20
          private readonly IRoadDs _roadDs;
          private readonly ISettlementDs _settlementDs;
          private readonly IStateCommonDs _stateCommonDs;
41da292f   Administrator   fix d
21
          private readonly IRegionDs _regionDs;
b9b3b8dd   Administrator   add deteils and c...
22
          private readonly ISurfaceTypeDs _surfaceTypeDs;
32912d0b   Administrator   first commit
23
  
41da292f   Administrator   fix d
24
          public BusStopController(IBusStopDs BusStopDs, IRoadDs RoadDs, ISettlementDs SettlementDs, IRegionDs RegionDs, IStateCommonDs StateCommonDs, ISurfaceTypeDs SurfaceTypeDs)
32912d0b   Administrator   first commit
25
          {
b9b3b8dd   Administrator   add deteils and c...
26
27
28
29
              _busStopDs = BusStopDs;
              _roadDs = RoadDs;    
              _settlementDs = SettlementDs;    
              _stateCommonDs = StateCommonDs;    
41da292f   Administrator   fix d
30
              _regionDs = RegionDs;    
b9b3b8dd   Administrator   add deteils and c...
31
              _surfaceTypeDs = SurfaceTypeDs;        
32912d0b   Administrator   first commit
32
33
34
35
          }
  
          // GET: BusStop
          [HttpGet]
db607025   Administrator   add pagination
36
          public async Task<IActionResult> Index([FromQuery] PaginationDsM data)
32912d0b   Administrator   first commit
37
          {
db607025   Administrator   add pagination
38
39
40
41
42
43
44
45
              try
              {
                  var busStops = await _busStopDs.GetIndexListAsync(data);
  
                  BusStopListVm vm = new BusStopListVm
                  {
                      BusStopEditDsM = busStops.ToList()
                  };
5414fbd7   Administrator   change ds
46
  
db607025   Administrator   add pagination
47
48
                  return Json(vm);
              }
ddeb0c63   Administrator   add RoadSurfaceCo...
49
              catch (NullReferenceException)
5414fbd7   Administrator   change ds
50
              {
db607025   Administrator   add pagination
51
52
53
                  Response.StatusCode = 400;
                  return Json("There is no field with name " + data.sort);
              }
ddeb0c63   Administrator   add RoadSurfaceCo...
54
              catch (Exception)
db607025   Administrator   add pagination
55
56
57
58
              {
                  return NotFound();
              }
  
5414fbd7   Administrator   change ds
59
  
5414fbd7   Administrator   change ds
60
61
62
63
          }
  
          [HttpGet]
          public async Task<IActionResult> Directory(){
2de47257   Administrator   add one ds with a...
64
65
66
67
68
              var SurfaceType = await _surfaceTypeDs.GetSelectListAsync();
              var StateCommon = await _stateCommonDs.GetSelectListAsync();
              var Settlement = await _settlementDs.GetSelectListAsync();
              var Road = await _roadDs.GetSelectListAsync();
              var Region = await _regionDs.GetSelectListAsync();
32912d0b   Administrator   first commit
69
  
27918c1f   Administrator   add service object
70
              CatalogListVm vm = new CatalogListVm
32912d0b   Administrator   first commit
71
              {
2de47257   Administrator   add one ds with a...
72
73
74
75
76
                  SurfaceTypeSelectListDsM = SurfaceType.ToList(),
                  StateCommonSelectListDsM = StateCommon.ToList(),
                  SettlementSelectListDsM = Settlement.ToList(),
                  RoadSelectListDsM = Road.ToList(),
                  RegionSelectListDsM = Region.ToList()
32912d0b   Administrator   first commit
77
              };
32912d0b   Administrator   first commit
78
79
80
              return Json(vm);
          }
  
44582203   Administrator   bag fix
81
  
7fd789ff   Yarik   Cors
82
          [HttpPost]
27918c1f   Administrator   add service object
83
          public async Task<IActionResult> Create([FromBody] BusStopEditDsM data)
b9b3b8dd   Administrator   add deteils and c...
84
          {
e02ee314   Administrator   add update and cr...
85
              var result = await _busStopDs.CreateAsync(data);
7230fa31   Yarik   Fixes
86
              return Json(result);
b9b3b8dd   Administrator   add deteils and c...
87
          }
44582203   Administrator   bag fix
88
  
7fd789ff   Yarik   Cors
89
          [HttpPost]
27918c1f   Administrator   add service object
90
          public async Task<IActionResult> Update(int id, [FromBody] BusStopEditDsM data){
e02ee314   Administrator   add update and cr...
91
                  await _busStopDs.UpdateAsync(data,id);
7230fa31   Yarik   Fixes
92
                  return Json(String.Empty);
e4970e8a   Administrator   commit
93
          }
a9a5efb8   Administrator   test
94
  
27918c1f   Administrator   add service object
95
       
94ffda14   Yarik   Delete action
96
          [HttpDelete]
e02ee314   Administrator   add update and cr...
97
          public async Task<IActionResult> Delete(int id)
e6477bbf   Administrator   test2
98
          {   
94ffda14   Yarik   Delete action
99
100
              try
              {
e6477bbf   Administrator   test2
101
102
                  int busStop = await _busStopDs.DeleteAsync(id);
                   return Json(busStop);
94ffda14   Yarik   Delete action
103
              }
abec55bf   Administrator   Finish busStop mo...
104
              catch (ArgumentNullException )
94ffda14   Yarik   Delete action
105
106
107
              {
                  return NotFound();
              }
94ffda14   Yarik   Delete action
108
          }
32912d0b   Administrator   first commit
109
110
      }
  }