Commit 4f948d42eeac27025b23162ea33a02b11b6d1f45

Authored by Yarik
1 parent 405bb8be

Mapper

src/Maps/Startup.cs
@@ -12,6 +12,7 @@ using MapsDb; @@ -12,6 +12,7 @@ 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 +
15 namespace Maps 16 namespace Maps
16 { 17 {
17 public class Startup 18 public class Startup
@@ -59,6 +60,7 @@ namespace Maps @@ -59,6 +60,7 @@ namespace Maps
59 services.AddScoped<IRoadWidthDs, RoadWidthDs>(); 60 services.AddScoped<IRoadWidthDs, RoadWidthDs>();
60 services.AddScoped<IFlowIntensityDs, FlowIntensityDs>(); 61 services.AddScoped<IFlowIntensityDs, FlowIntensityDs>();
61 services.AddScoped<ICrossSectionDs, CrossSectionDs>(); 62 services.AddScoped<ICrossSectionDs, CrossSectionDs>();
  63 + services.AddScoped<IRoadTypeDs, RoadTypeDs>();
62 // Add framework services. 64 // Add framework services.
63 services.AddApplicationInsightsTelemetry(Configuration); 65 services.AddApplicationInsightsTelemetry(Configuration);
64 66
src/Maps/project.json
@@ -36,7 +36,8 @@ @@ -36,7 +36,8 @@
36 "Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.2", 36 "Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.2",
37 "Npgsql.EntityFrameworkCore.PostgreSQL.Design": "1.0.2", 37 "Npgsql.EntityFrameworkCore.PostgreSQL.Design": "1.0.2",
38 "MapsDb": "1.0.0-*", 38 "MapsDb": "1.0.0-*",
39 - "MapsModels": "1.0.0-*" 39 + "MapsModels": "1.0.0-*",
  40 + "AutoMapper": "5.2.0"
40 }, 41 },
41 42
42 "tools": { 43 "tools": {
src/MapsDb/DataService/BusStopDs.cs
@@ -2,10 +2,12 @@ using System.Collections.Generic; @@ -2,10 +2,12 @@ using System.Collections.Generic;
2 using System.Linq; 2 using System.Linq;
3 using System.Reflection; 3 using System.Reflection;
4 using System.Threading.Tasks; 4 using System.Threading.Tasks;
  5 +using AutoMapper;
5 using MapsDb.Interfaces; 6 using MapsDb.Interfaces;
6 using MapsDb.Models; 7 using MapsDb.Models;
7 using MapsModels.DsModels; 8 using MapsModels.DsModels;
8 using Microsoft.EntityFrameworkCore; 9 using Microsoft.EntityFrameworkCore;
  10 +
9 namespace MapsDb.DataService 11 namespace MapsDb.DataService
10 { 12 {
11 public class BusStopDs : IBusStopDs 13 public class BusStopDs : IBusStopDs
@@ -13,29 +15,17 @@ namespace MapsDb.DataService @@ -13,29 +15,17 @@ namespace MapsDb.DataService
13 private PostgresDbContext _context; 15 private PostgresDbContext _context;
14 public BusStopDs(){ 16 public BusStopDs(){
15 _context = new PostgresDbContext(); 17 _context = new PostgresDbContext();
  18 + Mapper.Initialize(cnf => {
  19 + cnf.CreateMap<BusStop, BusStopEditDsM>();
  20 + cnf.CreateMap<BusStopEditDsM, BusStop>();
  21 + });
16 } 22 }
17 public Task<IList<BusStopEditDsM>> GetIndexListAsync(PaginationDsM pagination){ 23 public Task<IList<BusStopEditDsM>> GetIndexListAsync(PaginationDsM pagination){
18 return Task.Factory.StartNew(()=> { return GetAllBusStop(pagination); }); 24 return Task.Factory.StartNew(()=> { return GetAllBusStop(pagination); });
19 } 25 }
20 private IList<BusStopEditDsM> GetAllBusStop(PaginationDsM pagination) 26 private IList<BusStopEditDsM> GetAllBusStop(PaginationDsM pagination)
21 { 27 {
22 - var data = _context.BusStop.Select(BusStop => new BusStopEditDsM  
23 - {  
24 - Id = BusStop.Id,  
25 - RoadId = BusStop.RoadId,  
26 - RegionId = BusStop.RegionId,  
27 - SettlementId = BusStop.SettlementId,  
28 - LocationLeft = BusStop.LocationLeft,  
29 - LocationRight = BusStop.LocationRight,  
30 - SurfaceTypeId = BusStop.SurfaceTypeId,  
31 - AreaStopAvailability = BusStop.AreaStopAvailability,  
32 - AreaLandAvailability = BusStop.AreaLandAvailability,  
33 - PocketAvailability = BusStop.PocketAvailability,  
34 - ToiletAvailability = BusStop.ToiletAvailability,  
35 - YearBuild = BusStop.YearBuild,  
36 - YearRepair = BusStop.YearRepair,  
37 - StateCommonId = BusStop.StateCommonId  
38 - }).Skip(pagination.from).Take(pagination.perPage); 28 + var data = _context.BusStop.Select(BusStop => Mapper.Map<BusStopEditDsM>(BusStop)).Skip(pagination.from).Take(pagination.perPage);
39 switch (pagination.orderType()) 29 switch (pagination.orderType())
40 { 30 {
41 case "ASC": 31 case "ASC":
@@ -73,21 +63,7 @@ namespace MapsDb.DataService @@ -73,21 +63,7 @@ namespace MapsDb.DataService
73 return Model; 63 return Model;
74 } 64 }
75 public BusStop InsertModel(BusStopEditDsM data){ 65 public BusStop InsertModel(BusStopEditDsM data){
76 - BusStop Model = new BusStop{  
77 - RoadId = data.RoadId,  
78 - RegionId = data.RegionId,  
79 - SettlementId = data.SettlementId,  
80 - LocationLeft = data.LocationLeft,  
81 - LocationRight = data.LocationRight,  
82 - SurfaceTypeId = data.SurfaceTypeId,  
83 - AreaStopAvailability = data.AreaStopAvailability,  
84 - AreaLandAvailability = data.AreaLandAvailability,  
85 - PocketAvailability = data.PocketAvailability,  
86 - ToiletAvailability = data.ToiletAvailability,  
87 - YearBuild = data.YearBuild,  
88 - YearRepair = data.YearRepair,  
89 - StateCommonId = data.StateCommonId  
90 - }; 66 + BusStop Model = Mapper.Map<BusStop>(data);
91 return Model; 67 return Model;
92 } 68 }
93 public async Task<int> DeleteAsync(int Id) 69 public async Task<int> DeleteAsync(int Id)
src/MapsDb/project.json
@@ -13,7 +13,8 @@ @@ -13,7 +13,8 @@
13 "version": "1.0.0" 13 "version": "1.0.0"
14 }, 14 },
15 "Npgsql.EntityFrameworkCore.PostgreSQL": "1.0", 15 "Npgsql.EntityFrameworkCore.PostgreSQL": "1.0",
16 - "MapsModels": "1.0.0-*" 16 + "MapsModels": "1.0.0-*",
  17 + "AutoMapper": "5.2.0",
17 }, 18 },
18 "frameworks": { 19 "frameworks": {
19 "netcoreapp1.0": { 20 "netcoreapp1.0": {