Commit ddeb0c633371f41c75e57371ee5a9acede761904

Authored by Administrator
1 parent f89dc177

add RoadSurfaceController

src/Maps/Controllers/BusStopController.cs
@@ -46,12 +46,12 @@ namespace Maps.Controllers @@ -46,12 +46,12 @@ namespace Maps.Controllers
46 46
47 return Json(vm); 47 return Json(vm);
48 } 48 }
49 - catch (NullReferenceException e) 49 + catch (NullReferenceException)
50 { 50 {
51 Response.StatusCode = 400; 51 Response.StatusCode = 400;
52 return Json("There is no field with name " + data.sort); 52 return Json("There is no field with name " + data.sort);
53 } 53 }
54 - catch (Exception e) 54 + catch (Exception)
55 { 55 {
56 return NotFound(); 56 return NotFound();
57 } 57 }
src/Maps/Controllers/RoadSurfaceController.cs
@@ -19,74 +19,102 @@ namespace Maps.Controllers @@ -19,74 +19,102 @@ namespace Maps.Controllers
19 private readonly ISurfaceTypeDs _surfaceTypeDs; 19 private readonly ISurfaceTypeDs _surfaceTypeDs;
20 private readonly IStateCommonDs _stateCommonDs; 20 private readonly IStateCommonDs _stateCommonDs;
21 private readonly IRoadSurfaceDs _roadSurfaceDs; 21 private readonly IRoadSurfaceDs _roadSurfaceDs;
22 - public RoadSurfaceController(IRoadSurfaceDs RoadSurfaceDs, IStateCommonDs StateCommonDs, IRoadDs RoadDs, IRegionDs RegionDs, ISurfaceTypeDs SurfaceTypeDs) 22 + private readonly IRoadDirectionDs _roadDirectionDs;
  23 + private readonly ISurfaceTreatmentDs _surfaceTreatmentDs;
  24 + public RoadSurfaceController(
  25 + IRoadSurfaceDs RoadSurfaceDs,
  26 + IStateCommonDs StateCommonDs,
  27 + IRoadDs RoadDs,
  28 + IRegionDs RegionDs,
  29 + ISurfaceTypeDs SurfaceTypeDs,
  30 + ISurfaceTreatmentDs SurfaceTreatmentDs,
  31 + IRoadDirectionDs RoadDirectionDs
  32 + )
23 { 33 {
24 _roadDs = RoadDs; 34 _roadDs = RoadDs;
25 _surfaceTypeDs = SurfaceTypeDs; 35 _surfaceTypeDs = SurfaceTypeDs;
26 _regionDs = RegionDs; 36 _regionDs = RegionDs;
27 _stateCommonDs = StateCommonDs; 37 _stateCommonDs = StateCommonDs;
28 - _roadSurfaceDs = RoadSurfaceDs; 38 + _roadSurfaceDs = RoadSurfaceDs;
  39 + _surfaceTreatmentDs = SurfaceTreatmentDs;
  40 + _roadDirectionDs = RoadDirectionDs;
29 } 41 }
30 42
31 // GET: BusStop 43 // GET: BusStop
32 [HttpGet] 44 [HttpGet]
33 public async Task<IActionResult> Index([FromQuery] PaginationDsM data) 45 public async Task<IActionResult> Index([FromQuery] PaginationDsM data)
34 { 46 {
35 - var Data = await _roadSurfaceDs.GetIndexListAsync(data);  
36 47
37 - RoadSurfaceListVm vm = new RoadSurfaceListVm 48 + try
38 { 49 {
39 - RoadSurfaceEditDsM = Data.ToList()  
40 - }; 50 + var Data = await _roadSurfaceDs.GetIndexListAsync(data);
41 51
42 - return Json(vm); 52 + RoadSurfaceListVm vm = new RoadSurfaceListVm
  53 + {
  54 + RoadSurfaceEditDsM = Data.ToList()
  55 + };
  56 +
  57 + return Json(vm);
  58 + }
  59 + catch (NullReferenceException)
  60 + {
  61 + Response.StatusCode = 400;
  62 + return Json("There is no field with name " + data.sort);
  63 + }
  64 + catch (Exception)
  65 + {
  66 + return NotFound();
  67 + }
43 } 68 }
44 69
45 - //[HttpGet]  
46 - // public async Task<IActionResult> Directory(){  
47 - // var DepartmentAffiliation = await _departmentAffiliationDs.GetSelectListAsync();  
48 - // var Settlement = await _settlementDs.GetSelectListAsync();  
49 - // var Road = await _roadDs.GetSelectListAsync();  
50 - // var Region = await _regionDs.GetSelectListAsync();  
51 - // var ServiceObjectType = await _serviceObjectTypeDs.GetSelectListAsync();  
52 - // CatalogListVm vm = new CatalogListVm  
53 - // {  
54 - // DepartmentAffiliationSelectListDsM = DepartmentAffiliation.ToList(),  
55 - // SettlementSelectListDsM = Settlement.ToList(),  
56 - // ServiceObjectTypeSelectListDsM = ServiceObjectType.ToList(),  
57 - // RoadSelectListDsM = Road.ToList(),  
58 - // RegionSelectListDsM = Region.ToList()  
59 - // };  
60 - // return Json(vm);  
61 - // } 70 + [HttpGet]
  71 + public async Task<IActionResult> Directory(){
  72 + var Road = await _roadDs.GetSelectListAsync();
  73 + var Region = await _regionDs.GetSelectListAsync();
  74 + var SurfaceType = await _surfaceTypeDs.GetSelectListAsync();
  75 + var StateCommon = await _stateCommonDs.GetSelectListAsync();
  76 + var SurfaceTreatment = await _surfaceTreatmentDs.GetSelectListAsync();
  77 + var RoadDirection = await _roadDirectionDs.GetSelectListAsync();
  78 +
  79 + CatalogListVm vm = new CatalogListVm
  80 + {
  81 + RoadSelectListDsM = Road.ToList(),
  82 + RegionSelectListDsM = Region.ToList(),
  83 + SurfaceTypeSelectListDsM = SurfaceType.ToList(),
  84 + StateCommonSelectListDsM = StateCommon.ToList(),
  85 + SurfaceTreatmentSelectListDsM = SurfaceTreatment.ToList(),
  86 + RoadDirectionSelectListDsM = RoadDirection.ToList()
  87 + };
  88 + return Json(vm);
  89 + }
62 90
63 91
64 - // [HttpPost]  
65 - // public async Task<IActionResult> Create([FromBody] ServiceObjectEditDsM data)  
66 - // {  
67 - // var result = await _serviceObjectDs.CreateAsync(data);  
68 - // return Json(result);  
69 - // } 92 + [HttpPost]
  93 + public async Task<IActionResult> Create([FromBody] RoadSurfaceEditDsM data)
  94 + {
  95 + var result = await _roadSurfaceDs.CreateAsync(data);
  96 + return Json(result);
  97 + }
70 98
71 - // [HttpPost]  
72 - // public async Task<IActionResult> Update(int id, [FromBody] ServiceObjectEditDsM data){  
73 - // await _serviceObjectDs.UpdateAsync(data,id);  
74 - // return Json(String.Empty);  
75 - // } 99 + [HttpPost]
  100 + public async Task<IActionResult> Update(int id, [FromBody] RoadSurfaceEditDsM data){
  101 + await _roadSurfaceDs.UpdateAsync(data,id);
  102 + return Json(String.Empty);
  103 + }
76 104
77 105
78 - // [HttpDelete]  
79 - // public async Task<IActionResult> Delete(int id)  
80 - // {  
81 - // try  
82 - // {  
83 - // int data = await _serviceObjectDs.DeleteAsync(id);  
84 - // return Json(data);  
85 - // }  
86 - // catch (ArgumentNullException )  
87 - // {  
88 - // return NotFound();  
89 - // }  
90 - // } 106 + [HttpDelete]
  107 + public async Task<IActionResult> Delete(int id)
  108 + {
  109 + try
  110 + {
  111 + int data = await _roadSurfaceDs.DeleteAsync(id);
  112 + return Json(data);
  113 + }
  114 + catch (ArgumentNullException )
  115 + {
  116 + return NotFound();
  117 + }
  118 + }
91 } 119 }
92 } 120 }
src/Maps/Controllers/ServiceObjectController.cs
@@ -35,14 +35,26 @@ namespace Maps.Controllers @@ -35,14 +35,26 @@ namespace Maps.Controllers
35 [HttpGet] 35 [HttpGet]
36 public async Task<IActionResult> Index([FromQuery] PaginationDsM data) 36 public async Task<IActionResult> Index([FromQuery] PaginationDsM data)
37 { 37 {
38 - var Data = await _serviceObjectDs.GetIndexListAsync(data);  
39 -  
40 - ServiceObjectListVm vm = new ServiceObjectListVm 38 + try
41 { 39 {
42 - ServiceObjectEditDsM = Data.ToList()  
43 - }; 40 + var Data = await _serviceObjectDs.GetIndexListAsync(data);
44 41
45 - return Json(vm); 42 + ServiceObjectListVm vm = new ServiceObjectListVm
  43 + {
  44 + ServiceObjectEditDsM = Data.ToList()
  45 + };
  46 +
  47 + return Json(vm);
  48 + }
  49 + catch (NullReferenceException)
  50 + {
  51 + Response.StatusCode = 400;
  52 + return Json("There is no field with name " + data.sort);
  53 + }
  54 + catch (Exception)
  55 + {
  56 + return NotFound();
  57 + }
46 } 58 }
47 59
48 [HttpGet] 60 [HttpGet]
src/MapsDb/DataService/RoadDirectionDs.cs 0 → 100644
  1 +using System.Collections.Generic;
  2 +using System.Linq;
  3 +using System.Threading.Tasks;
  4 +using MapsDb.Interfaces;
  5 +using MapsDb.Models;
  6 +using MapsModels.DsModels;
  7 +namespace MapsDb.DataService
  8 +{
  9 + public class RoadDirectionDs : IRoadDirectionDs
  10 + {
  11 + private PostgresDbContext _context;
  12 + public RoadDirectionDs(){
  13 + _context = new PostgresDbContext();
  14 + }
  15 + public Task<IList<RoadDirectionSelectListDsM>> GetSelectListAsync(){
  16 + return Task.Factory.StartNew(GetSelectList);
  17 + }
  18 + private IList<RoadDirectionSelectListDsM> GetSelectList()
  19 + {
  20 + return _context.RoadDirection.Select(x => new RoadDirectionSelectListDsM
  21 + {
  22 + RoadDirectionId = x.RoadDirectionId,
  23 + Name = x.Name
  24 + }).ToList();
  25 + }
  26 +
  27 + }
  28 +}
0 \ No newline at end of file 29 \ No newline at end of file
src/MapsDb/DataService/SurfaceTreatmentDs.cs 0 → 100644
  1 +using System.Collections.Generic;
  2 +using System.Linq;
  3 +using System.Threading.Tasks;
  4 +using MapsDb.Interfaces;
  5 +using MapsDb.Models;
  6 +using MapsModels.DsModels;
  7 +namespace MapsDb.DataService
  8 +{
  9 + public class SurfaceTreatmentDs : ISurfaceTreatmentDs
  10 + {
  11 + private PostgresDbContext _context;
  12 + public SurfaceTreatmentDs(){
  13 + _context = new PostgresDbContext();
  14 + }
  15 + public Task<IList<SurfaceTreatmentSelectListDsM>> GetSelectListAsync(){
  16 + return Task.Factory.StartNew(GetSelectList);
  17 + }
  18 + private IList<SurfaceTreatmentSelectListDsM> GetSelectList()
  19 + {
  20 + return _context.SurfaceTreatment.Select(x => new SurfaceTreatmentSelectListDsM
  21 + {
  22 + SurfaceTreatmentId = x.SurfaceTreatmentId,
  23 + Name = x.Name
  24 + }).ToList();
  25 + }
  26 +
  27 + }
  28 +}
0 \ No newline at end of file 29 \ No newline at end of file
src/MapsDb/Interfaces/IRoadDirectionDs.cs 0 → 100644
  1 +using System.Collections.Generic;
  2 +using System.Threading.Tasks;
  3 +using MapsModels.DsModels;
  4 +using MapsDb.Models;
  5 +namespace MapsDb.Interfaces
  6 +{
  7 + public interface IRoadDirectionDs
  8 + {
  9 + Task<IList<RoadDirectionSelectListDsM>> GetSelectListAsync();
  10 + }
  11 +}
0 \ No newline at end of file 12 \ No newline at end of file
src/MapsDb/Interfaces/ISurfaceTreatmentDs.cs 0 → 100644
  1 +using System.Collections.Generic;
  2 +using System.Threading.Tasks;
  3 +using MapsModels.DsModels;
  4 +using MapsDb.Models;
  5 +namespace MapsDb.Interfaces
  6 +{
  7 + public interface ISurfaceTreatmentDs
  8 + {
  9 + Task<IList<SurfaceTreatmentSelectListDsM>> GetSelectListAsync();
  10 + }
  11 +}
0 \ No newline at end of file 12 \ No newline at end of file
src/MapsDb/Models/RoadDirection.cs
@@ -13,7 +13,7 @@ namespace MapsDb.Models @@ -13,7 +13,7 @@ namespace MapsDb.Models
13 } 13 }
14 14
15 public int RoadDirectionId { get; set; } 15 public int RoadDirectionId { get; set; }
16 - public string DirectionName { get; set; } 16 + public string Name { get; set; }
17 17
18 public virtual ICollection<FlowIntensity> FlowIntensity { get; set; } 18 public virtual ICollection<FlowIntensity> FlowIntensity { get; set; }
19 public virtual ICollection<RoadService> RoadService { get; set; } 19 public virtual ICollection<RoadService> RoadService { get; set; }
src/MapsDb/PostgresDbContext.cs
@@ -353,9 +353,9 @@ namespace MapsDb @@ -353,9 +353,9 @@ namespace MapsDb
353 353
354 entity.Property(e => e.RoadDirectionId).HasColumnName("road_direction_id"); 354 entity.Property(e => e.RoadDirectionId).HasColumnName("road_direction_id");
355 355
356 - entity.Property(e => e.DirectionName) 356 + entity.Property(e => e.Name)
357 .IsRequired() 357 .IsRequired()
358 - .HasColumnName("direction_name") 358 + .HasColumnName("name")
359 .HasColumnType("varchar") 359 .HasColumnType("varchar")
360 .HasMaxLength(255); 360 .HasMaxLength(255);
361 }); 361 });
src/MapsModels/DsModels/RoadDirectionSelectListDsM.cs 0 → 100644
  1 +namespace MapsModels.DsModels
  2 +{
  3 + public class RoadDirectionSelectListDsM
  4 + {
  5 + public int RoadDirectionId { get; set; }
  6 + public string Name { get; set; }
  7 + }
  8 +}
0 \ No newline at end of file 9 \ No newline at end of file
src/MapsModels/DsModels/SurfaceTreatmentSelectListDsM.cs 0 → 100644
  1 +namespace MapsModels.DsModels
  2 +{
  3 + public class SurfaceTreatmentSelectListDsM
  4 + {
  5 + public int SurfaceTreatmentId { get; set; }
  6 + public string Name { get; set; }
  7 + }
  8 +}
0 \ No newline at end of file 9 \ No newline at end of file
src/MapsModels/ViewModels/CatalogListVm.cs
@@ -12,5 +12,7 @@ namespace MapsModels.ViewModels @@ -12,5 +12,7 @@ namespace MapsModels.ViewModels
12 public List<SettlementSelectListDsM> SettlementSelectListDsM { get; set; } 12 public List<SettlementSelectListDsM> SettlementSelectListDsM { get; set; }
13 public List<RoadSelectListDsM> RoadSelectListDsM { get; set; } 13 public List<RoadSelectListDsM> RoadSelectListDsM { get; set; }
14 public List<RegionSelectListDsM> RegionSelectListDsM { get; set; } 14 public List<RegionSelectListDsM> RegionSelectListDsM { get; set; }
  15 + public List<RoadDirectionSelectListDsM> RoadDirectionSelectListDsM { get; set; }
  16 + public List<SurfaceTreatmentSelectListDsM> SurfaceTreatmentSelectListDsM { get; set; }
15 } 17 }
16 } 18 }