From 24f8b1afc991b2b724a82b61f55f8e222abb511f Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 13 Feb 2017 13:14:02 +0200 Subject: [PATCH] add RoadSurface --- src/Maps/Controllers/RoadSurfaceController.cs | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/MapsDb/DataService/BusStopDs.cs | 30 +++++++++++++++--------------- src/MapsDb/DataService/RoadSurfaceDs.cs | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/MapsDb/DataService/ServiceObjectDs.cs | 4 ++-- src/MapsDb/Interfaces/IRoadSurfaceDs.cs | 15 +++++++++++++++ src/MapsDb/Models/RoadSurface.cs | 2 +- src/MapsDb/PostgresDbContext.cs | 2 +- src/MapsModels/DsModels/RoadSurfaceEditDsM.cs | 9 +++++++++ 8 files changed, 207 insertions(+), 19 deletions(-) create mode 100755 src/Maps/Controllers/RoadSurfaceController.cs create mode 100644 src/MapsDb/DataService/RoadSurfaceDs.cs create mode 100644 src/MapsDb/Interfaces/IRoadSurfaceDs.cs create mode 100644 src/MapsModels/DsModels/RoadSurfaceEditDsM.cs diff --git a/src/Maps/Controllers/RoadSurfaceController.cs b/src/Maps/Controllers/RoadSurfaceController.cs new file mode 100755 index 0000000..95796a4 --- /dev/null +++ b/src/Maps/Controllers/RoadSurfaceController.cs @@ -0,0 +1,91 @@ +// using System.Linq; +// using System.Threading.Tasks; +// using Microsoft.AspNetCore.Mvc; +// using Microsoft.AspNetCore.Mvc.Rendering; +// using Microsoft.EntityFrameworkCore; +// using MapsDb; +// using MapsDb.Interfaces; +// using MapsDb.DataService; +// using MapsModels.ViewModels; +// using MapsModels.DsModels; +// using System; + +// namespace Maps.Controllers +// { +// public class RoadSurfaceController : Controller +// { +// private readonly IRoadDs _roadDs; +// private readonly IRegionDs _regionDs; +// private readonly ISurfaceTypeDs _surfaceTypeDs; +// private readonly IStateCommonDs _stateCommonDs; +// public RoadSurfaceController(IStateCommonDs StateCommonDs, IRoadDs RoadDs, IRegionDs RegionDs, ISurfaceTypeDs SurfaceTypeDs) +// { + +// _roadDs = RoadDs; +// _surfaceTypeDs = SurfaceTypeDs; +// _regionDs = RegionDs; +// _stateCommonDs = StateCommonDs; +// } + +// // GET: BusStop +// [HttpGet] +// public async Task Index([FromQuery] PaginationDsM data) +// { +// var Data = await _serviceObjectDs.GetIndexListAsync(data); + +// ServiceObjectListVm vm = new ServiceObjectListVm +// { +// ServiceObjectEditDsM = Data.ToList() +// }; + +// return Json(vm); +// } + +// [HttpGet] +// public async Task Directory(){ +// var DepartmentAffiliation = await _departmentAffiliationDs.GetSelectListAsync(); +// var Settlement = await _settlementDs.GetSelectListAsync(); +// var Road = await _roadDs.GetSelectListAsync(); +// var Region = await _regionDs.GetSelectListAsync(); +// var ServiceObjectType = await _serviceObjectTypeDs.GetSelectListAsync(); +// CatalogListVm vm = new CatalogListVm +// { +// DepartmentAffiliationSelectListDsM = DepartmentAffiliation.ToList(), +// SettlementSelectListDsM = Settlement.ToList(), +// ServiceObjectTypeSelectListDsM = ServiceObjectType.ToList(), +// RoadSelectListDsM = Road.ToList(), +// RegionSelectListDsM = Region.ToList() +// }; +// return Json(vm); +// } + + +// [HttpPost] +// public async Task Create([FromBody] ServiceObjectEditDsM data) +// { +// var result = await _serviceObjectDs.CreateAsync(data); +// return Json(result); +// } + +// [HttpPost] +// public async Task Update(int id, [FromBody] ServiceObjectEditDsM data){ +// await _serviceObjectDs.UpdateAsync(data,id); +// return Json(String.Empty); +// } + + +// [HttpDelete] +// public async Task Delete(int id) +// { +// try +// { +// int data = await _serviceObjectDs.DeleteAsync(id); +// return Json(data); +// } +// catch (ArgumentNullException ) +// { +// return NotFound(); +// } +// } +// } +// } diff --git a/src/MapsDb/DataService/BusStopDs.cs b/src/MapsDb/DataService/BusStopDs.cs index 76004ea..dd1ca30 100644 --- a/src/MapsDb/DataService/BusStopDs.cs +++ b/src/MapsDb/DataService/BusStopDs.cs @@ -19,22 +19,22 @@ namespace MapsDb.DataService } private IList GetAllBusStop(PaginationDsM pagination) { - var data = _context.BusStop.Select(busStop => new BusStopEditDsM + var data = _context.BusStop.Select(BusStop => new BusStopEditDsM { - Id = busStop.Id, - RoadId = busStop.RoadId, - RegionId = busStop.RegionId, - SettlementId = busStop.SettlementId, - LocationLeft = busStop.LocationLeft, - LocationRight = busStop.LocationRight, - SurfaceTypeId = busStop.SurfaceTypeId, - AreaStopAvailability = busStop.AreaStopAvailability, - AreaLandAvailability = busStop.AreaLandAvailability, - PocketAvailability = busStop.PocketAvailability, - ToiletAvailability = busStop.ToiletAvailability, - YearBuild = busStop.YearBuild, - YearRepair = busStop.YearRepair, - StateCommonId = busStop.StateCommonId + Id = BusStop.Id, + RoadId = BusStop.RoadId, + RegionId = BusStop.RegionId, + SettlementId = BusStop.SettlementId, + LocationLeft = BusStop.LocationLeft, + LocationRight = BusStop.LocationRight, + SurfaceTypeId = BusStop.SurfaceTypeId, + AreaStopAvailability = BusStop.AreaStopAvailability, + AreaLandAvailability = BusStop.AreaLandAvailability, + PocketAvailability = BusStop.PocketAvailability, + ToiletAvailability = BusStop.ToiletAvailability, + YearBuild = BusStop.YearBuild, + YearRepair = BusStop.YearRepair, + StateCommonId = BusStop.StateCommonId }).Skip(pagination.from).Take(pagination.perPage); switch (pagination.orderType()) { diff --git a/src/MapsDb/DataService/RoadSurfaceDs.cs b/src/MapsDb/DataService/RoadSurfaceDs.cs new file mode 100644 index 0000000..d73953d --- /dev/null +++ b/src/MapsDb/DataService/RoadSurfaceDs.cs @@ -0,0 +1,73 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using MapsDb.Interfaces; +using MapsDb.Models; +using MapsModels.DsModels; +using System.Reflection; +using Microsoft.EntityFrameworkCore; +namespace MapsDb.DataService +{ + public class RoadSurfaceDs : IRoadSurfaceDs + { + private PostgresDbContext _context; + public RoadSurfaceDs(){ + _context = new PostgresDbContext(); + } + public Task> GetIndexListAsync(PaginationDsM pagination){ + return Task.Factory.StartNew(()=> { return GetAllRoadSurface(pagination); }); + } + private IList GetAllRoadSurface(PaginationDsM pagination) + { + var data = _context.RoadSurface.Select(RoadSurface => new RoadSurfaceEditDsM + { + + }).Skip(pagination.from).Take(pagination.perPage); + switch (pagination.orderType()) + { + case "ASC": + return data.OrderBy(i => i.GetType().GetProperty(pagination.sort).GetValue(i, null)).ToList(); + + case "DESC": + return data.OrderByDescending(i => i.GetType().GetProperty(pagination.sort).GetValue(i, null)).ToList(); + + default: + return data.OrderByDescending(i => i.Id).ToList(); + } + } + + public Task CreateAsync(RoadSurfaceEditDsM data){ + return Task.Factory.StartNew(()=> { return Create(data); }); + } + private RoadSurface Create(RoadSurfaceEditDsM data) + { + RoadSurface Model = InsertModel(data); + _context.RoadSurface.Add(Model); + _context.SaveChanges(); + return Model; + } + public Task UpdateAsync(RoadSurfaceEditDsM data, int id){ + return Task.Factory.StartNew(()=> { return Update(data, id); }); + } + private RoadSurface Update(RoadSurfaceEditDsM data, int id) + { + RoadSurface Model = InsertModel(data); + Model.Id = id; + _context.RoadSurface.Update(Model); + _context.SaveChanges(); + return Model; + } + public RoadSurface InsertModel(RoadSurfaceEditDsM data){ + RoadSurface Model = new RoadSurface{ + + }; + return Model; + } + public async Task DeleteAsync(int Id) + { + var RoadSurface = await _context.RoadSurface.SingleOrDefaultAsync(x => x.Id == Id); + _context.RoadSurface.Remove(RoadSurface); + return await _context.SaveChangesAsync(); + } + } +} \ No newline at end of file diff --git a/src/MapsDb/DataService/ServiceObjectDs.cs b/src/MapsDb/DataService/ServiceObjectDs.cs index daec83f..39e7803 100644 --- a/src/MapsDb/DataService/ServiceObjectDs.cs +++ b/src/MapsDb/DataService/ServiceObjectDs.cs @@ -21,7 +21,7 @@ namespace MapsDb.DataService { var data = _context.ServiceObject.Select(ServiceObject => new ServiceObjectEditDsM { - ServiceObjectId = ServiceObject.Id, + Id = ServiceObject.Id, RoadId = ServiceObject.RoadId, RegionId = ServiceObject.RegionId, SettlementId = ServiceObject.SettlementId, @@ -70,7 +70,7 @@ namespace MapsDb.DataService } public ServiceObject InsertModel(ServiceObjectEditDsM data){ ServiceObject Model = new ServiceObject{ - Id = data.ServiceObjectId, + Id = data.Id, RoadId = data.RoadId, RegionId = data.RegionId, SettlementId = data.SettlementId, diff --git a/src/MapsDb/Interfaces/IRoadSurfaceDs.cs b/src/MapsDb/Interfaces/IRoadSurfaceDs.cs new file mode 100644 index 0000000..3a53754 --- /dev/null +++ b/src/MapsDb/Interfaces/IRoadSurfaceDs.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using MapsModels.DsModels; +using MapsDb.Models; +namespace MapsDb.Interfaces +{ + public interface IRoadSurfaceDs + { + Task> GetIndexListAsync(PaginationDsM pagination); + Task CreateAsync(RoadSurfaceEditDsM RoadSurface); + Task UpdateAsync(RoadSurfaceEditDsM RoadSurface, int id); + Task DeleteAsync(int Id); + + } +} \ No newline at end of file diff --git a/src/MapsDb/Models/RoadSurface.cs b/src/MapsDb/Models/RoadSurface.cs index db3ecbc..8f9b01e 100644 --- a/src/MapsDb/Models/RoadSurface.cs +++ b/src/MapsDb/Models/RoadSurface.cs @@ -5,7 +5,7 @@ namespace MapsDb.Models { public partial class RoadSurface { - public int RoadSurfaceId { get; set; } + public int Id { get; set; } public int? RoadId { get; set; } public int? RegionId { get; set; } public int? RoadDirectionId { get; set; } diff --git a/src/MapsDb/PostgresDbContext.cs b/src/MapsDb/PostgresDbContext.cs index 7315160..f86d0e6 100644 --- a/src/MapsDb/PostgresDbContext.cs +++ b/src/MapsDb/PostgresDbContext.cs @@ -436,7 +436,7 @@ namespace MapsDb { entity.ToTable("road_surface"); - entity.Property(e => e.RoadSurfaceId).HasColumnName("road_surface_id"); + entity.Property(e => e.Id).HasColumnName("id"); entity.Property(e => e.Begin).HasColumnName("begin"); diff --git a/src/MapsModels/DsModels/RoadSurfaceEditDsM.cs b/src/MapsModels/DsModels/RoadSurfaceEditDsM.cs new file mode 100644 index 0000000..6faf982 --- /dev/null +++ b/src/MapsModels/DsModels/RoadSurfaceEditDsM.cs @@ -0,0 +1,9 @@ +namespace MapsModels.DsModels +{ + public class RoadSurfaceEditDsM + { + public int Id { get; set; } + + + } +} \ No newline at end of file -- libgit2 0.21.4