Commit 24f8b1afc991b2b724a82b61f55f8e222abb511f
1 parent
25539461
add RoadSurface
Showing
8 changed files
with
207 additions
and
19 deletions
Show diff stats
| 1 | +// using System.Linq; | |
| 2 | +// using System.Threading.Tasks; | |
| 3 | +// using Microsoft.AspNetCore.Mvc; | |
| 4 | +// using Microsoft.AspNetCore.Mvc.Rendering; | |
| 5 | +// using Microsoft.EntityFrameworkCore; | |
| 6 | +// using MapsDb; | |
| 7 | +// using MapsDb.Interfaces; | |
| 8 | +// using MapsDb.DataService; | |
| 9 | +// using MapsModels.ViewModels; | |
| 10 | +// using MapsModels.DsModels; | |
| 11 | +// using System; | |
| 12 | + | |
| 13 | +// namespace Maps.Controllers | |
| 14 | +// { | |
| 15 | +// public class RoadSurfaceController : Controller | |
| 16 | +// { | |
| 17 | +// private readonly IRoadDs _roadDs; | |
| 18 | +// private readonly IRegionDs _regionDs; | |
| 19 | +// private readonly ISurfaceTypeDs _surfaceTypeDs; | |
| 20 | +// private readonly IStateCommonDs _stateCommonDs; | |
| 21 | +// public RoadSurfaceController(IStateCommonDs StateCommonDs, IRoadDs RoadDs, IRegionDs RegionDs, ISurfaceTypeDs SurfaceTypeDs) | |
| 22 | +// { | |
| 23 | + | |
| 24 | +// _roadDs = RoadDs; | |
| 25 | +// _surfaceTypeDs = SurfaceTypeDs; | |
| 26 | +// _regionDs = RegionDs; | |
| 27 | +// _stateCommonDs = StateCommonDs; | |
| 28 | +// } | |
| 29 | + | |
| 30 | +// // GET: BusStop | |
| 31 | +// [HttpGet] | |
| 32 | +// public async Task<IActionResult> Index([FromQuery] PaginationDsM data) | |
| 33 | +// { | |
| 34 | +// var Data = await _serviceObjectDs.GetIndexListAsync(data); | |
| 35 | + | |
| 36 | +// ServiceObjectListVm vm = new ServiceObjectListVm | |
| 37 | +// { | |
| 38 | +// ServiceObjectEditDsM = Data.ToList() | |
| 39 | +// }; | |
| 40 | + | |
| 41 | +// return Json(vm); | |
| 42 | +// } | |
| 43 | + | |
| 44 | +// [HttpGet] | |
| 45 | +// public async Task<IActionResult> Directory(){ | |
| 46 | +// var DepartmentAffiliation = await _departmentAffiliationDs.GetSelectListAsync(); | |
| 47 | +// var Settlement = await _settlementDs.GetSelectListAsync(); | |
| 48 | +// var Road = await _roadDs.GetSelectListAsync(); | |
| 49 | +// var Region = await _regionDs.GetSelectListAsync(); | |
| 50 | +// var ServiceObjectType = await _serviceObjectTypeDs.GetSelectListAsync(); | |
| 51 | +// CatalogListVm vm = new CatalogListVm | |
| 52 | +// { | |
| 53 | +// DepartmentAffiliationSelectListDsM = DepartmentAffiliation.ToList(), | |
| 54 | +// SettlementSelectListDsM = Settlement.ToList(), | |
| 55 | +// ServiceObjectTypeSelectListDsM = ServiceObjectType.ToList(), | |
| 56 | +// RoadSelectListDsM = Road.ToList(), | |
| 57 | +// RegionSelectListDsM = Region.ToList() | |
| 58 | +// }; | |
| 59 | +// return Json(vm); | |
| 60 | +// } | |
| 61 | + | |
| 62 | + | |
| 63 | +// [HttpPost] | |
| 64 | +// public async Task<IActionResult> Create([FromBody] ServiceObjectEditDsM data) | |
| 65 | +// { | |
| 66 | +// var result = await _serviceObjectDs.CreateAsync(data); | |
| 67 | +// return Json(result); | |
| 68 | +// } | |
| 69 | + | |
| 70 | +// [HttpPost] | |
| 71 | +// public async Task<IActionResult> Update(int id, [FromBody] ServiceObjectEditDsM data){ | |
| 72 | +// await _serviceObjectDs.UpdateAsync(data,id); | |
| 73 | +// return Json(String.Empty); | |
| 74 | +// } | |
| 75 | + | |
| 76 | + | |
| 77 | +// [HttpDelete] | |
| 78 | +// public async Task<IActionResult> Delete(int id) | |
| 79 | +// { | |
| 80 | +// try | |
| 81 | +// { | |
| 82 | +// int data = await _serviceObjectDs.DeleteAsync(id); | |
| 83 | +// return Json(data); | |
| 84 | +// } | |
| 85 | +// catch (ArgumentNullException ) | |
| 86 | +// { | |
| 87 | +// return NotFound(); | |
| 88 | +// } | |
| 89 | +// } | |
| 90 | +// } | |
| 91 | +// } | ... | ... |
src/MapsDb/DataService/BusStopDs.cs
| ... | ... | @@ -19,22 +19,22 @@ namespace MapsDb.DataService |
| 19 | 19 | } |
| 20 | 20 | private IList<BusStopEditDsM> GetAllBusStop(PaginationDsM pagination) |
| 21 | 21 | { |
| 22 | - var data = _context.BusStop.Select(busStop => new BusStopEditDsM | |
| 22 | + var data = _context.BusStop.Select(BusStop => new BusStopEditDsM | |
| 23 | 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 | |
| 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 | 38 | }).Skip(pagination.from).Take(pagination.perPage); |
| 39 | 39 | switch (pagination.orderType()) |
| 40 | 40 | { | ... | ... |
| 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 | +using System.Reflection; | |
| 8 | +using Microsoft.EntityFrameworkCore; | |
| 9 | +namespace MapsDb.DataService | |
| 10 | +{ | |
| 11 | + public class RoadSurfaceDs : IRoadSurfaceDs | |
| 12 | + { | |
| 13 | + private PostgresDbContext _context; | |
| 14 | + public RoadSurfaceDs(){ | |
| 15 | + _context = new PostgresDbContext(); | |
| 16 | + } | |
| 17 | + public Task<IList<RoadSurfaceEditDsM>> GetIndexListAsync(PaginationDsM pagination){ | |
| 18 | + return Task.Factory.StartNew(()=> { return GetAllRoadSurface(pagination); }); | |
| 19 | + } | |
| 20 | + private IList<RoadSurfaceEditDsM> GetAllRoadSurface(PaginationDsM pagination) | |
| 21 | + { | |
| 22 | + var data = _context.RoadSurface.Select(RoadSurface => new RoadSurfaceEditDsM | |
| 23 | + { | |
| 24 | + | |
| 25 | + }).Skip(pagination.from).Take(pagination.perPage); | |
| 26 | + switch (pagination.orderType()) | |
| 27 | + { | |
| 28 | + case "ASC": | |
| 29 | + return data.OrderBy(i => i.GetType().GetProperty(pagination.sort).GetValue(i, null)).ToList(); | |
| 30 | + | |
| 31 | + case "DESC": | |
| 32 | + return data.OrderByDescending(i => i.GetType().GetProperty(pagination.sort).GetValue(i, null)).ToList(); | |
| 33 | + | |
| 34 | + default: | |
| 35 | + return data.OrderByDescending(i => i.Id).ToList(); | |
| 36 | + } | |
| 37 | + } | |
| 38 | + | |
| 39 | + public Task<RoadSurface> CreateAsync(RoadSurfaceEditDsM data){ | |
| 40 | + return Task.Factory.StartNew(()=> { return Create(data); }); | |
| 41 | + } | |
| 42 | + private RoadSurface Create(RoadSurfaceEditDsM data) | |
| 43 | + { | |
| 44 | + RoadSurface Model = InsertModel(data); | |
| 45 | + _context.RoadSurface.Add(Model); | |
| 46 | + _context.SaveChanges(); | |
| 47 | + return Model; | |
| 48 | + } | |
| 49 | + public Task<RoadSurface> UpdateAsync(RoadSurfaceEditDsM data, int id){ | |
| 50 | + return Task.Factory.StartNew(()=> { return Update(data, id); }); | |
| 51 | + } | |
| 52 | + private RoadSurface Update(RoadSurfaceEditDsM data, int id) | |
| 53 | + { | |
| 54 | + RoadSurface Model = InsertModel(data); | |
| 55 | + Model.Id = id; | |
| 56 | + _context.RoadSurface.Update(Model); | |
| 57 | + _context.SaveChanges(); | |
| 58 | + return Model; | |
| 59 | + } | |
| 60 | + public RoadSurface InsertModel(RoadSurfaceEditDsM data){ | |
| 61 | + RoadSurface Model = new RoadSurface{ | |
| 62 | + | |
| 63 | + }; | |
| 64 | + return Model; | |
| 65 | + } | |
| 66 | + public async Task<int> DeleteAsync(int Id) | |
| 67 | + { | |
| 68 | + var RoadSurface = await _context.RoadSurface.SingleOrDefaultAsync(x => x.Id == Id); | |
| 69 | + _context.RoadSurface.Remove(RoadSurface); | |
| 70 | + return await _context.SaveChangesAsync(); | |
| 71 | + } | |
| 72 | + } | |
| 73 | +} | |
| 0 | 74 | \ No newline at end of file | ... | ... |
src/MapsDb/DataService/ServiceObjectDs.cs
| ... | ... | @@ -21,7 +21,7 @@ namespace MapsDb.DataService |
| 21 | 21 | { |
| 22 | 22 | var data = _context.ServiceObject.Select(ServiceObject => new ServiceObjectEditDsM |
| 23 | 23 | { |
| 24 | - ServiceObjectId = ServiceObject.Id, | |
| 24 | + Id = ServiceObject.Id, | |
| 25 | 25 | RoadId = ServiceObject.RoadId, |
| 26 | 26 | RegionId = ServiceObject.RegionId, |
| 27 | 27 | SettlementId = ServiceObject.SettlementId, |
| ... | ... | @@ -70,7 +70,7 @@ namespace MapsDb.DataService |
| 70 | 70 | } |
| 71 | 71 | public ServiceObject InsertModel(ServiceObjectEditDsM data){ |
| 72 | 72 | ServiceObject Model = new ServiceObject{ |
| 73 | - Id = data.ServiceObjectId, | |
| 73 | + Id = data.Id, | |
| 74 | 74 | RoadId = data.RoadId, |
| 75 | 75 | RegionId = data.RegionId, |
| 76 | 76 | SettlementId = data.SettlementId, | ... | ... |
| 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 IRoadSurfaceDs | |
| 8 | + { | |
| 9 | + Task<IList<RoadSurfaceEditDsM>> GetIndexListAsync(PaginationDsM pagination); | |
| 10 | + Task<RoadSurface> CreateAsync(RoadSurfaceEditDsM RoadSurface); | |
| 11 | + Task<RoadSurface> UpdateAsync(RoadSurfaceEditDsM RoadSurface, int id); | |
| 12 | + Task<int> DeleteAsync(int Id); | |
| 13 | + | |
| 14 | + } | |
| 15 | +} | |
| 0 | 16 | \ No newline at end of file | ... | ... |
src/MapsDb/Models/RoadSurface.cs
| ... | ... | @@ -5,7 +5,7 @@ namespace MapsDb.Models |
| 5 | 5 | { |
| 6 | 6 | public partial class RoadSurface |
| 7 | 7 | { |
| 8 | - public int RoadSurfaceId { get; set; } | |
| 8 | + public int Id { get; set; } | |
| 9 | 9 | public int? RoadId { get; set; } |
| 10 | 10 | public int? RegionId { get; set; } |
| 11 | 11 | public int? RoadDirectionId { get; set; } | ... | ... |
src/MapsDb/PostgresDbContext.cs
| ... | ... | @@ -436,7 +436,7 @@ namespace MapsDb |
| 436 | 436 | { |
| 437 | 437 | entity.ToTable("road_surface"); |
| 438 | 438 | |
| 439 | - entity.Property(e => e.RoadSurfaceId).HasColumnName("road_surface_id"); | |
| 439 | + entity.Property(e => e.Id).HasColumnName("id"); | |
| 440 | 440 | |
| 441 | 441 | entity.Property(e => e.Begin).HasColumnName("begin"); |
| 442 | 442 | ... | ... |