Commit f59d6b52fcf3c75ea4cc70b4727e7ebdcfefb61c
1 parent
bb8e8397
add road width
Showing
9 changed files
with
261 additions
and
4 deletions
Show diff stats
1 | +using System.Linq; | |
2 | +using System.Threading.Tasks; | |
3 | +using Microsoft.AspNetCore.Mvc; | |
4 | +using Microsoft.AspNetCore.Mvc.Rendering; | |
5 | +using Microsoft.EntityFrameworkCore; | |
6 | +using MapsDb; | |
7 | +using MapsDb.Interfaces; | |
8 | +using MapsDb.DataService; | |
9 | +using MapsModels.ViewModels; | |
10 | +using MapsModels.DsModels; | |
11 | +using System; | |
12 | + | |
13 | +namespace Maps.Controllers | |
14 | +{ | |
15 | + public class RoadWidthController : Controller | |
16 | + { | |
17 | + private readonly IRoadDs _roadDs; | |
18 | + private readonly IRegionDs _regionDs; | |
19 | + private readonly IRoadWidthDs _roadWidthDs; | |
20 | + public RoadWidthController( | |
21 | + IRoadWidthDs RoadWidthDs, | |
22 | + IRoadDs RoadDs, | |
23 | + IRegionDs RegionDs | |
24 | + ) | |
25 | + { | |
26 | + _roadDs = RoadDs; | |
27 | + _regionDs = RegionDs; | |
28 | + _roadWidthDs = RoadWidthDs; | |
29 | + } | |
30 | + | |
31 | + // GET: BusStop | |
32 | + [HttpGet] | |
33 | + public async Task<IActionResult> Index([FromQuery] PaginationDsM data) | |
34 | + { | |
35 | + | |
36 | + try | |
37 | + { | |
38 | + var Data = await _roadWidthDs.GetIndexListAsync(data); | |
39 | + | |
40 | + RoadWidthListVm vm = new RoadWidthListVm | |
41 | + { | |
42 | + RoadWidthEditDsM = Data.ToList() | |
43 | + }; | |
44 | + | |
45 | + return Json(vm); | |
46 | + } | |
47 | + catch (NullReferenceException) | |
48 | + { | |
49 | + Response.StatusCode = 400; | |
50 | + return Json("There is no field with name " + data.sort); | |
51 | + } | |
52 | + catch (Exception) | |
53 | + { | |
54 | + return NotFound(); | |
55 | + } | |
56 | + } | |
57 | + | |
58 | + [HttpGet] | |
59 | + public async Task<IActionResult> Directory(){ | |
60 | + var Road = await _roadDs.GetSelectListAsync(); | |
61 | + var Region = await _regionDs.GetSelectListAsync(); | |
62 | + | |
63 | + CatalogListVm vm = new CatalogListVm | |
64 | + { | |
65 | + RoadSelectListDsM = Road.ToList(), | |
66 | + RegionSelectListDsM = Region.ToList() | |
67 | + }; | |
68 | + return Json(vm); | |
69 | + } | |
70 | + | |
71 | + | |
72 | + [HttpPost] | |
73 | + public async Task<IActionResult> Create([FromBody] RoadWidthEditDsM data) | |
74 | + { | |
75 | + var result = await _roadWidthDs.CreateAsync(data); | |
76 | + return Json(result); | |
77 | + } | |
78 | + | |
79 | + [HttpPost] | |
80 | + public async Task<IActionResult> Update(int id, [FromBody] RoadWidthEditDsM data){ | |
81 | + await _roadWidthDs.UpdateAsync(data,id); | |
82 | + return Json(String.Empty); | |
83 | + } | |
84 | + | |
85 | + | |
86 | + [HttpDelete] | |
87 | + public async Task<IActionResult> Delete(int id) | |
88 | + { | |
89 | + try | |
90 | + { | |
91 | + int data = await _roadWidthDs.DeleteAsync(id); | |
92 | + return Json(data); | |
93 | + } | |
94 | + catch (ArgumentNullException ) | |
95 | + { | |
96 | + return NotFound(); | |
97 | + } | |
98 | + } | |
99 | + } | |
100 | +} | ... | ... |
src/Maps/Startup.cs
... | ... | @@ -56,6 +56,7 @@ namespace Maps |
56 | 56 | services.AddScoped<ISurfaceTreatmentDs, SurfaceTreatmentDs>(); |
57 | 57 | services.AddScoped<IRoadDirectionDs, RoadDirectionDs>(); |
58 | 58 | services.AddScoped<IRoadSurfaceDs, RoadSurfaceDs>(); |
59 | + services.AddScoped<IRoadWidthDs, RoadWidthDs>(); | |
59 | 60 | // Add framework services. |
60 | 61 | services.AddApplicationInsightsTelemetry(Configuration); |
61 | 62 | ... | ... |
src/MapsDb/DataService/RoadSurfaceDs.cs
... | ... | @@ -21,7 +21,15 @@ namespace MapsDb.DataService |
21 | 21 | { |
22 | 22 | var data = _context.RoadSurface.Select(RoadSurface => new RoadSurfaceEditDsM |
23 | 23 | { |
24 | - | |
24 | + Id = RoadSurface.Id, | |
25 | + RoadId = RoadSurface.RoadId, | |
26 | + RegionId = RoadSurface.RegionId, | |
27 | + RoadDirectionId = RoadSurface.RoadDirectionId, | |
28 | + Begin = RoadSurface.Begin, | |
29 | + End = RoadSurface.End, | |
30 | + SurfaceTypeId = RoadSurface.SurfaceTypeId, | |
31 | + SurfaceTreatmentId = RoadSurface.SurfaceTreatmentId, | |
32 | + StateCommonId = RoadSurface.StateCommonId, | |
25 | 33 | }).Skip(pagination.from).Take(pagination.perPage); |
26 | 34 | switch (pagination.orderType()) |
27 | 35 | { |
... | ... | @@ -59,7 +67,15 @@ namespace MapsDb.DataService |
59 | 67 | } |
60 | 68 | public RoadSurface InsertModel(RoadSurfaceEditDsM data){ |
61 | 69 | RoadSurface Model = new RoadSurface{ |
62 | - | |
70 | + Id = data.Id, | |
71 | + RoadId = data.RoadId, | |
72 | + RegionId = data.RegionId, | |
73 | + RoadDirectionId = data.RoadDirectionId, | |
74 | + Begin = data.Begin, | |
75 | + End = data.End, | |
76 | + SurfaceTypeId = data.SurfaceTypeId, | |
77 | + SurfaceTreatmentId = data.SurfaceTreatmentId, | |
78 | + StateCommonId = data.StateCommonId, | |
63 | 79 | }; |
64 | 80 | return Model; |
65 | 81 | } | ... | ... |
1 | +using System.Collections.Generic; | |
2 | +using System.Linq; | |
3 | +using System.Reflection; | |
4 | +using System.Threading.Tasks; | |
5 | +using MapsDb.Interfaces; | |
6 | +using MapsDb.Models; | |
7 | +using MapsModels.DsModels; | |
8 | +using Microsoft.EntityFrameworkCore; | |
9 | +namespace MapsDb.DataService | |
10 | +{ | |
11 | + public class RoadWidthDs : IRoadWidthDs | |
12 | + { | |
13 | + private PostgresDbContext _context; | |
14 | + public RoadWidthDs(){ | |
15 | + _context = new PostgresDbContext(); | |
16 | + } | |
17 | + public Task<IList<RoadWidthEditDsM>> GetIndexListAsync(PaginationDsM pagination){ | |
18 | + return Task.Factory.StartNew(()=> { return GetAllRoadWidth(pagination); }); | |
19 | + } | |
20 | + private IList<RoadWidthEditDsM> GetAllRoadWidth(PaginationDsM pagination) | |
21 | + { | |
22 | + var data = _context.RoadWidth.Select(RoadWidth => new RoadWidthEditDsM | |
23 | + { | |
24 | + Id = RoadWidth.Id, | |
25 | + RoadId = RoadWidth.RoadId, | |
26 | + RegionId = RoadWidth.RegionId, | |
27 | + Begin = RoadWidth.Begin, | |
28 | + End = RoadWidth.End, | |
29 | + WidthRoadsideLeft = RoadWidth.WidthRoadsideLeft, | |
30 | + WidthReverseRoad = RoadWidth.WidthReverseRoad, | |
31 | + WidthStrip = RoadWidth.WidthStrip, | |
32 | + WidthRoadwayForward = RoadWidth.WidthRoadwayForward, | |
33 | + WidthRoadsideRight = RoadWidth.WidthRoadsideRight, | |
34 | + CountLaneLeft = RoadWidth.CountLaneLeft, | |
35 | + CountLaneRight = RoadWidth.CountLaneRight, | |
36 | + }).Skip(pagination.from).Take(pagination.perPage); | |
37 | + switch (pagination.orderType()) | |
38 | + { | |
39 | + case "ASC": | |
40 | + return data.OrderBy(i => i.GetType().GetProperty(pagination.sort).GetValue(i, null)).ToList(); | |
41 | + | |
42 | + case "DESC": | |
43 | + return data.OrderByDescending(i => i.GetType().GetProperty(pagination.sort).GetValue(i, null)).ToList(); | |
44 | + | |
45 | + default: | |
46 | + return data.OrderByDescending(i => i.Id).ToList(); | |
47 | + } | |
48 | + | |
49 | + } | |
50 | + | |
51 | + public Task<RoadWidth> CreateAsync(RoadWidthEditDsM data){ | |
52 | + return Task.Factory.StartNew(()=> { return Create(data); }); | |
53 | + } | |
54 | + private RoadWidth Create(RoadWidthEditDsM data) | |
55 | + { | |
56 | + | |
57 | + RoadWidth Model = InsertModel(data); | |
58 | + _context.RoadWidth.Add(Model); | |
59 | + _context.SaveChanges(); | |
60 | + return Model; | |
61 | + } | |
62 | + public Task<RoadWidth> UpdateAsync(RoadWidthEditDsM data, int id){ | |
63 | + return Task.Factory.StartNew(()=> { return Update(data, id); }); | |
64 | + } | |
65 | + private RoadWidth Update(RoadWidthEditDsM data, int id) | |
66 | + { | |
67 | + RoadWidth Model = InsertModel(data); | |
68 | + Model.Id = id; | |
69 | + _context.RoadWidth.Update(Model); | |
70 | + _context.SaveChanges(); | |
71 | + return Model; | |
72 | + } | |
73 | + public RoadWidth InsertModel(RoadWidthEditDsM data){ | |
74 | + RoadWidth Model = new RoadWidth{ | |
75 | + RoadId = data.RoadId, | |
76 | + RegionId = data.RegionId, | |
77 | + Begin = data.Begin, | |
78 | + End = data.End, | |
79 | + WidthRoadsideLeft = data.WidthRoadsideLeft, | |
80 | + WidthReverseRoad = data.WidthReverseRoad, | |
81 | + WidthStrip = data.WidthStrip, | |
82 | + WidthRoadwayForward = data.WidthRoadwayForward, | |
83 | + WidthRoadsideRight = data.WidthRoadsideRight, | |
84 | + CountLaneLeft = data.CountLaneLeft, | |
85 | + CountLaneRight = data.CountLaneRight, | |
86 | + }; | |
87 | + return Model; | |
88 | + } | |
89 | + public async Task<int> DeleteAsync(int Id) | |
90 | + { | |
91 | + var RoadWidth = await _context.RoadWidth.SingleOrDefaultAsync(x => x.Id == Id); | |
92 | + _context.RoadWidth.Remove(RoadWidth); | |
93 | + return await _context.SaveChangesAsync(); | |
94 | + } | |
95 | + } | |
96 | +} | |
0 | 97 | \ No newline at end of file | ... | ... |
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 IRoadWidthDs | |
8 | + { | |
9 | + Task<IList<RoadWidthEditDsM>> GetIndexListAsync(PaginationDsM pagination); | |
10 | + Task<RoadWidth> CreateAsync(RoadWidthEditDsM data); | |
11 | + Task<RoadWidth> UpdateAsync(RoadWidthEditDsM data, int id); | |
12 | + Task<int> DeleteAsync(int Id); | |
13 | + } | |
14 | +} | |
0 | 15 | \ No newline at end of file | ... | ... |
src/MapsDb/Models/RoadWidth.cs
src/MapsDb/PostgresDbContext.cs
... | ... | @@ -525,7 +525,7 @@ namespace MapsDb |
525 | 525 | { |
526 | 526 | entity.ToTable("road_width"); |
527 | 527 | |
528 | - entity.Property(e => e.RoadWidthId).HasColumnName("road_width_id"); | |
528 | + entity.Property(e => e.Id).HasColumnName("id"); | |
529 | 529 | |
530 | 530 | entity.Property(e => e.Begin).HasColumnName("begin"); |
531 | 531 | ... | ... |
1 | +namespace MapsModels.DsModels | |
2 | +{ | |
3 | + public class RoadWidthEditDsM | |
4 | + { | |
5 | + | |
6 | + public int Id { get; set; } | |
7 | + public int? RegionId { get; set; } | |
8 | + public int? RoadId { get; set; } | |
9 | + public double? Begin { get; set; } | |
10 | + public double? End { get; set; } | |
11 | + public double? WidthRoadsideLeft { get; set; } | |
12 | + public double? WidthReverseRoad { get; set; } | |
13 | + public double? WidthStrip { get; set; } | |
14 | + public double? WidthRoadwayForward { get; set; } | |
15 | + public double? WidthRoadsideRight { get; set; } | |
16 | + public double? CountLaneLeft { get; set; } | |
17 | + public double? CountLaneRight { get; set; } | |
18 | + | |
19 | + } | |
20 | +} | |
0 | 21 | \ No newline at end of file | ... | ... |