Commit 43dfbc981f454bab8dc452e0a96bc91c21e49dbc
Merge branch 'master' of gitlab.artweb.com.ua:root/FirstFullmaps
Showing
14 changed files
with
281 additions
and
8 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 RoadServiceController : Controller | ||
16 | + { | ||
17 | + private readonly IRoadServiceDs _roadServiceDs; | ||
18 | + private readonly IRoadDs _roadDs; | ||
19 | + private readonly IRegionDs _regionDs; | ||
20 | + private readonly IOrganizationDs _organizationDs; | ||
21 | + private readonly IRoadDirectionDs _roadDirectionDs; | ||
22 | + | ||
23 | + public RoadServiceController(IRoadServiceDs RoadServiceDs, IRoadDs RoadDs, IRegionDs RegionDs, IOrganizationDs OrganizationDs, IRoadDirectionDs RoadDirectionDs) | ||
24 | + { | ||
25 | + _roadServiceDs = RoadServiceDs; | ||
26 | + _roadDs = RoadDs; | ||
27 | + _regionDs = RegionDs; | ||
28 | + _organizationDs = OrganizationDs; | ||
29 | + _roadDirectionDs = RoadDirectionDs; | ||
30 | + } | ||
31 | + | ||
32 | + // GET: RoadService | ||
33 | + [HttpGet] | ||
34 | + public async Task<IActionResult> Index([FromQuery] PaginationDsM data) | ||
35 | + { | ||
36 | + try | ||
37 | + { | ||
38 | + var roadServices = await _roadServiceDs.GetIndexListAsync(data); | ||
39 | + | ||
40 | + RoadServiceListVm vm = new RoadServiceListVm | ||
41 | + { | ||
42 | + RoadServiceEditDsM = roadServices.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 | + } | ||
59 | + | ||
60 | + [HttpGet] | ||
61 | + public async Task<IActionResult> Directory(){ | ||
62 | + var Road = await _roadDs.GetSelectListAsync(); | ||
63 | + var Region = await _regionDs.GetSelectListAsync(); | ||
64 | + var Organization = await _organizationDs.GetSelectListAsync(); | ||
65 | + var RoadDirection = await _roadDirectionDs.GetSelectListAsync(); | ||
66 | + | ||
67 | + CatalogListVm vm = new CatalogListVm | ||
68 | + { | ||
69 | + RoadSelectListDsM = Road.ToList(), | ||
70 | + RegionSelectListDsM = Region.ToList(), | ||
71 | + OrganizationSelectListDsM = Organization.ToList(), | ||
72 | + RoadDirectionSelectListDsM = RoadDirection.ToList(), | ||
73 | + }; | ||
74 | + return Json(vm); | ||
75 | + } | ||
76 | + | ||
77 | + | ||
78 | + [HttpPost] | ||
79 | + public async Task<IActionResult> Create([FromBody] RoadServiceEditDsM data) | ||
80 | + { | ||
81 | + var result = await _roadServiceDs.CreateAsync(data); | ||
82 | + return Json(result); | ||
83 | + } | ||
84 | + | ||
85 | + [HttpPost] | ||
86 | + public async Task<IActionResult> Update(int id, [FromBody] RoadServiceEditDsM data){ | ||
87 | + await _roadServiceDs.UpdateAsync(data,id); | ||
88 | + return Json(String.Empty); | ||
89 | + } | ||
90 | + | ||
91 | + | ||
92 | + [HttpDelete] | ||
93 | + public async Task<IActionResult> Delete(int id) | ||
94 | + { | ||
95 | + try | ||
96 | + { | ||
97 | + int roadService = await _roadServiceDs.DeleteAsync(id); | ||
98 | + return Json(roadService); | ||
99 | + } | ||
100 | + catch (ArgumentNullException ) | ||
101 | + { | ||
102 | + return NotFound(); | ||
103 | + } | ||
104 | + } | ||
105 | + } | ||
106 | +} |
src/Maps/Startup.cs
@@ -12,6 +12,9 @@ using MapsDb; | @@ -12,6 +12,9 @@ using MapsDb; | ||
12 | using MapsDb.Interfaces; | 12 | using MapsDb.Interfaces; |
13 | using MapsDb.DataService; | 13 | using MapsDb.DataService; |
14 | using MapsModels; | 14 | using MapsModels; |
15 | +using AutoMapper; | ||
16 | +using MapsDb.Models; | ||
17 | +using MapsModels.DsModels; | ||
15 | 18 | ||
16 | namespace Maps | 19 | namespace Maps |
17 | { | 20 | { |
@@ -45,6 +48,13 @@ namespace Maps | @@ -45,6 +48,13 @@ namespace Maps | ||
45 | })); | 48 | })); |
46 | services.AddScoped<PostgresDbContext>(); | 49 | services.AddScoped<PostgresDbContext>(); |
47 | 50 | ||
51 | + Mapper.Initialize(cnf => { | ||
52 | + cnf.CreateMap<BusStop, BusStopEditDsM>(); | ||
53 | + cnf.CreateMap<BusStopEditDsM, BusStop>(); | ||
54 | + cnf.CreateMap<RoadService, RoadServiceEditDsM>(); | ||
55 | + cnf.CreateMap<RoadServiceEditDsM, RoadService>(); | ||
56 | + }); | ||
57 | + | ||
48 | services.AddScoped<IBusStopDs, BusStopDs>(); | 58 | services.AddScoped<IBusStopDs, BusStopDs>(); |
49 | services.AddScoped<IRoadDs, RoadDs>(); | 59 | services.AddScoped<IRoadDs, RoadDs>(); |
50 | services.AddScoped<IRegionDs, RegionDs>(); | 60 | services.AddScoped<IRegionDs, RegionDs>(); |
@@ -61,6 +71,8 @@ namespace Maps | @@ -61,6 +71,8 @@ namespace Maps | ||
61 | services.AddScoped<IFlowIntensityDs, FlowIntensityDs>(); | 71 | services.AddScoped<IFlowIntensityDs, FlowIntensityDs>(); |
62 | services.AddScoped<ICrossSectionDs, CrossSectionDs>(); | 72 | services.AddScoped<ICrossSectionDs, CrossSectionDs>(); |
63 | services.AddScoped<IRoadTypeDs, RoadTypeDs>(); | 73 | services.AddScoped<IRoadTypeDs, RoadTypeDs>(); |
74 | + services.AddScoped<IOrganizationDs, OrganizationDs>(); | ||
75 | + services.AddScoped<IRoadServiceDs, RoadServiceDs>(); | ||
64 | // Add framework services. | 76 | // Add framework services. |
65 | services.AddApplicationInsightsTelemetry(Configuration); | 77 | services.AddApplicationInsightsTelemetry(Configuration); |
66 | 78 |
src/MapsDb/DataService/BusStopDs.cs
@@ -17,10 +17,6 @@ namespace MapsDb.DataService | @@ -17,10 +17,6 @@ namespace MapsDb.DataService | ||
17 | private PostgresDbContext _context; | 17 | private PostgresDbContext _context; |
18 | public BusStopDs(){ | 18 | public BusStopDs(){ |
19 | _context = new PostgresDbContext(); | 19 | _context = new PostgresDbContext(); |
20 | - Mapper.Initialize(cnf => { | ||
21 | - cnf.CreateMap<BusStop, BusStopEditDsM>(); | ||
22 | - cnf.CreateMap<BusStopEditDsM, BusStop>(); | ||
23 | - }); | ||
24 | } | 20 | } |
25 | public Task<IList<BusStopEditDsM>> GetIndexListAsync(PaginationDsM pagination){ | 21 | public Task<IList<BusStopEditDsM>> GetIndexListAsync(PaginationDsM pagination){ |
26 | return Task.Factory.StartNew(()=> { return GetAllBusStop(pagination); }); | 22 | return Task.Factory.StartNew(()=> { return GetAllBusStop(pagination); }); |
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 OrganizationDs : IOrganizationDs | ||
10 | + { | ||
11 | + private PostgresDbContext _context; | ||
12 | + public OrganizationDs(){ | ||
13 | + _context = new PostgresDbContext(); | ||
14 | + } | ||
15 | + public Task<IList<OrganizationSelectListDsM>> GetSelectListAsync(){ | ||
16 | + return Task.Factory.StartNew(GetSelectList); | ||
17 | + } | ||
18 | + private IList<OrganizationSelectListDsM> GetSelectList() | ||
19 | + { | ||
20 | + return _context.Organization.Select(x => new OrganizationSelectListDsM | ||
21 | + { | ||
22 | + Id = x.Id, | ||
23 | + Name = x.Name | ||
24 | + }).ToList(); | ||
25 | + } | ||
26 | + | ||
27 | + } | ||
28 | +} | ||
0 | \ No newline at end of file | 29 | \ No newline at end of file |
1 | +using System.Collections.Generic; | ||
2 | +using System.Linq; | ||
3 | +using System.Reflection; | ||
4 | +using System.Threading.Tasks; | ||
5 | +using AutoMapper; | ||
6 | +using MapsDb.Interfaces; | ||
7 | +using MapsDb.Models; | ||
8 | +using MapsModels.DsModels; | ||
9 | +using Microsoft.EntityFrameworkCore; | ||
10 | + | ||
11 | +namespace MapsDb.DataService | ||
12 | +{ | ||
13 | + public class RoadServiceDs : IRoadServiceDs | ||
14 | + { | ||
15 | + private PostgresDbContext _context; | ||
16 | + public RoadServiceDs(){ | ||
17 | + _context = new PostgresDbContext(); | ||
18 | + } | ||
19 | + public Task<IList<RoadServiceEditDsM>> GetIndexListAsync(PaginationDsM pagination){ | ||
20 | + return Task.Factory.StartNew(()=> { return GetAllRoadService(pagination); }); | ||
21 | + } | ||
22 | + private IList<RoadServiceEditDsM> GetAllRoadService(PaginationDsM pagination) | ||
23 | + { | ||
24 | + var data = _context.RoadService.Select(RoadService => Mapper.Map<RoadServiceEditDsM>(RoadService)).Skip(pagination.from).Take(pagination.perPage); | ||
25 | + switch (pagination.orderType()) | ||
26 | + { | ||
27 | + case "ASC": | ||
28 | + return data.OrderBy(i => i.GetType().GetProperty(pagination.sort).GetValue(i, null)).ToList(); | ||
29 | + | ||
30 | + case "DESC": | ||
31 | + return data.OrderByDescending(i => i.GetType().GetProperty(pagination.sort).GetValue(i, null)).ToList(); | ||
32 | + | ||
33 | + default: | ||
34 | + return data.OrderByDescending(i => i.Id).ToList(); | ||
35 | + } | ||
36 | + | ||
37 | + } | ||
38 | + | ||
39 | + public Task<RoadService> CreateAsync(RoadServiceEditDsM data){ | ||
40 | + return Task.Factory.StartNew(()=> { return Create(data); }); | ||
41 | + } | ||
42 | + private RoadService Create(RoadServiceEditDsM data) | ||
43 | + { | ||
44 | + | ||
45 | + RoadService Model = InsertModel(data); | ||
46 | + _context.RoadService.Add(Model); | ||
47 | + _context.SaveChanges(); | ||
48 | + return Model; | ||
49 | + } | ||
50 | + public Task<RoadService> UpdateAsync(RoadServiceEditDsM data, int id){ | ||
51 | + return Task.Factory.StartNew(()=> { return Update(data, id); }); | ||
52 | + } | ||
53 | + private RoadService Update(RoadServiceEditDsM data, int id) | ||
54 | + { | ||
55 | + RoadService Model = InsertModel(data); | ||
56 | + Model.Id = id; | ||
57 | + _context.RoadService.Update(Model); | ||
58 | + _context.SaveChanges(); | ||
59 | + return Model; | ||
60 | + } | ||
61 | + public RoadService InsertModel(RoadServiceEditDsM data){ | ||
62 | + RoadService Model = Mapper.Map<RoadService>(data); | ||
63 | + return Model; | ||
64 | + } | ||
65 | + public async Task<int> DeleteAsync(int Id) | ||
66 | + { | ||
67 | + var roadService = await _context.RoadService.SingleOrDefaultAsync(x => x.Id == Id); | ||
68 | + _context.RoadService.Remove(roadService); | ||
69 | + return await _context.SaveChangesAsync(); | ||
70 | + } | ||
71 | + } | ||
72 | +} | ||
0 | \ No newline at end of file | 73 | \ 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 IOrganizationDs | ||
8 | + { | ||
9 | + Task<IList<OrganizationSelectListDsM>> GetSelectListAsync(); | ||
10 | + } | ||
11 | +} | ||
0 | \ No newline at end of file | 12 | \ 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 IRoadServiceDs | ||
8 | + { | ||
9 | + Task<IList<RoadServiceEditDsM>> GetIndexListAsync(PaginationDsM pagination); | ||
10 | + Task<RoadService> CreateAsync(RoadServiceEditDsM roadService); | ||
11 | + Task<RoadService> UpdateAsync(RoadServiceEditDsM roadService, int id); | ||
12 | + Task<int> DeleteAsync(int Id); | ||
13 | + } | ||
14 | +} | ||
0 | \ No newline at end of file | 15 | \ No newline at end of file |
src/MapsDb/Models/Organization.cs
@@ -10,7 +10,7 @@ namespace MapsDb.Models | @@ -10,7 +10,7 @@ namespace MapsDb.Models | ||
10 | RoadService = new HashSet<RoadService>(); | 10 | RoadService = new HashSet<RoadService>(); |
11 | } | 11 | } |
12 | 12 | ||
13 | - public int OrganizationId { get; set; } | 13 | + public int Id { get; set; } |
14 | public string Name { get; set; } | 14 | public string Name { get; set; } |
15 | public int? DateAdd { get; set; } | 15 | public int? DateAdd { get; set; } |
16 | 16 |
src/MapsDb/Models/RoadService.cs
@@ -5,7 +5,7 @@ namespace MapsDb.Models | @@ -5,7 +5,7 @@ namespace MapsDb.Models | ||
5 | { | 5 | { |
6 | public partial class RoadService | 6 | public partial class RoadService |
7 | { | 7 | { |
8 | - public int RoadServiceId { get; set; } | 8 | + public int Id { get; set; } |
9 | public int? RoadId { get; set; } | 9 | public int? RoadId { get; set; } |
10 | public int? RegionId { get; set; } | 10 | public int? RegionId { get; set; } |
11 | public int? RoadDirectionId { get; set; } | 11 | public int? RoadDirectionId { get; set; } |
src/MapsDb/PostgresDbContext.cs
@@ -288,7 +288,7 @@ namespace MapsDb | @@ -288,7 +288,7 @@ namespace MapsDb | ||
288 | { | 288 | { |
289 | entity.ToTable("organization"); | 289 | entity.ToTable("organization"); |
290 | 290 | ||
291 | - entity.Property(e => e.OrganizationId).HasColumnName("organization_id"); | 291 | + entity.Property(e => e.Id).HasColumnName("id"); |
292 | 292 | ||
293 | entity.Property(e => e.DateAdd).HasColumnName("date_add"); | 293 | entity.Property(e => e.DateAdd).HasColumnName("date_add"); |
294 | 294 | ||
@@ -419,7 +419,7 @@ namespace MapsDb | @@ -419,7 +419,7 @@ namespace MapsDb | ||
419 | { | 419 | { |
420 | entity.ToTable("road_service"); | 420 | entity.ToTable("road_service"); |
421 | 421 | ||
422 | - entity.Property(e => e.RoadServiceId).HasColumnName("road_service_id"); | 422 | + entity.Property(e => e.Id).HasColumnName("id"); |
423 | 423 | ||
424 | entity.Property(e => e.Begin).HasColumnName("begin"); | 424 | entity.Property(e => e.Begin).HasColumnName("begin"); |
425 | 425 |
src/MapsModels/DsModels/OrganizationSelectListDsM.cs
0 → 100644
1 | +namespace MapsModels.DsModels | ||
2 | +{ | ||
3 | + public class RoadServiceEditDsM | ||
4 | + { | ||
5 | + public int Id { get; set; } | ||
6 | + public int? RoadId { get; set; } | ||
7 | + public int? RegionId { get; set; } | ||
8 | + public int? RoadDirectionId { get; set; } | ||
9 | + public int? OrganizationId { get; set; } | ||
10 | + public double? Begin { get; set; } | ||
11 | + public double? End { get; set; } | ||
12 | + public int? YearBegin { get; set; } | ||
13 | + | ||
14 | + } | ||
15 | +} | ||
0 | \ No newline at end of file | 16 | \ No newline at end of file |
src/MapsModels/ViewModels/CatalogListVm.cs
@@ -15,5 +15,6 @@ namespace MapsModels.ViewModels | @@ -15,5 +15,6 @@ namespace MapsModels.ViewModels | ||
15 | public List<RoadDirectionSelectListDsM> RoadDirectionSelectListDsM { get; set; } | 15 | public List<RoadDirectionSelectListDsM> RoadDirectionSelectListDsM { get; set; } |
16 | public List<SurfaceTreatmentSelectListDsM> SurfaceTreatmentSelectListDsM { get; set; } | 16 | public List<SurfaceTreatmentSelectListDsM> SurfaceTreatmentSelectListDsM { get; set; } |
17 | public List<RoadTypeSelectListDsM> RoadTypeSelectListDsM { get; set; } | 17 | public List<RoadTypeSelectListDsM> RoadTypeSelectListDsM { get; set; } |
18 | + public List<OrganizationSelectListDsM> OrganizationSelectListDsM { get; set; } | ||
18 | } | 19 | } |
19 | } | 20 | } |