diff --git a/src/Maps/Controllers/BusStopController.cs b/src/Maps/Controllers/BusStopController.cs index bb3e236..07e8147 100755 --- a/src/Maps/Controllers/BusStopController.cs +++ b/src/Maps/Controllers/BusStopController.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; using MapsDb; -using MapsDb.Interfeces; +using MapsDb.Interfaces; using MapsDb.DataService; using MapsModels.ViewModels; namespace Maps.Controllers @@ -12,53 +12,76 @@ namespace Maps.Controllers public class BusStopController : Controller { private readonly IBusStopDs _busStopDs; + private readonly IRoadDs _roadDs; + private readonly ISettlementDs _settlementDs; + private readonly IStateCommonDs _stateCommonDs; + private readonly IRegionDc _regionDc; + private readonly ISurfaceTypeDs _surfaceTypeDs; - public BusStopController(IBusStopDs BusStopDs) + public BusStopController(IBusStopDs BusStopDs, IRoadDs RoadDs, ISettlementDs SettlementDs, IRegionDc RegionDs, IStateCommonDs StateCommonDs, ISurfaceTypeDs SurfaceTypeDs) { - _busStopDs = BusStopDs; + _busStopDs = BusStopDs; + _roadDs = RoadDs; + _settlementDs = SettlementDs; + _stateCommonDs = StateCommonDs; + _regionDc = RegionDs; + _surfaceTypeDs = SurfaceTypeDs; } // GET: BusStop [HttpGet] public async Task Index() { - var busStops = await _busStopDs.GetAllBusStopAsync(); + var busStops = await _busStopDs.GetIndexListAsync(); ListBusStopVm vm = new ListBusStopVm { - busStopListDs = busStops.ToList() + busStopListDsM = busStops.ToList() }; return Json(vm); } - // // GET: BusStop/Details/5 - // public async Task Details(int id) - // { + // GET: BusStop/Details/5 + public async Task Details(int id) + { + try{ + var busStop = await _busStopDs.FindOneDetailsAsync(id); + if (busStop == null) + { + return NotFound(); + } + DetailsBusStopVm vm = new DetailsBusStopVm + { + busStopDetailsDsM = busStop + }; + return Json(vm); + } catch { + return Json(false); + } + + } - // var busStop = await _busStopDs.FindOneDetailsAsync(id); - // if (busStop == null) - // { - // return NotFound(); - // } - // DetailsBusStopVm vm = new DetailsBusStopVm - // { - // BusStopDetailsDs = busStop - // }; - // return Json(vm); - // } + // GET: BusStop/Create + public async Task Create() + { + var SurfaceType = await _surfaceTypeDs.GetSelectListAsync(); + var StateCommon = await _stateCommonDs.GetSelectListAsync(); + var Settlement = await _settlementDs.GetSelectListAsync(); + var Road = await _roadDs.GetSelectListAsync(); + var Region = await _regionDc.GetSelectListAsync(); - // // GET: BusStop/Create - // public IActionResult Create() - // { - // ViewData["RegionId"] = new SelectList(_context.Region, "RegionId", "RegionId"); - // ViewData["RoadId"] = new SelectList(_context.Road, "RoadId", "Name"); - // ViewData["SettlementId"] = new SelectList(_context.Settlement, "SettlementId", "Name"); - // ViewData["StateCommonId"] = new SelectList(_context.StateCommon, "StateCommonId", "Value"); - // ViewData["SurfaceTypeId"] = new SelectList(_context.SurfaceType, "SurfaceTypeId", "Name"); - // return View(); - // } + CreateBusStopVm vm = new CreateBusStopVm + { + SurfaceTypeSelectListDsM = SurfaceType.ToList(), + StateCommonSelectListDsM = StateCommon.ToList(), + SettlementSelectListDsM = Settlement.ToList(), + RoadSelectListDsM = Road.ToList(), + RegionSelectListDsM = Region.ToList() + }; + return Json(vm); + } // // POST: BusStop/Create // // To protect from overposting attacks, please enable the specific properties you want to bind to, for diff --git a/src/Maps/Startup.cs b/src/Maps/Startup.cs index fb7a5be..1505dc4 100644 --- a/src/Maps/Startup.cs +++ b/src/Maps/Startup.cs @@ -9,7 +9,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.EntityFrameworkCore; using MapsDb; -using MapsDb.Interfeces; +using MapsDb.Interfaces; using MapsDb.DataService; using MapsModels; namespace Maps @@ -40,6 +40,11 @@ namespace Maps services.AddScoped(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); // Add framework services. services.AddApplicationInsightsTelemetry(Configuration); diff --git a/src/MapsDb/DataService/BusStopDs.cs b/src/MapsDb/DataService/BusStopDs.cs index 396b215..26bd3c8 100644 --- a/src/MapsDb/DataService/BusStopDs.cs +++ b/src/MapsDb/DataService/BusStopDs.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using MapsDb.Interfeces; +using MapsDb.Interfaces; using MapsDb.Models; using MapsModels.DsModels; @@ -13,17 +13,12 @@ namespace MapsDb.DataService public BusStopDs(){ _context = new PostgresDbContext(); } - public void Dispose() - { - _context.Dispose(); - } - - public Task> GetAllBusStopAsync(){ + public Task> GetIndexListAsync(){ return Task.Factory.StartNew(GetAllBusStop); } - private IList GetAllBusStop() + private IList GetAllBusStop() { - return _context.BusStop.Select(x => new BusStopListDs + return _context.BusStop.Select(x => new BusStopListDsM { Road = x.Road.Name, Region = x.Region.Name, @@ -34,7 +29,7 @@ namespace MapsDb.DataService }).ToList(); } - public Task SaveBusStopAsync(BusStop busStop){ + public Task SaveAsync(BusStop busStop){ return Task.Factory.StartNew(()=> { Save(busStop); }); } private void Save(BusStop busStop) @@ -49,11 +44,11 @@ namespace MapsDb.DataService _context.BusStop.Add(busStop); } } - public Task FindOneDetailsAsync(int Id){ + public Task FindOneDetailsAsync(int Id){ return Task.Factory.StartNew(()=> { return FindOneDetails(Id); }); } - private BusStopDetailsDs FindOneDetails(int Id){ - return _context.BusStop.Where(x => x.BusStopId == Id).Select(x => new BusStopDetailsDs{ + private BusStopDetailsDsM FindOneDetails(int Id){ + return _context.BusStop.Where(x => x.BusStopId == Id).Select(x => new BusStopDetailsDsM{ BusStopId = x.BusStopId, Road = x.Road.Name, Region = x.Region.Name, diff --git a/src/MapsDb/DataService/RegionDc.cs b/src/MapsDb/DataService/RegionDc.cs new file mode 100644 index 0000000..843f603 --- /dev/null +++ b/src/MapsDb/DataService/RegionDc.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using MapsDb.Interfaces; +using MapsDb.Models; +using MapsModels.DsModels; +namespace MapsDb.DataService +{ + public class RegionDc : IRegionDc + { + private PostgresDbContext _context; + public RegionDc(){ + _context = new PostgresDbContext(); + } + public Task> GetSelectListAsync(){ + return Task.Factory.StartNew(GetSelectList); + } + private IList GetSelectList() + { + return _context.Region.Select(x => new RegionSelectListDsM + { + RegionId = x.RegionId, + Name = x.Name + }).ToList(); + } + + } +} \ No newline at end of file diff --git a/src/MapsDb/DataService/RoadDs.cs b/src/MapsDb/DataService/RoadDs.cs new file mode 100644 index 0000000..ec84b4a --- /dev/null +++ b/src/MapsDb/DataService/RoadDs.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using MapsDb.Interfaces; +using MapsDb.Models; +using MapsModels.DsModels; +namespace MapsDb.DataService +{ + public class RoadDc : IRoadDs + { + private PostgresDbContext _context; + public RoadDc(){ + _context = new PostgresDbContext(); + } + public Task> GetSelectListAsync(){ + return Task.Factory.StartNew(GetSelectList); + } + private IList GetSelectList() + { + return _context.Road.Select(x => new RoadSelectListDsM + { + RoadId = x.RoadId, + Name = x.Name + }).ToList(); + } + + } +} \ No newline at end of file diff --git a/src/MapsDb/DataService/SettlementDs.cs b/src/MapsDb/DataService/SettlementDs.cs new file mode 100644 index 0000000..09f01cd --- /dev/null +++ b/src/MapsDb/DataService/SettlementDs.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using MapsDb.Interfaces; +using MapsDb.Models; +using MapsModels.DsModels; +namespace MapsDb.DataService +{ + public class SettlementDc : ISettlementDs + { + private PostgresDbContext _context; + public SettlementDc(){ + _context = new PostgresDbContext(); + } + public Task> GetSelectListAsync(){ + return Task.Factory.StartNew(GetSelectList); + } + private IList GetSelectList() + { + return _context.Settlement.Select(x => new SettlementSelectListDsM + { + SettlementId = x.SettlementId, + Name = x.Name + }).ToList(); + } + + } +} \ No newline at end of file diff --git a/src/MapsDb/DataService/StateCommonDs.cs b/src/MapsDb/DataService/StateCommonDs.cs new file mode 100644 index 0000000..189b47f --- /dev/null +++ b/src/MapsDb/DataService/StateCommonDs.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using MapsDb.Interfaces; +using MapsDb.Models; +using MapsModels.DsModels; +namespace MapsDb.DataService +{ + public class StateCommonDc : IStateCommonDs + { + private PostgresDbContext _context; + public StateCommonDc(){ + _context = new PostgresDbContext(); + } + public Task> GetSelectListAsync(){ + return Task.Factory.StartNew(GetSelectList); + } + private IList GetSelectList() + { + return _context.StateCommon.Select(x => new StateCommonSelectListDsM + { + StateCommonId = x.StateCommonId, + Value = x.Value + }).ToList(); + } + + } +} \ No newline at end of file diff --git a/src/MapsDb/DataService/SurfaceTypeDs.cs b/src/MapsDb/DataService/SurfaceTypeDs.cs new file mode 100644 index 0000000..b8cfbd4 --- /dev/null +++ b/src/MapsDb/DataService/SurfaceTypeDs.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using MapsDb.Interfaces; +using MapsDb.Models; +using MapsModels.DsModels; +namespace MapsDb.DataService +{ + public class SurfaceTypeDc : ISurfaceTypeDs + { + private PostgresDbContext _context; + public SurfaceTypeDc(){ + _context = new PostgresDbContext(); + } + public Task> GetSelectListAsync(){ + return Task.Factory.StartNew(GetSelectList); + } + private IList GetSelectList() + { + return _context.SurfaceType.Select(x => new SurfaceTypeSelectListDsM + { + SurfaceTypeId = x.SurfaceTypeId, + Name = x.Name + }).ToList(); + } + + } +} \ No newline at end of file diff --git a/src/MapsDb/Interfaces/IBusStopDs.cs b/src/MapsDb/Interfaces/IBusStopDs.cs index 7fcaa9b..1353e52 100644 --- a/src/MapsDb/Interfaces/IBusStopDs.cs +++ b/src/MapsDb/Interfaces/IBusStopDs.cs @@ -2,12 +2,12 @@ using System.Collections.Generic; using System.Threading.Tasks; using MapsModels.DsModels; using MapsDb.Models; -namespace MapsDb.Interfeces +namespace MapsDb.Interfaces { public interface IBusStopDs { - Task> GetAllBusStopAsync(); - Task SaveBusStopAsync(BusStop busStop); - Task FindOneDetailsAsync(int Id); + Task> GetIndexListAsync(); + Task SaveAsync(BusStop busStop); + Task FindOneDetailsAsync(int Id); } } \ No newline at end of file diff --git a/src/MapsDb/Interfaces/IRegionDc.cs b/src/MapsDb/Interfaces/IRegionDc.cs new file mode 100644 index 0000000..1125c78 --- /dev/null +++ b/src/MapsDb/Interfaces/IRegionDc.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using MapsModels.DsModels; +using MapsDb.Models; +namespace MapsDb.Interfaces +{ + public interface IRegionDc + { + Task> GetSelectListAsync(); + } +} \ No newline at end of file diff --git a/src/MapsDb/Interfaces/IRoadDs.cs b/src/MapsDb/Interfaces/IRoadDs.cs new file mode 100644 index 0000000..9cbe352 --- /dev/null +++ b/src/MapsDb/Interfaces/IRoadDs.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using MapsModels.DsModels; +using MapsDb.Models; +namespace MapsDb.Interfaces +{ + public interface IRoadDs + { + Task> GetSelectListAsync(); + } +} \ No newline at end of file diff --git a/src/MapsDb/Interfaces/ISettlementDs.cs b/src/MapsDb/Interfaces/ISettlementDs.cs new file mode 100644 index 0000000..6897340 --- /dev/null +++ b/src/MapsDb/Interfaces/ISettlementDs.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using MapsModels.DsModels; +using MapsDb.Models; +namespace MapsDb.Interfaces +{ + public interface ISettlementDs + { + Task> GetSelectListAsync(); + } +} \ No newline at end of file diff --git a/src/MapsDb/Interfaces/IStateCommonDs.cs b/src/MapsDb/Interfaces/IStateCommonDs.cs new file mode 100644 index 0000000..da6b427 --- /dev/null +++ b/src/MapsDb/Interfaces/IStateCommonDs.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using MapsModels.DsModels; +using MapsDb.Models; +namespace MapsDb.Interfaces +{ + public interface IStateCommonDs + { + Task> GetSelectListAsync(); + } +} \ No newline at end of file diff --git a/src/MapsDb/Interfaces/ISurfaceTypeDs.cs b/src/MapsDb/Interfaces/ISurfaceTypeDs.cs new file mode 100644 index 0000000..4ad74ef --- /dev/null +++ b/src/MapsDb/Interfaces/ISurfaceTypeDs.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using MapsModels.DsModels; +using MapsDb.Models; +namespace MapsDb.Interfaces +{ + public interface ISurfaceTypeDs + { + Task> GetSelectListAsync(); + } +} \ No newline at end of file diff --git a/src/MapsModels/DsModels/BusStopDetailsDs.cs b/src/MapsModels/DsModels/BusStopDetailsDs.cs deleted file mode 100644 index 3a294a9..0000000 --- a/src/MapsModels/DsModels/BusStopDetailsDs.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace MapsModels.DsModels -{ - public class BusStopDetailsDs - { - public int BusStopId { get; set; } - public string Road { get; set; } - public string Region { get; set; } - public string Settlement { get; set; } - public double? LocationLeft { get; set; } - public double? LocationRight { get; set; } - public string SurfaceType { get; set; } - public int? AreaStopAvailability { get; set; } - public int? AreaLandAvailability { get; set; } - public int? PocketAvailability { get; set; } - public int? ToiletAvailability { get; set; } - public int? YearBuild { get; set; } - public int? YearRepair { get; set; } - public string StateCommon { get; set; } - - } -} \ No newline at end of file diff --git a/src/MapsModels/DsModels/BusStopDetailsDsM.cs b/src/MapsModels/DsModels/BusStopDetailsDsM.cs new file mode 100644 index 0000000..655310d --- /dev/null +++ b/src/MapsModels/DsModels/BusStopDetailsDsM.cs @@ -0,0 +1,21 @@ +namespace MapsModels.DsModels +{ + public class BusStopDetailsDsM + { + public int BusStopId { get; set; } + public string Road { get; set; } + public string Region { get; set; } + public string Settlement { get; set; } + public double? LocationLeft { get; set; } + public double? LocationRight { get; set; } + public string SurfaceType { get; set; } + public int? AreaStopAvailability { get; set; } + public int? AreaLandAvailability { get; set; } + public int? PocketAvailability { get; set; } + public int? ToiletAvailability { get; set; } + public int? YearBuild { get; set; } + public int? YearRepair { get; set; } + public string StateCommon { get; set; } + + } +} \ No newline at end of file diff --git a/src/MapsModels/DsModels/BusStopListDs.cs b/src/MapsModels/DsModels/BusStopListDs.cs deleted file mode 100644 index 6b13b69..0000000 --- a/src/MapsModels/DsModels/BusStopListDs.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace MapsModels.DsModels -{ - public class BusStopListDs - { - public string Road { get; set; } - public string Region { get; set; } - public string Settlement { get; set; } - public double? LocationLeft { get; set; } - public double? LocationRight { get; set; } - public string StateCommon { get; set; } - } -} \ No newline at end of file diff --git a/src/MapsModels/DsModels/BusStopListDsM.cs b/src/MapsModels/DsModels/BusStopListDsM.cs new file mode 100644 index 0000000..1b4c1e8 --- /dev/null +++ b/src/MapsModels/DsModels/BusStopListDsM.cs @@ -0,0 +1,12 @@ +namespace MapsModels.DsModels +{ + public class BusStopListDsM + { + public string Road { get; set; } + public string Region { get; set; } + public string Settlement { get; set; } + public double? LocationLeft { get; set; } + public double? LocationRight { get; set; } + public string StateCommon { get; set; } + } +} \ No newline at end of file diff --git a/src/MapsModels/DsModels/RegionSelectListDsM.cs b/src/MapsModels/DsModels/RegionSelectListDsM.cs new file mode 100644 index 0000000..a13ea75 --- /dev/null +++ b/src/MapsModels/DsModels/RegionSelectListDsM.cs @@ -0,0 +1,8 @@ +namespace MapsModels.DsModels +{ + public class RegionSelectListDsM + { + public int RegionId { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/MapsModels/DsModels/RoadSelectListDsM.cs b/src/MapsModels/DsModels/RoadSelectListDsM.cs new file mode 100644 index 0000000..571b6f8 --- /dev/null +++ b/src/MapsModels/DsModels/RoadSelectListDsM.cs @@ -0,0 +1,8 @@ +namespace MapsModels.DsModels +{ + public class RoadSelectListDsM + { + public int RoadId { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/MapsModels/DsModels/SettlementSelectListDsM.cs b/src/MapsModels/DsModels/SettlementSelectListDsM.cs new file mode 100644 index 0000000..6d82577 --- /dev/null +++ b/src/MapsModels/DsModels/SettlementSelectListDsM.cs @@ -0,0 +1,8 @@ +namespace MapsModels.DsModels +{ + public class SettlementSelectListDsM + { + public int SettlementId { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/MapsModels/DsModels/StateCommonSelectListDsM.cs b/src/MapsModels/DsModels/StateCommonSelectListDsM.cs new file mode 100644 index 0000000..c3d318b --- /dev/null +++ b/src/MapsModels/DsModels/StateCommonSelectListDsM.cs @@ -0,0 +1,8 @@ +namespace MapsModels.DsModels +{ + public class StateCommonSelectListDsM + { + public int StateCommonId { get; set; } + public string Value { get; set; } + } +} \ No newline at end of file diff --git a/src/MapsModels/DsModels/SurfaceTypeSelectListDsM.cs b/src/MapsModels/DsModels/SurfaceTypeSelectListDsM.cs new file mode 100644 index 0000000..4945cb1 --- /dev/null +++ b/src/MapsModels/DsModels/SurfaceTypeSelectListDsM.cs @@ -0,0 +1,8 @@ +namespace MapsModels.DsModels +{ + public class SurfaceTypeSelectListDsM + { + public int SurfaceTypeId { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/MapsModels/ViewModels/CreateBusStopVm.cs b/src/MapsModels/ViewModels/CreateBusStopVm.cs new file mode 100644 index 0000000..861fdd8 --- /dev/null +++ b/src/MapsModels/ViewModels/CreateBusStopVm.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using MapsModels.DsModels; + +namespace MapsModels.ViewModels +{ + public class CreateBusStopVm + { + public List SurfaceTypeSelectListDsM { get; set; } + public List StateCommonSelectListDsM { get; set; } + public List SettlementSelectListDsM { get; set; } + public List RoadSelectListDsM { get; set; } + public List RegionSelectListDsM { get; set; } + } +} diff --git a/src/MapsModels/ViewModels/DetailsBusStopVm.cs b/src/MapsModels/ViewModels/DetailsBusStopVm.cs index 5663244..edf4709 100644 --- a/src/MapsModels/ViewModels/DetailsBusStopVm.cs +++ b/src/MapsModels/ViewModels/DetailsBusStopVm.cs @@ -5,6 +5,6 @@ namespace MapsModels.ViewModels { public class DetailsBusStopVm { - public BusStopDetailsDs busStopDetailsDs { get; set; } + public BusStopDetailsDsM busStopDetailsDsM { get; set; } } } diff --git a/src/MapsModels/ViewModels/ListBusStopVm.cs b/src/MapsModels/ViewModels/ListBusStopVm.cs index 61cbdb0..6b29be1 100644 --- a/src/MapsModels/ViewModels/ListBusStopVm.cs +++ b/src/MapsModels/ViewModels/ListBusStopVm.cs @@ -5,6 +5,6 @@ namespace MapsModels.ViewModels { public class ListBusStopVm { - public List busStopListDs { get; set; } + public List busStopListDsM { get; set; } } } -- libgit2 0.21.4