Commit 4f948d42eeac27025b23162ea33a02b11b6d1f45
1 parent
405bb8be
Mapper
Showing
4 changed files
with
14 additions
and
34 deletions
Show diff stats
src/Maps/Startup.cs
| ... | ... | @@ -12,6 +12,7 @@ using MapsDb; |
| 12 | 12 | using MapsDb.Interfaces; |
| 13 | 13 | using MapsDb.DataService; |
| 14 | 14 | using MapsModels; |
| 15 | + | |
| 15 | 16 | namespace Maps |
| 16 | 17 | { |
| 17 | 18 | public class Startup |
| ... | ... | @@ -59,6 +60,7 @@ namespace Maps |
| 59 | 60 | services.AddScoped<IRoadWidthDs, RoadWidthDs>(); |
| 60 | 61 | services.AddScoped<IFlowIntensityDs, FlowIntensityDs>(); |
| 61 | 62 | services.AddScoped<ICrossSectionDs, CrossSectionDs>(); |
| 63 | + services.AddScoped<IRoadTypeDs, RoadTypeDs>(); | |
| 62 | 64 | // Add framework services. |
| 63 | 65 | services.AddApplicationInsightsTelemetry(Configuration); |
| 64 | 66 | ... | ... |
src/Maps/project.json
src/MapsDb/DataService/BusStopDs.cs
| ... | ... | @@ -2,10 +2,12 @@ using System.Collections.Generic; |
| 2 | 2 | using System.Linq; |
| 3 | 3 | using System.Reflection; |
| 4 | 4 | using System.Threading.Tasks; |
| 5 | +using AutoMapper; | |
| 5 | 6 | using MapsDb.Interfaces; |
| 6 | 7 | using MapsDb.Models; |
| 7 | 8 | using MapsModels.DsModels; |
| 8 | 9 | using Microsoft.EntityFrameworkCore; |
| 10 | + | |
| 9 | 11 | namespace MapsDb.DataService |
| 10 | 12 | { |
| 11 | 13 | public class BusStopDs : IBusStopDs |
| ... | ... | @@ -13,29 +15,17 @@ namespace MapsDb.DataService |
| 13 | 15 | private PostgresDbContext _context; |
| 14 | 16 | public BusStopDs(){ |
| 15 | 17 | _context = new PostgresDbContext(); |
| 18 | + Mapper.Initialize(cnf => { | |
| 19 | + cnf.CreateMap<BusStop, BusStopEditDsM>(); | |
| 20 | + cnf.CreateMap<BusStopEditDsM, BusStop>(); | |
| 21 | + }); | |
| 16 | 22 | } |
| 17 | 23 | public Task<IList<BusStopEditDsM>> GetIndexListAsync(PaginationDsM pagination){ |
| 18 | 24 | return Task.Factory.StartNew(()=> { return GetAllBusStop(pagination); }); |
| 19 | 25 | } |
| 20 | 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 | 29 | switch (pagination.orderType()) |
| 40 | 30 | { |
| 41 | 31 | case "ASC": |
| ... | ... | @@ -73,21 +63,7 @@ namespace MapsDb.DataService |
| 73 | 63 | return Model; |
| 74 | 64 | } |
| 75 | 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 | 67 | return Model; |
| 92 | 68 | } |
| 93 | 69 | public async Task<int> DeleteAsync(int Id) | ... | ... |
src/MapsDb/project.json