Commit b9b3b8dd3f389325d43ce5282bc6f7481b980a67

Authored by Administrator
1 parent 44582203

add deteils and create in bus stop

src/Maps/Controllers/BusStopController.cs
@@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc; @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc;
4 using Microsoft.AspNetCore.Mvc.Rendering; 4 using Microsoft.AspNetCore.Mvc.Rendering;
5 using Microsoft.EntityFrameworkCore; 5 using Microsoft.EntityFrameworkCore;
6 using MapsDb; 6 using MapsDb;
7 -using MapsDb.Interfeces; 7 +using MapsDb.Interfaces;
8 using MapsDb.DataService; 8 using MapsDb.DataService;
9 using MapsModels.ViewModels; 9 using MapsModels.ViewModels;
10 namespace Maps.Controllers 10 namespace Maps.Controllers
@@ -12,53 +12,76 @@ namespace Maps.Controllers @@ -12,53 +12,76 @@ namespace Maps.Controllers
12 public class BusStopController : Controller 12 public class BusStopController : Controller
13 { 13 {
14 private readonly IBusStopDs _busStopDs; 14 private readonly IBusStopDs _busStopDs;
  15 + private readonly IRoadDs _roadDs;
  16 + private readonly ISettlementDs _settlementDs;
  17 + private readonly IStateCommonDs _stateCommonDs;
  18 + private readonly IRegionDc _regionDc;
  19 + private readonly ISurfaceTypeDs _surfaceTypeDs;
15 20
16 - public BusStopController(IBusStopDs BusStopDs) 21 + public BusStopController(IBusStopDs BusStopDs, IRoadDs RoadDs, ISettlementDs SettlementDs, IRegionDc RegionDs, IStateCommonDs StateCommonDs, ISurfaceTypeDs SurfaceTypeDs)
17 { 22 {
18 - _busStopDs = BusStopDs; 23 + _busStopDs = BusStopDs;
  24 + _roadDs = RoadDs;
  25 + _settlementDs = SettlementDs;
  26 + _stateCommonDs = StateCommonDs;
  27 + _regionDc = RegionDs;
  28 + _surfaceTypeDs = SurfaceTypeDs;
19 } 29 }
20 30
21 // GET: BusStop 31 // GET: BusStop
22 [HttpGet] 32 [HttpGet]
23 public async Task<IActionResult> Index() 33 public async Task<IActionResult> Index()
24 { 34 {
25 - var busStops = await _busStopDs.GetAllBusStopAsync(); 35 + var busStops = await _busStopDs.GetIndexListAsync();
26 36
27 ListBusStopVm vm = new ListBusStopVm 37 ListBusStopVm vm = new ListBusStopVm
28 { 38 {
29 - busStopListDs = busStops.ToList() 39 + busStopListDsM = busStops.ToList()
30 }; 40 };
31 41
32 return Json(vm); 42 return Json(vm);
33 } 43 }
34 44
35 45
36 - // // GET: BusStop/Details/5  
37 - // public async Task<IActionResult> Details(int id)  
38 - // { 46 + // GET: BusStop/Details/5
  47 + public async Task<IActionResult> Details(int id)
  48 + {
  49 + try{
  50 + var busStop = await _busStopDs.FindOneDetailsAsync(id);
  51 + if (busStop == null)
  52 + {
  53 + return NotFound();
  54 + }
  55 + DetailsBusStopVm vm = new DetailsBusStopVm
  56 + {
  57 + busStopDetailsDsM = busStop
  58 + };
  59 + return Json(vm);
  60 + } catch {
  61 + return Json(false);
  62 + }
  63 +
  64 + }
39 65
40 - // var busStop = await _busStopDs.FindOneDetailsAsync(id);  
41 - // if (busStop == null)  
42 - // {  
43 - // return NotFound();  
44 - // }  
45 - // DetailsBusStopVm vm = new DetailsBusStopVm  
46 - // {  
47 - // BusStopDetailsDs = busStop  
48 - // };  
49 - // return Json(vm);  
50 - // } 66 + // GET: BusStop/Create
  67 + public async Task<IActionResult> Create()
  68 + {
  69 + var SurfaceType = await _surfaceTypeDs.GetSelectListAsync();
  70 + var StateCommon = await _stateCommonDs.GetSelectListAsync();
  71 + var Settlement = await _settlementDs.GetSelectListAsync();
  72 + var Road = await _roadDs.GetSelectListAsync();
  73 + var Region = await _regionDc.GetSelectListAsync();
51 74
52 - // // GET: BusStop/Create  
53 - // public IActionResult Create()  
54 - // {  
55 - // ViewData["RegionId"] = new SelectList(_context.Region, "RegionId", "RegionId");  
56 - // ViewData["RoadId"] = new SelectList(_context.Road, "RoadId", "Name");  
57 - // ViewData["SettlementId"] = new SelectList(_context.Settlement, "SettlementId", "Name");  
58 - // ViewData["StateCommonId"] = new SelectList(_context.StateCommon, "StateCommonId", "Value");  
59 - // ViewData["SurfaceTypeId"] = new SelectList(_context.SurfaceType, "SurfaceTypeId", "Name");  
60 - // return View();  
61 - // } 75 + CreateBusStopVm vm = new CreateBusStopVm
  76 + {
  77 + SurfaceTypeSelectListDsM = SurfaceType.ToList(),
  78 + StateCommonSelectListDsM = StateCommon.ToList(),
  79 + SettlementSelectListDsM = Settlement.ToList(),
  80 + RoadSelectListDsM = Road.ToList(),
  81 + RegionSelectListDsM = Region.ToList()
  82 + };
  83 + return Json(vm);
  84 + }
62 85
63 // // POST: BusStop/Create 86 // // POST: BusStop/Create
64 // // To protect from overposting attacks, please enable the specific properties you want to bind to, for 87 // // To protect from overposting attacks, please enable the specific properties you want to bind to, for
src/Maps/Startup.cs
@@ -9,7 +9,7 @@ using Microsoft.Extensions.DependencyInjection; @@ -9,7 +9,7 @@ using Microsoft.Extensions.DependencyInjection;
9 using Microsoft.Extensions.Logging; 9 using Microsoft.Extensions.Logging;
10 using Microsoft.EntityFrameworkCore; 10 using Microsoft.EntityFrameworkCore;
11 using MapsDb; 11 using MapsDb;
12 -using MapsDb.Interfeces; 12 +using MapsDb.Interfaces;
13 using MapsDb.DataService; 13 using MapsDb.DataService;
14 using MapsModels; 14 using MapsModels;
15 namespace Maps 15 namespace Maps
@@ -40,6 +40,11 @@ namespace Maps @@ -40,6 +40,11 @@ namespace Maps
40 services.AddScoped<PostgresDbContext>(); 40 services.AddScoped<PostgresDbContext>();
41 41
42 services.AddScoped<IBusStopDs, BusStopDs>(); 42 services.AddScoped<IBusStopDs, BusStopDs>();
  43 + services.AddScoped<IRoadDs, RoadDc>();
  44 + services.AddScoped<IRegionDc, RegionDc>();
  45 + services.AddScoped<IStateCommonDs, StateCommonDc>();
  46 + services.AddScoped<ISurfaceTypeDs, SurfaceTypeDc>();
  47 + services.AddScoped<ISettlementDs, SettlementDc>();
43 // Add framework services. 48 // Add framework services.
44 services.AddApplicationInsightsTelemetry(Configuration); 49 services.AddApplicationInsightsTelemetry(Configuration);
45 50
src/MapsDb/DataService/BusStopDs.cs
1 using System.Collections.Generic; 1 using System.Collections.Generic;
2 using System.Linq; 2 using System.Linq;
3 using System.Threading.Tasks; 3 using System.Threading.Tasks;
4 -using MapsDb.Interfeces; 4 +using MapsDb.Interfaces;
5 using MapsDb.Models; 5 using MapsDb.Models;
6 using MapsModels.DsModels; 6 using MapsModels.DsModels;
7 7
@@ -13,17 +13,12 @@ namespace MapsDb.DataService @@ -13,17 +13,12 @@ namespace MapsDb.DataService
13 public BusStopDs(){ 13 public BusStopDs(){
14 _context = new PostgresDbContext(); 14 _context = new PostgresDbContext();
15 } 15 }
16 - public void Dispose()  
17 - {  
18 - _context.Dispose();  
19 - }  
20 -  
21 - public Task<IList<BusStopListDs>> GetAllBusStopAsync(){ 16 + public Task<IList<BusStopListDsM>> GetIndexListAsync(){
22 return Task.Factory.StartNew(GetAllBusStop); 17 return Task.Factory.StartNew(GetAllBusStop);
23 } 18 }
24 - private IList<BusStopListDs> GetAllBusStop() 19 + private IList<BusStopListDsM> GetAllBusStop()
25 { 20 {
26 - return _context.BusStop.Select(x => new BusStopListDs 21 + return _context.BusStop.Select(x => new BusStopListDsM
27 { 22 {
28 Road = x.Road.Name, 23 Road = x.Road.Name,
29 Region = x.Region.Name, 24 Region = x.Region.Name,
@@ -34,7 +29,7 @@ namespace MapsDb.DataService @@ -34,7 +29,7 @@ namespace MapsDb.DataService
34 }).ToList(); 29 }).ToList();
35 } 30 }
36 31
37 - public Task SaveBusStopAsync(BusStop busStop){ 32 + public Task SaveAsync(BusStop busStop){
38 return Task.Factory.StartNew(()=> { Save(busStop); }); 33 return Task.Factory.StartNew(()=> { Save(busStop); });
39 } 34 }
40 private void Save(BusStop busStop) 35 private void Save(BusStop busStop)
@@ -49,11 +44,11 @@ namespace MapsDb.DataService @@ -49,11 +44,11 @@ namespace MapsDb.DataService
49 _context.BusStop.Add(busStop); 44 _context.BusStop.Add(busStop);
50 } 45 }
51 } 46 }
52 - public Task<BusStopDetailsDs> FindOneDetailsAsync(int Id){ 47 + public Task<BusStopDetailsDsM> FindOneDetailsAsync(int Id){
53 return Task.Factory.StartNew(()=> { return FindOneDetails(Id); }); 48 return Task.Factory.StartNew(()=> { return FindOneDetails(Id); });
54 } 49 }
55 - private BusStopDetailsDs FindOneDetails(int Id){  
56 - return _context.BusStop.Where(x => x.BusStopId == Id).Select(x => new BusStopDetailsDs{ 50 + private BusStopDetailsDsM FindOneDetails(int Id){
  51 + return _context.BusStop.Where(x => x.BusStopId == Id).Select(x => new BusStopDetailsDsM{
57 BusStopId = x.BusStopId, 52 BusStopId = x.BusStopId,
58 Road = x.Road.Name, 53 Road = x.Road.Name,
59 Region = x.Region.Name, 54 Region = x.Region.Name,
src/MapsDb/DataService/RegionDc.cs 0 → 100644
  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 RegionDc : IRegionDc
  10 + {
  11 + private PostgresDbContext _context;
  12 + public RegionDc(){
  13 + _context = new PostgresDbContext();
  14 + }
  15 + public Task<IList<RegionSelectListDsM>> GetSelectListAsync(){
  16 + return Task.Factory.StartNew(GetSelectList);
  17 + }
  18 + private IList<RegionSelectListDsM> GetSelectList()
  19 + {
  20 + return _context.Region.Select(x => new RegionSelectListDsM
  21 + {
  22 + RegionId = x.RegionId,
  23 + Name = x.Name
  24 + }).ToList();
  25 + }
  26 +
  27 + }
  28 +}
0 \ No newline at end of file 29 \ No newline at end of file
src/MapsDb/DataService/RoadDs.cs 0 → 100644
  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 RoadDc : IRoadDs
  10 + {
  11 + private PostgresDbContext _context;
  12 + public RoadDc(){
  13 + _context = new PostgresDbContext();
  14 + }
  15 + public Task<IList<RoadSelectListDsM>> GetSelectListAsync(){
  16 + return Task.Factory.StartNew(GetSelectList);
  17 + }
  18 + private IList<RoadSelectListDsM> GetSelectList()
  19 + {
  20 + return _context.Road.Select(x => new RoadSelectListDsM
  21 + {
  22 + RoadId = x.RoadId,
  23 + Name = x.Name
  24 + }).ToList();
  25 + }
  26 +
  27 + }
  28 +}
0 \ No newline at end of file 29 \ No newline at end of file
src/MapsDb/DataService/SettlementDs.cs 0 → 100644
  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 SettlementDc : ISettlementDs
  10 + {
  11 + private PostgresDbContext _context;
  12 + public SettlementDc(){
  13 + _context = new PostgresDbContext();
  14 + }
  15 + public Task<IList<SettlementSelectListDsM>> GetSelectListAsync(){
  16 + return Task.Factory.StartNew(GetSelectList);
  17 + }
  18 + private IList<SettlementSelectListDsM> GetSelectList()
  19 + {
  20 + return _context.Settlement.Select(x => new SettlementSelectListDsM
  21 + {
  22 + SettlementId = x.SettlementId,
  23 + Name = x.Name
  24 + }).ToList();
  25 + }
  26 +
  27 + }
  28 +}
0 \ No newline at end of file 29 \ No newline at end of file
src/MapsDb/DataService/StateCommonDs.cs 0 → 100644
  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 StateCommonDc : IStateCommonDs
  10 + {
  11 + private PostgresDbContext _context;
  12 + public StateCommonDc(){
  13 + _context = new PostgresDbContext();
  14 + }
  15 + public Task<IList<StateCommonSelectListDsM>> GetSelectListAsync(){
  16 + return Task.Factory.StartNew(GetSelectList);
  17 + }
  18 + private IList<StateCommonSelectListDsM> GetSelectList()
  19 + {
  20 + return _context.StateCommon.Select(x => new StateCommonSelectListDsM
  21 + {
  22 + StateCommonId = x.StateCommonId,
  23 + Value = x.Value
  24 + }).ToList();
  25 + }
  26 +
  27 + }
  28 +}
0 \ No newline at end of file 29 \ No newline at end of file
src/MapsDb/DataService/SurfaceTypeDs.cs 0 → 100644
  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 SurfaceTypeDc : ISurfaceTypeDs
  10 + {
  11 + private PostgresDbContext _context;
  12 + public SurfaceTypeDc(){
  13 + _context = new PostgresDbContext();
  14 + }
  15 + public Task<IList<SurfaceTypeSelectListDsM>> GetSelectListAsync(){
  16 + return Task.Factory.StartNew(GetSelectList);
  17 + }
  18 + private IList<SurfaceTypeSelectListDsM> GetSelectList()
  19 + {
  20 + return _context.SurfaceType.Select(x => new SurfaceTypeSelectListDsM
  21 + {
  22 + SurfaceTypeId = x.SurfaceTypeId,
  23 + Name = x.Name
  24 + }).ToList();
  25 + }
  26 +
  27 + }
  28 +}
0 \ No newline at end of file 29 \ No newline at end of file
src/MapsDb/Interfaces/IBusStopDs.cs
@@ -2,12 +2,12 @@ using System.Collections.Generic; @@ -2,12 +2,12 @@ using System.Collections.Generic;
2 using System.Threading.Tasks; 2 using System.Threading.Tasks;
3 using MapsModels.DsModels; 3 using MapsModels.DsModels;
4 using MapsDb.Models; 4 using MapsDb.Models;
5 -namespace MapsDb.Interfeces 5 +namespace MapsDb.Interfaces
6 { 6 {
7 public interface IBusStopDs 7 public interface IBusStopDs
8 { 8 {
9 - Task<IList<BusStopListDs>> GetAllBusStopAsync();  
10 - Task SaveBusStopAsync(BusStop busStop);  
11 - Task<BusStopDetailsDs> FindOneDetailsAsync(int Id); 9 + Task<IList<BusStopListDsM>> GetIndexListAsync();
  10 + Task SaveAsync(BusStop busStop);
  11 + Task<BusStopDetailsDsM> FindOneDetailsAsync(int Id);
12 } 12 }
13 } 13 }
14 \ No newline at end of file 14 \ No newline at end of file
src/MapsDb/Interfaces/IRegionDc.cs 0 → 100644
  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 IRegionDc
  8 + {
  9 + Task<IList<RegionSelectListDsM>> GetSelectListAsync();
  10 + }
  11 +}
0 \ No newline at end of file 12 \ No newline at end of file
src/MapsDb/Interfaces/IRoadDs.cs 0 → 100644
  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 IRoadDs
  8 + {
  9 + Task<IList<RoadSelectListDsM>> GetSelectListAsync();
  10 + }
  11 +}
0 \ No newline at end of file 12 \ No newline at end of file
src/MapsDb/Interfaces/ISettlementDs.cs 0 → 100644
  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 ISettlementDs
  8 + {
  9 + Task<IList<SettlementSelectListDsM>> GetSelectListAsync();
  10 + }
  11 +}
0 \ No newline at end of file 12 \ No newline at end of file
src/MapsDb/Interfaces/IStateCommonDs.cs 0 → 100644
  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 IStateCommonDs
  8 + {
  9 + Task<IList<StateCommonSelectListDsM>> GetSelectListAsync();
  10 + }
  11 +}
0 \ No newline at end of file 12 \ No newline at end of file
src/MapsDb/Interfaces/ISurfaceTypeDs.cs 0 → 100644
  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 ISurfaceTypeDs
  8 + {
  9 + Task<IList<SurfaceTypeSelectListDsM>> GetSelectListAsync();
  10 + }
  11 +}
0 \ No newline at end of file 12 \ No newline at end of file
src/MapsModels/DsModels/BusStopDetailsDs.cs renamed to src/MapsModels/DsModels/BusStopDetailsDsM.cs
1 namespace MapsModels.DsModels 1 namespace MapsModels.DsModels
2 { 2 {
3 - public class BusStopDetailsDs 3 + public class BusStopDetailsDsM
4 { 4 {
5 public int BusStopId { get; set; } 5 public int BusStopId { get; set; }
6 public string Road { get; set; } 6 public string Road { get; set; }
src/MapsModels/DsModels/BusStopListDs.cs renamed to src/MapsModels/DsModels/BusStopListDsM.cs
1 namespace MapsModels.DsModels 1 namespace MapsModels.DsModels
2 { 2 {
3 - public class BusStopListDs 3 + public class BusStopListDsM
4 { 4 {
5 public string Road { get; set; } 5 public string Road { get; set; }
6 public string Region { get; set; } 6 public string Region { get; set; }
src/MapsModels/DsModels/RegionSelectListDsM.cs 0 → 100644
  1 +namespace MapsModels.DsModels
  2 +{
  3 + public class RegionSelectListDsM
  4 + {
  5 + public int RegionId { get; set; }
  6 + public string Name { get; set; }
  7 + }
  8 +}
0 \ No newline at end of file 9 \ No newline at end of file
src/MapsModels/DsModels/RoadSelectListDsM.cs 0 → 100644
  1 +namespace MapsModels.DsModels
  2 +{
  3 + public class RoadSelectListDsM
  4 + {
  5 + public int RoadId { get; set; }
  6 + public string Name { get; set; }
  7 + }
  8 +}
0 \ No newline at end of file 9 \ No newline at end of file
src/MapsModels/DsModels/SettlementSelectListDsM.cs 0 → 100644
  1 +namespace MapsModels.DsModels
  2 +{
  3 + public class SettlementSelectListDsM
  4 + {
  5 + public int SettlementId { get; set; }
  6 + public string Name { get; set; }
  7 + }
  8 +}
0 \ No newline at end of file 9 \ No newline at end of file
src/MapsModels/DsModels/StateCommonSelectListDsM.cs 0 → 100644
  1 +namespace MapsModels.DsModels
  2 +{
  3 + public class StateCommonSelectListDsM
  4 + {
  5 + public int StateCommonId { get; set; }
  6 + public string Value { get; set; }
  7 + }
  8 +}
0 \ No newline at end of file 9 \ No newline at end of file
src/MapsModels/DsModels/SurfaceTypeSelectListDsM.cs 0 → 100644
  1 +namespace MapsModels.DsModels
  2 +{
  3 + public class SurfaceTypeSelectListDsM
  4 + {
  5 + public int SurfaceTypeId { get; set; }
  6 + public string Name { get; set; }
  7 + }
  8 +}
0 \ No newline at end of file 9 \ No newline at end of file
src/MapsModels/ViewModels/CreateBusStopVm.cs 0 → 100644
  1 +using System.Collections.Generic;
  2 +using MapsModels.DsModels;
  3 +
  4 +namespace MapsModels.ViewModels
  5 +{
  6 + public class CreateBusStopVm
  7 + {
  8 + public List<SurfaceTypeSelectListDsM> SurfaceTypeSelectListDsM { get; set; }
  9 + public List<StateCommonSelectListDsM> StateCommonSelectListDsM { get; set; }
  10 + public List<SettlementSelectListDsM> SettlementSelectListDsM { get; set; }
  11 + public List<RoadSelectListDsM> RoadSelectListDsM { get; set; }
  12 + public List<RegionSelectListDsM> RegionSelectListDsM { get; set; }
  13 + }
  14 +}
src/MapsModels/ViewModels/DetailsBusStopVm.cs
@@ -5,6 +5,6 @@ namespace MapsModels.ViewModels @@ -5,6 +5,6 @@ namespace MapsModels.ViewModels
5 { 5 {
6 public class DetailsBusStopVm 6 public class DetailsBusStopVm
7 { 7 {
8 - public BusStopDetailsDs busStopDetailsDs { get; set; } 8 + public BusStopDetailsDsM busStopDetailsDsM { get; set; }
9 } 9 }
10 } 10 }
src/MapsModels/ViewModels/ListBusStopVm.cs
@@ -5,6 +5,6 @@ namespace MapsModels.ViewModels @@ -5,6 +5,6 @@ namespace MapsModels.ViewModels
5 { 5 {
6 public class ListBusStopVm 6 public class ListBusStopVm
7 { 7 {
8 - public List<BusStopListDs> busStopListDs { get; set; } 8 + public List<BusStopListDsM> busStopListDsM { get; set; }
9 } 9 }
10 } 10 }