Commit e02ee314ad9d20320f299b2d1c9f867268bbe2f4
1 parent
27918c1f
add update and create methods
Showing
14 changed files
with
147 additions
and
111 deletions
Show diff stats
src/Maps/Controllers/BusStopController.cs
... | ... | @@ -68,27 +68,22 @@ namespace Maps.Controllers |
68 | 68 | [HttpPost] |
69 | 69 | public async Task<IActionResult> Create([FromBody] BusStopEditDsM data) |
70 | 70 | { |
71 | - var result = await _busStopDs.SaveAsync(data); | |
71 | + var result = await _busStopDs.CreateAsync(data); | |
72 | 72 | return Json(result); |
73 | 73 | } |
74 | 74 | |
75 | 75 | [HttpPost] |
76 | 76 | public async Task<IActionResult> Update(int id, [FromBody] BusStopEditDsM data){ |
77 | - await _busStopDs.SaveAsync(data,id); | |
77 | + await _busStopDs.UpdateAsync(data,id); | |
78 | 78 | return Json(String.Empty); |
79 | 79 | } |
80 | 80 | |
81 | 81 | |
82 | 82 | [HttpDelete] |
83 | - public async Task<IActionResult> Delete(int? id) | |
83 | + public async Task<IActionResult> Delete(int id) | |
84 | 84 | { |
85 | 85 | try |
86 | 86 | { |
87 | - if (id == null) | |
88 | - { | |
89 | - return NotFound(); | |
90 | - } | |
91 | - | |
92 | 87 | int busStop = await _busStopDs.DeleteAsync(id); |
93 | 88 | return Json(busStop); |
94 | 89 | } | ... | ... |
src/Maps/Controllers/ServiceObjectController.cs
... | ... | @@ -15,18 +15,20 @@ namespace Maps.Controllers |
15 | 15 | public class ServiceObjectController : Controller |
16 | 16 | { |
17 | 17 | private readonly IServiceObjectDs _serviceObjectDs; |
18 | + private readonly IServiceObjectTypeDs _serviceObjectTypeDs; | |
18 | 19 | private readonly IRoadDs _roadDs; |
19 | 20 | private readonly ISettlementDs _settlementDs; |
20 | 21 | private readonly IRegionDs _regionDs; |
21 | 22 | private readonly IDepartmentAffiliationDs _departmentAffiliationDs; |
22 | 23 | |
23 | - public ServiceObjectController(IServiceObjectDs ServiceObjectDs, IRoadDs RoadDs, ISettlementDs SettlementDs, IRegionDs RegionDs, IDepartmentAffiliationDs DepartmentAffiliationDs) | |
24 | + public ServiceObjectController(IServiceObjectTypeDs ServiceObjectTypeDs, IServiceObjectDs ServiceObjectDs, IRoadDs RoadDs, ISettlementDs SettlementDs, IRegionDs RegionDs, IDepartmentAffiliationDs DepartmentAffiliationDs) | |
24 | 25 | { |
25 | 26 | _serviceObjectDs = ServiceObjectDs; |
26 | 27 | _roadDs = RoadDs; |
27 | 28 | _settlementDs = SettlementDs; |
28 | 29 | _regionDs = RegionDs; |
29 | - _departmentAffiliationDs = DepartmentAffiliationDs; | |
30 | + _departmentAffiliationDs = DepartmentAffiliationDs; | |
31 | + _serviceObjectTypeDs = ServiceObjectTypeDs; | |
30 | 32 | } |
31 | 33 | |
32 | 34 | // GET: BusStop |
... | ... | @@ -49,11 +51,12 @@ namespace Maps.Controllers |
49 | 51 | var Settlement = await _settlementDs.GetSelectListAsync(); |
50 | 52 | var Road = await _roadDs.GetSelectListAsync(); |
51 | 53 | var Region = await _regionDs.GetSelectListAsync(); |
52 | - | |
54 | + var ServiceObjectType = await _serviceObjectTypeDs.GetSelectListAsync(); | |
53 | 55 | CatalogListVm vm = new CatalogListVm |
54 | 56 | { |
55 | - DepartmentAffiliationDsM = DepartmentAffiliation.ToList(), | |
57 | + DepartmentAffiliationSelectListDsM = DepartmentAffiliation.ToList(), | |
56 | 58 | SettlementSelectListDsM = Settlement.ToList(), |
59 | + ServiceObjectTypeSelectListDsM = ServiceObjectType.ToList(), | |
57 | 60 | RoadSelectListDsM = Road.ToList(), |
58 | 61 | RegionSelectListDsM = Region.ToList() |
59 | 62 | }; |
... | ... | @@ -64,28 +67,23 @@ namespace Maps.Controllers |
64 | 67 | [HttpPost] |
65 | 68 | public async Task<IActionResult> Create([FromBody] ServiceObjectEditDsM data) |
66 | 69 | { |
67 | - var result = await _serviceObjectDs.SaveAsync(data); | |
70 | + var result = await _serviceObjectDs.CreateAsync(data); | |
68 | 71 | return Json(result); |
69 | 72 | } |
70 | 73 | |
71 | 74 | [HttpPost] |
72 | 75 | public async Task<IActionResult> Update(int id, [FromBody] ServiceObjectEditDsM data){ |
73 | - await _serviceObjectDs.SaveAsync(data,id); | |
76 | + await _serviceObjectDs.UpdateAsync(data,id); | |
74 | 77 | return Json(String.Empty); |
75 | 78 | } |
76 | 79 | |
77 | 80 | |
78 | 81 | [HttpDelete] |
79 | - public async Task<IActionResult> Delete(int? id) | |
82 | + public async Task<IActionResult> Delete(int id) | |
80 | 83 | { |
81 | 84 | try |
82 | 85 | { |
83 | - if (id == null) | |
84 | - { | |
85 | - return NotFound(); | |
86 | - } | |
87 | - | |
88 | - int data = await _serviceObjectDs.DeleteAsync(id); | |
86 | + int data = await _serviceObjectDs.DeleteAsync(id); | |
89 | 87 | return Json(data); |
90 | 88 | } |
91 | 89 | catch (ArgumentNullException ) | ... | ... |
src/Maps/Startup.cs
... | ... | @@ -50,6 +50,7 @@ namespace Maps |
50 | 50 | services.AddScoped<IStateCommonDs, StateCommonDs>(); |
51 | 51 | services.AddScoped<ISurfaceTypeDs, SurfaceTypeDs>(); |
52 | 52 | services.AddScoped<IServiceObjectDs, ServiceObjectDs>(); |
53 | + services.AddScoped<IServiceObjectTypeDs, ServiceObjectTypeDs>(); | |
53 | 54 | services.AddScoped<ISettlementDs, SettlementDs>(); |
54 | 55 | services.AddScoped<IDepartmentAffiliationDs, DepartmentAffiliationDs>(); |
55 | 56 | // Add framework services. | ... | ... |
src/MapsDb/DataService/BusStopDs.cs
... | ... | @@ -37,51 +37,47 @@ namespace MapsDb.DataService |
37 | 37 | }).OrderByDescending(BusStop => BusStop.BusStopId).ToList(); |
38 | 38 | } |
39 | 39 | |
40 | - public Task<BusStop> SaveAsync(BusStopEditDsM busStop, int? id = null){ | |
41 | - return Task.Factory.StartNew(()=> { return Save(busStop, id); }); | |
40 | + public Task<BusStop> CreateAsync(BusStopEditDsM data){ | |
41 | + return Task.Factory.StartNew(()=> { return Create(data); }); | |
42 | 42 | } |
43 | - private BusStop Save(BusStopEditDsM busStop, int? id) | |
43 | + private BusStop Create(BusStopEditDsM data) | |
44 | 44 | { |
45 | - BusStop Bs = new BusStop{ | |
46 | - RoadId = busStop.RoadId, | |
47 | - RegionId = busStop.RegionId, | |
48 | - SettlementId = busStop.SettlementId, | |
49 | - LocationLeft = busStop.LocationLeft, | |
50 | - LocationRight = busStop.LocationRight, | |
51 | - SurfaceTypeId = busStop.SurfaceTypeId, | |
52 | - AreaStopAvailability = busStop.AreaStopAvailability, | |
53 | - AreaLandAvailability = busStop.AreaLandAvailability, | |
54 | - PocketAvailability = busStop.PocketAvailability, | |
55 | - ToiletAvailability = busStop.ToiletAvailability, | |
56 | - YearBuild = busStop.YearBuild, | |
57 | - YearRepair = busStop.YearRepair, | |
58 | - StateCommonId = busStop.StateCommonId | |
59 | - }; | |
60 | - var busStopFromDb = _context.BusStop.FirstOrDefault(x => x.BusStopId == id); | |
61 | - if(busStopFromDb != null) | |
62 | - { | |
63 | - busStopFromDb.RoadId = busStop.RoadId; | |
64 | - busStopFromDb.RegionId = busStop.RegionId; | |
65 | - busStopFromDb.SettlementId = busStop.SettlementId; | |
66 | - busStopFromDb.LocationLeft = busStop.LocationLeft; | |
67 | - busStopFromDb.LocationRight = busStop.LocationRight; | |
68 | - busStopFromDb.SurfaceTypeId = busStop.SurfaceTypeId; | |
69 | - busStopFromDb.AreaStopAvailability = busStop.AreaStopAvailability; | |
70 | - busStopFromDb.AreaLandAvailability = busStop.AreaLandAvailability; | |
71 | - busStopFromDb.PocketAvailability = busStop.PocketAvailability; | |
72 | - busStopFromDb.ToiletAvailability = busStop.ToiletAvailability; | |
73 | - busStopFromDb.YearBuild = busStop.YearBuild; | |
74 | - busStopFromDb.YearRepair = busStop.YearRepair; | |
75 | - busStopFromDb.StateCommonId = busStop.StateCommonId; | |
76 | - } | |
77 | - else | |
78 | - { | |
79 | - _context.BusStop.Add(Bs); | |
80 | - } | |
45 | + | |
46 | + BusStop Model = InsertModel(data); | |
47 | + _context.BusStop.Add(Model); | |
81 | 48 | _context.SaveChanges(); |
82 | - return Bs; | |
49 | + return Model; | |
50 | + } | |
51 | + public Task<BusStop> UpdateAsync(BusStopEditDsM data, int id){ | |
52 | + return Task.Factory.StartNew(()=> { return Update(data, id); }); | |
53 | + } | |
54 | + private BusStop Update(BusStopEditDsM data, int id) | |
55 | + { | |
56 | + BusStop Model = InsertModel(data); | |
57 | + Model.BusStopId = id; | |
58 | + _context.BusStop.Update(Model); | |
59 | + _context.SaveChanges(); | |
60 | + return Model; | |
61 | + } | |
62 | + public BusStop InsertModel(BusStopEditDsM data){ | |
63 | + BusStop Model = new BusStop{ | |
64 | + RoadId = data.RoadId, | |
65 | + RegionId = data.RegionId, | |
66 | + SettlementId = data.SettlementId, | |
67 | + LocationLeft = data.LocationLeft, | |
68 | + LocationRight = data.LocationRight, | |
69 | + SurfaceTypeId = data.SurfaceTypeId, | |
70 | + AreaStopAvailability = data.AreaStopAvailability, | |
71 | + AreaLandAvailability = data.AreaLandAvailability, | |
72 | + PocketAvailability = data.PocketAvailability, | |
73 | + ToiletAvailability = data.ToiletAvailability, | |
74 | + YearBuild = data.YearBuild, | |
75 | + YearRepair = data.YearRepair, | |
76 | + StateCommonId = data.StateCommonId | |
77 | + }; | |
78 | + return Model; | |
83 | 79 | } |
84 | - public async Task<int> DeleteAsync(int? Id) | |
80 | + public async Task<int> DeleteAsync(int Id) | |
85 | 81 | { |
86 | 82 | var busStop = await _context.BusStop.SingleOrDefaultAsync(x => x.BusStopId == Id); |
87 | 83 | _context.BusStop.Remove(busStop); | ... | ... |
src/MapsDb/DataService/DepartmentAffiliationDs.cs
... | ... | @@ -12,12 +12,12 @@ namespace MapsDb.DataService |
12 | 12 | public DepartmentAffiliationDs(){ |
13 | 13 | _context = new PostgresDbContext(); |
14 | 14 | } |
15 | - public Task<IList<DepartmentAffiliationListDsM>> GetSelectListAsync(){ | |
15 | + public Task<IList<DepartmentAffiliationSelectListDsM>> GetSelectListAsync(){ | |
16 | 16 | return Task.Factory.StartNew(GetSelectList); |
17 | 17 | } |
18 | - private IList<DepartmentAffiliationListDsM> GetSelectList() | |
18 | + private IList<DepartmentAffiliationSelectListDsM> GetSelectList() | |
19 | 19 | { |
20 | - return _context.DepartmentAffiliation.Select(x => new DepartmentAffiliationListDsM | |
20 | + return _context.DepartmentAffiliation.Select(x => new DepartmentAffiliationSelectListDsM | |
21 | 21 | { |
22 | 22 | DepartmentAffiliationId = x.DepartmentAffiliationId, |
23 | 23 | Name = x.Name | ... | ... |
src/MapsDb/DataService/ServiceObjectDs.cs
... | ... | @@ -35,49 +35,45 @@ namespace MapsDb.DataService |
35 | 35 | }).OrderByDescending(ServiceObject => ServiceObject.ServiceObjectId).ToList(); |
36 | 36 | } |
37 | 37 | |
38 | - public Task<ServiceObject> SaveAsync(ServiceObjectEditDsM serviceObject, int? id = null){ | |
39 | - return Task.Factory.StartNew(()=> { return Save(serviceObject, id); }); | |
38 | + public Task<ServiceObject> CreateAsync(ServiceObjectEditDsM data){ | |
39 | + return Task.Factory.StartNew(()=> { return Create(data); }); | |
40 | 40 | } |
41 | - private ServiceObject Save(ServiceObjectEditDsM serviceObject, int? id) | |
41 | + private ServiceObject Create(ServiceObjectEditDsM data) | |
42 | 42 | { |
43 | - ServiceObject Data = new ServiceObject{ | |
44 | - ServiceObjectId = serviceObject.ServiceObjectId, | |
45 | - RoadId = serviceObject.RoadId, | |
46 | - RegionId = serviceObject.RegionId, | |
47 | - SettlementId = serviceObject.SettlementId, | |
48 | - LocationLeft = serviceObject.LocationLeft, | |
49 | - LocationRight = serviceObject.LocationRight, | |
50 | - ServiceObjectTypeId = serviceObject.ServiceObjectTypeId, | |
51 | - DepartmentAffiliationId = serviceObject.DepartmentAffiliationId, | |
52 | - LocationAxis = serviceObject.LocationAxis, | |
53 | - Distance = serviceObject.Distance, | |
54 | - Capacity = serviceObject.Capacity, | |
55 | - ArrangementElements = serviceObject.ArrangementElements, | |
56 | - }; | |
57 | - var ServiceObjectFromDb = _context.ServiceObject.FirstOrDefault(x => x.ServiceObjectId == id); | |
58 | - if(ServiceObjectFromDb != null) | |
59 | - { | |
60 | - ServiceObjectFromDb.ServiceObjectId = Data.ServiceObjectId; | |
61 | - ServiceObjectFromDb.RoadId = Data.RoadId; | |
62 | - ServiceObjectFromDb.RegionId = Data.RegionId; | |
63 | - ServiceObjectFromDb.SettlementId = Data.SettlementId; | |
64 | - ServiceObjectFromDb.LocationLeft = Data.LocationLeft; | |
65 | - ServiceObjectFromDb.LocationRight = Data.LocationRight; | |
66 | - ServiceObjectFromDb.ServiceObjectTypeId = Data.ServiceObjectTypeId; | |
67 | - ServiceObjectFromDb.DepartmentAffiliationId = Data.DepartmentAffiliationId; | |
68 | - ServiceObjectFromDb.LocationAxis = Data.LocationAxis; | |
69 | - ServiceObjectFromDb.Distance = Data.Distance; | |
70 | - ServiceObjectFromDb.Capacity = Data.Capacity; | |
71 | - ServiceObjectFromDb.ArrangementElements = Data.ArrangementElements; | |
72 | - } | |
73 | - else | |
74 | - { | |
75 | - _context.ServiceObject.Add(Data); | |
76 | - } | |
43 | + ServiceObject Model = InsertModel(data); | |
44 | + _context.ServiceObject.Add(Model); | |
77 | 45 | _context.SaveChanges(); |
78 | - return Data; | |
46 | + return Model; | |
47 | + } | |
48 | + public Task<ServiceObject> UpdateAsync(ServiceObjectEditDsM data, int id){ | |
49 | + return Task.Factory.StartNew(()=> { return Update(data, id); }); | |
50 | + } | |
51 | + private ServiceObject Update(ServiceObjectEditDsM data, int id) | |
52 | + { | |
53 | + ServiceObject Model = InsertModel(data); | |
54 | + Model.ServiceObjectId = id; | |
55 | + _context.ServiceObject.Update(Model); | |
56 | + _context.SaveChanges(); | |
57 | + return Model; | |
58 | + } | |
59 | + public ServiceObject InsertModel(ServiceObjectEditDsM data){ | |
60 | + ServiceObject Model = new ServiceObject{ | |
61 | + ServiceObjectId = data.ServiceObjectId, | |
62 | + RoadId = data.RoadId, | |
63 | + RegionId = data.RegionId, | |
64 | + SettlementId = data.SettlementId, | |
65 | + LocationLeft = data.LocationLeft, | |
66 | + LocationRight = data.LocationRight, | |
67 | + ServiceObjectTypeId = data.ServiceObjectTypeId, | |
68 | + DepartmentAffiliationId = data.DepartmentAffiliationId, | |
69 | + LocationAxis = data.LocationAxis, | |
70 | + Distance = data.Distance, | |
71 | + Capacity = data.Capacity, | |
72 | + ArrangementElements = data.ArrangementElements, | |
73 | + }; | |
74 | + return Model; | |
79 | 75 | } |
80 | - public async Task<int> DeleteAsync(int? Id) | |
76 | + public async Task<int> DeleteAsync(int Id) | |
81 | 77 | { |
82 | 78 | var ServiceObject = await _context.ServiceObject.SingleOrDefaultAsync(x => x.ServiceObjectId == Id); |
83 | 79 | _context.ServiceObject.Remove(ServiceObject); | ... | ... |
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 ServiceObjectTypeDs : IServiceObjectTypeDs | |
10 | + { | |
11 | + private PostgresDbContext _context; | |
12 | + public ServiceObjectTypeDs(){ | |
13 | + _context = new PostgresDbContext(); | |
14 | + } | |
15 | + public Task<IList<ServiceObjectTypeSelectListDsM>> GetSelectListAsync(){ | |
16 | + return Task.Factory.StartNew(GetSelectList); | |
17 | + } | |
18 | + private IList<ServiceObjectTypeSelectListDsM> GetSelectList() | |
19 | + { | |
20 | + return _context.ServiceObjectType.Select(x => new ServiceObjectTypeSelectListDsM | |
21 | + { | |
22 | + ServiceObjectTypeId = x.ServiceObjectTypeId, | |
23 | + Name = x.Name | |
24 | + }).ToList(); | |
25 | + } | |
26 | + | |
27 | + } | |
28 | +} | |
0 | 29 | \ No newline at end of file | ... | ... |
src/MapsDb/Interfaces/IBusStopDs.cs
... | ... | @@ -7,7 +7,8 @@ namespace MapsDb.Interfaces |
7 | 7 | public interface IBusStopDs |
8 | 8 | { |
9 | 9 | Task<IList<BusStopEditDsM>> GetIndexListAsync(); |
10 | - Task<BusStop> SaveAsync(BusStopEditDsM busStop, int? id = null); | |
11 | - Task<int> DeleteAsync(int? Id); | |
10 | + Task<BusStop> CreateAsync(BusStopEditDsM busStop); | |
11 | + Task<BusStop> UpdateAsync(BusStopEditDsM busStop, int id); | |
12 | + Task<int> DeleteAsync(int Id); | |
12 | 13 | } |
13 | 14 | } |
14 | 15 | \ No newline at end of file | ... | ... |
src/MapsDb/Interfaces/IDepartmentAffiliationDs.cs
... | ... | @@ -6,6 +6,6 @@ namespace MapsDb.Interfaces |
6 | 6 | { |
7 | 7 | public interface IDepartmentAffiliationDs |
8 | 8 | { |
9 | - Task<IList<DepartmentAffiliationListDsM>> GetSelectListAsync(); | |
9 | + Task<IList<DepartmentAffiliationSelectListDsM>> GetSelectListAsync(); | |
10 | 10 | } |
11 | 11 | } |
12 | 12 | \ No newline at end of file | ... | ... |
src/MapsDb/Interfaces/IServiceObjectDs.cs
... | ... | @@ -7,8 +7,9 @@ namespace MapsDb.Interfaces |
7 | 7 | public interface IServiceObjectDs |
8 | 8 | { |
9 | 9 | Task<IList<ServiceObjectEditDsM>> GetIndexListAsync(); |
10 | - Task<ServiceObject> SaveAsync(ServiceObjectEditDsM serviceObject, int? id = null); | |
11 | - Task<int> DeleteAsync(int? Id); | |
10 | + Task<ServiceObject> CreateAsync(ServiceObjectEditDsM serviceObject); | |
11 | + Task<ServiceObject> UpdateAsync(ServiceObjectEditDsM serviceObject, int id); | |
12 | + Task<int> DeleteAsync(int Id); | |
12 | 13 | |
13 | 14 | } |
14 | 15 | } |
15 | 16 | \ 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 IServiceObjectTypeDs | |
8 | + { | |
9 | + Task<IList<ServiceObjectTypeSelectListDsM>> GetSelectListAsync(); | |
10 | + } | |
11 | +} | |
0 | 12 | \ No newline at end of file | ... | ... |
src/MapsModels/DsModels/DepartmentAffiliationListDsM.cs renamed to src/MapsModels/DsModels/DepartmentAffiliationSelectListDsM.cs
src/MapsModels/DsModels/ServiceObjectTypeSelectListDsM.cs
0 → 100644
src/MapsModels/ViewModels/CatalogListVm.cs
... | ... | @@ -5,8 +5,9 @@ namespace MapsModels.ViewModels |
5 | 5 | { |
6 | 6 | public class CatalogListVm |
7 | 7 | { |
8 | - public List<DepartmentAffiliationListDsM> DepartmentAffiliationDsM { get; set; } | |
8 | + public List<DepartmentAffiliationSelectListDsM> DepartmentAffiliationSelectListDsM { get; set; } | |
9 | 9 | public List<SurfaceTypeSelectListDsM> SurfaceTypeSelectListDsM { get; set; } |
10 | + public List<ServiceObjectTypeSelectListDsM> ServiceObjectTypeSelectListDsM { get; set; } | |
10 | 11 | public List<StateCommonSelectListDsM> StateCommonSelectListDsM { get; set; } |
11 | 12 | public List<SettlementSelectListDsM> SettlementSelectListDsM { get; set; } |
12 | 13 | public List<RoadSelectListDsM> RoadSelectListDsM { get; set; } | ... | ... |