Commit da981eb590e4acbe6bec661aba52d1f9c545933a
1 parent
59f80a46
FlowIntensity
Showing
6 changed files
with
280 additions
and
1 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 FlowIntensityController : Controller | ||
| 16 | + { | ||
| 17 | + private readonly IFlowIntensityDs _flowIntensityDs; | ||
| 18 | + private readonly IRoadDs _roadDs; | ||
| 19 | + private readonly IRegionDs _regionDs; | ||
| 20 | + private readonly IRoadDirectionDs _roadDirectionDs; | ||
| 21 | + private readonly ISettlementDs _settlementDs; | ||
| 22 | + | ||
| 23 | + public FlowIntensityController(IFlowIntensityDs FlowIntensityDs, IRoadDs RoadDs, ISettlementDs SettlementDs, IRegionDs RegionDs, IRoadDirectionDs RoadDirectionDs) | ||
| 24 | + { | ||
| 25 | + _flowIntensityDs = FlowIntensityDs; | ||
| 26 | + _roadDs = RoadDs; | ||
| 27 | + _settlementDs = SettlementDs; | ||
| 28 | + _regionDs = RegionDs; | ||
| 29 | + _roadDirectionDs = RoadDirectionDs; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + // GET: FlowIntensity | ||
| 33 | + [HttpGet] | ||
| 34 | + public async Task<IActionResult> Index([FromQuery] PaginationDsM data) | ||
| 35 | + { | ||
| 36 | + try | ||
| 37 | + { | ||
| 38 | + var flowIntensitys = await _flowIntensityDs.GetIndexListAsync(data); | ||
| 39 | + | ||
| 40 | + FlowIntensityListVm vm = new FlowIntensityListVm | ||
| 41 | + { | ||
| 42 | + FlowIntensityEditDsM = flowIntensitys.ToList() | ||
| 43 | + }; | ||
| 44 | + | ||
| 45 | + return Json(vm); | ||
| 46 | + } | ||
| 47 | + catch (NullReferenceException) | ||
| 48 | + { | ||
| 49 | + Response.StatusCode = 400; | ||
| 50 | + return Json("There is no field with name " + data.sort); | ||
| 51 | + } | ||
| 52 | + catch (Exception) | ||
| 53 | + { | ||
| 54 | + return NotFound(); | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + [HttpGet] | ||
| 59 | + public async Task<IActionResult> Directory(){ | ||
| 60 | + var Settlement = await _settlementDs.GetSelectListAsync(); | ||
| 61 | + var Road = await _roadDs.GetSelectListAsync(); | ||
| 62 | + var Region = await _regionDs.GetSelectListAsync(); | ||
| 63 | + var RoadDirection = await _roadDirectionDs.GetSelectListAsync(); | ||
| 64 | + | ||
| 65 | + CatalogListVm vm = new CatalogListVm | ||
| 66 | + { | ||
| 67 | + SettlementSelectListDsM = Settlement.ToList(), | ||
| 68 | + RoadSelectListDsM = Road.ToList(), | ||
| 69 | + RegionSelectListDsM = Region.ToList(), | ||
| 70 | + RoadDirectionSelectListDsM = RoadDirection.ToList(), | ||
| 71 | + }; | ||
| 72 | + return Json(vm); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + | ||
| 76 | + [HttpPost] | ||
| 77 | + public async Task<IActionResult> Create([FromBody] FlowIntensityEditDsM data) | ||
| 78 | + { | ||
| 79 | + var result = await _flowIntensityDs.CreateAsync(data); | ||
| 80 | + return Json(result); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + [HttpPost] | ||
| 84 | + public async Task<IActionResult> Update(int id, [FromBody] FlowIntensityEditDsM data){ | ||
| 85 | + await _flowIntensityDs.UpdateAsync(data,id); | ||
| 86 | + return Json(String.Empty); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + | ||
| 90 | + [HttpDelete] | ||
| 91 | + public async Task<IActionResult> Delete(int id) | ||
| 92 | + { | ||
| 93 | + try | ||
| 94 | + { | ||
| 95 | + int flowIntensity = await _flowIntensityDs.DeleteAsync(id); | ||
| 96 | + return Json(flowIntensity); | ||
| 97 | + } | ||
| 98 | + catch (ArgumentNullException ) | ||
| 99 | + { | ||
| 100 | + return NotFound(); | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | + } | ||
| 104 | +} |
src/Maps/Startup.cs
| @@ -57,6 +57,7 @@ namespace Maps | @@ -57,6 +57,7 @@ namespace Maps | ||
| 57 | services.AddScoped<IRoadDirectionDs, RoadDirectionDs>(); | 57 | services.AddScoped<IRoadDirectionDs, RoadDirectionDs>(); |
| 58 | services.AddScoped<IRoadSurfaceDs, RoadSurfaceDs>(); | 58 | services.AddScoped<IRoadSurfaceDs, RoadSurfaceDs>(); |
| 59 | services.AddScoped<IRoadWidthDs, RoadWidthDs>(); | 59 | services.AddScoped<IRoadWidthDs, RoadWidthDs>(); |
| 60 | + services.AddScoped<IFlowIntensityDs, FlowIntensityDs>(); | ||
| 60 | services.AddScoped<ICrossSectionDs, CrossSectionDs>(); | 61 | services.AddScoped<ICrossSectionDs, CrossSectionDs>(); |
| 61 | // Add framework services. | 62 | // Add framework services. |
| 62 | services.AddApplicationInsightsTelemetry(Configuration); | 63 | services.AddApplicationInsightsTelemetry(Configuration); |
| 1 | +using System.Collections.Generic; | ||
| 2 | +using System.Linq; | ||
| 3 | +using System.Reflection; | ||
| 4 | +using System.Threading.Tasks; | ||
| 5 | +using MapsDb.Interfaces; | ||
| 6 | +using MapsDb.Models; | ||
| 7 | +using MapsModels.DsModels; | ||
| 8 | +using Microsoft.EntityFrameworkCore; | ||
| 9 | +namespace MapsDb.DataService | ||
| 10 | +{ | ||
| 11 | + public class FlowIntensityDs : IFlowIntensityDs | ||
| 12 | + { | ||
| 13 | + private PostgresDbContext _context; | ||
| 14 | + public FlowIntensityDs(){ | ||
| 15 | + _context = new PostgresDbContext(); | ||
| 16 | + } | ||
| 17 | + public Task<IList<FlowIntensityEditDsM>> GetIndexListAsync(PaginationDsM pagination){ | ||
| 18 | + return Task.Factory.StartNew(()=> { return GetAllFlowIntensity(pagination); }); | ||
| 19 | + } | ||
| 20 | + private IList<FlowIntensityEditDsM> GetAllFlowIntensity(PaginationDsM pagination) | ||
| 21 | + { | ||
| 22 | + var data = _context.FlowIntensity.Select(FlowIntensity => new FlowIntensityEditDsM | ||
| 23 | + { | ||
| 24 | + Id = FlowIntensity.Id, | ||
| 25 | + RoadId = FlowIntensity.RoadId, | ||
| 26 | + RegionId = FlowIntensity.RegionId, | ||
| 27 | + Location = FlowIntensity.Location, | ||
| 28 | + Begin = FlowIntensity.Begin, | ||
| 29 | + End = FlowIntensity.End, | ||
| 30 | + RoadDirectionId = FlowIntensity.RoadDirectionId, | ||
| 31 | + SettlementId = FlowIntensity.SettlementId, | ||
| 32 | + IntensityTotal = FlowIntensity.IntensityTotal, | ||
| 33 | + IntensityIncrease = FlowIntensity.IntensityIncrease, | ||
| 34 | + IntensityMoto = FlowIntensity.IntensityMoto, | ||
| 35 | + IntensityMotoSidecar = FlowIntensity.IntensityMotoSidecar, | ||
| 36 | + IntensityCar = FlowIntensity.IntensityCar, | ||
| 37 | + IntensityTruckTwo = FlowIntensity.IntensityTruckTwo, | ||
| 38 | + IntensityTruckTwoSix = FlowIntensity.IntensityTruckTwoSix, | ||
| 39 | + IntensityTruckSixEight = FlowIntensity.IntensityTruckSixEight, | ||
| 40 | + IntensityTruckEightFourteen = FlowIntensity.IntensityTruckEightFourteen, | ||
| 41 | + IntensityTruckFourteen = FlowIntensity.IntensityTruckFourteen, | ||
| 42 | + IntensityLorryTwelve = FlowIntensity.IntensityLorryTwelve, | ||
| 43 | + IntensityLorryTwelveTwenty = FlowIntensity.IntensityLorryTwelveTwenty, | ||
| 44 | + IntensityLorryTwentyThirty = FlowIntensity.IntensityLorryTwentyThirty, | ||
| 45 | + IntensityLorryThirty = FlowIntensity.IntensityLorryThirty, | ||
| 46 | + IntensityTractorUnderTen = FlowIntensity.IntensityTractorUnderTen, | ||
| 47 | + IntensityTractorOverTen = FlowIntensity.IntensityTractorOverTen, | ||
| 48 | + IntensityBus = FlowIntensity.IntensityBus, | ||
| 49 | + IntensityBusCoupled = FlowIntensity.IntensityBusCoupled, | ||
| 50 | + DateAdd = FlowIntensity.DateAdd, | ||
| 51 | + }).Skip(pagination.from).Take(pagination.perPage); | ||
| 52 | + switch (pagination.orderType()) | ||
| 53 | + { | ||
| 54 | + case "ASC": | ||
| 55 | + return data.OrderBy(i => i.GetType().GetProperty(pagination.sort).GetValue(i, null)).ToList(); | ||
| 56 | + | ||
| 57 | + case "DESC": | ||
| 58 | + return data.OrderByDescending(i => i.GetType().GetProperty(pagination.sort).GetValue(i, null)).ToList(); | ||
| 59 | + | ||
| 60 | + default: | ||
| 61 | + return data.OrderByDescending(i => i.Id).ToList(); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public Task<FlowIntensity> CreateAsync(FlowIntensityEditDsM data){ | ||
| 67 | + return Task.Factory.StartNew(()=> { return Create(data); }); | ||
| 68 | + } | ||
| 69 | + private FlowIntensity Create(FlowIntensityEditDsM data) | ||
| 70 | + { | ||
| 71 | + | ||
| 72 | + FlowIntensity Model = InsertModel(data); | ||
| 73 | + _context.FlowIntensity.Add(Model); | ||
| 74 | + _context.SaveChanges(); | ||
| 75 | + return Model; | ||
| 76 | + } | ||
| 77 | + public Task<FlowIntensity> UpdateAsync(FlowIntensityEditDsM data, int id){ | ||
| 78 | + return Task.Factory.StartNew(()=> { return Update(data, id); }); | ||
| 79 | + } | ||
| 80 | + private FlowIntensity Update(FlowIntensityEditDsM data, int id) | ||
| 81 | + { | ||
| 82 | + FlowIntensity Model = InsertModel(data); | ||
| 83 | + Model.Id = id; | ||
| 84 | + _context.FlowIntensity.Update(Model); | ||
| 85 | + _context.SaveChanges(); | ||
| 86 | + return Model; | ||
| 87 | + } | ||
| 88 | + public FlowIntensity InsertModel(FlowIntensityEditDsM data){ | ||
| 89 | + FlowIntensity Model = new FlowIntensity{ | ||
| 90 | + RoadId = data.RoadId, | ||
| 91 | + RegionId = data.RegionId, | ||
| 92 | + Location = data.Location, | ||
| 93 | + Begin = data.Begin, | ||
| 94 | + End = data.End, | ||
| 95 | + RoadDirectionId = data.RoadDirectionId, | ||
| 96 | + SettlementId = data.SettlementId, | ||
| 97 | + IntensityTotal = data.IntensityTotal, | ||
| 98 | + IntensityIncrease = data.IntensityIncrease, | ||
| 99 | + IntensityMoto = data.IntensityMoto, | ||
| 100 | + IntensityMotoSidecar = data.IntensityMotoSidecar, | ||
| 101 | + IntensityCar = data.IntensityCar, | ||
| 102 | + IntensityTruckTwo = data.IntensityTruckTwo, | ||
| 103 | + IntensityTruckTwoSix = data.IntensityTruckTwoSix, | ||
| 104 | + IntensityTruckSixEight = data.IntensityTruckSixEight, | ||
| 105 | + IntensityTruckEightFourteen = data.IntensityTruckEightFourteen, | ||
| 106 | + IntensityTruckFourteen = data.IntensityTruckFourteen, | ||
| 107 | + IntensityLorryTwelve = data.IntensityLorryTwelve, | ||
| 108 | + IntensityLorryTwelveTwenty = data.IntensityLorryTwelveTwenty, | ||
| 109 | + IntensityLorryTwentyThirty = data.IntensityLorryTwentyThirty, | ||
| 110 | + IntensityLorryThirty = data.IntensityLorryThirty, | ||
| 111 | + IntensityTractorUnderTen = data.IntensityTractorUnderTen, | ||
| 112 | + IntensityTractorOverTen = data.IntensityTractorOverTen, | ||
| 113 | + IntensityBus = data.IntensityBus, | ||
| 114 | + IntensityBusCoupled = data.IntensityBusCoupled, | ||
| 115 | + DateAdd = data.DateAdd, | ||
| 116 | + }; | ||
| 117 | + return Model; | ||
| 118 | + } | ||
| 119 | + public async Task<int> DeleteAsync(int Id) | ||
| 120 | + { | ||
| 121 | + var flowIntensity = await _context.FlowIntensity.SingleOrDefaultAsync(x => x.Id == Id); | ||
| 122 | + _context.FlowIntensity.Remove(flowIntensity); | ||
| 123 | + return await _context.SaveChangesAsync(); | ||
| 124 | + } | ||
| 125 | + } | ||
| 126 | +} | ||
| 0 | \ No newline at end of file | 127 | \ 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 IFlowIntensityDs | ||
| 8 | + { | ||
| 9 | + Task<IList<FlowIntensityEditDsM>> GetIndexListAsync(PaginationDsM pagination); | ||
| 10 | + Task<FlowIntensity> CreateAsync(FlowIntensityEditDsM flowIntensity); | ||
| 11 | + Task<FlowIntensity> UpdateAsync(FlowIntensityEditDsM flowIntensity, int id); | ||
| 12 | + Task<int> DeleteAsync(int Id); | ||
| 13 | + } | ||
| 14 | +} | ||
| 0 | \ No newline at end of file | 15 | \ No newline at end of file |
src/MapsDb/Models/FlowIntensity.cs
| @@ -5,7 +5,7 @@ namespace MapsDb.Models | @@ -5,7 +5,7 @@ namespace MapsDb.Models | ||
| 5 | { | 5 | { |
| 6 | public partial class FlowIntensity | 6 | public partial class FlowIntensity |
| 7 | { | 7 | { |
| 8 | - public int FlowIntensityId { get; set; } | 8 | + public int Id { get; set; } |
| 9 | public int? RoadId { get; set; } | 9 | public int? RoadId { get; set; } |
| 10 | public int? RegionId { get; set; } | 10 | public int? RegionId { get; set; } |
| 11 | public double? Location { get; set; } | 11 | public double? Location { get; set; } |
| 1 | +namespace MapsModels.DsModels | ||
| 2 | +{ | ||
| 3 | + public class FlowIntensityEditDsM | ||
| 4 | + { | ||
| 5 | + public int Id { get; set; } | ||
| 6 | + public int? RoadId { get; set; } | ||
| 7 | + public int? RegionId { get; set; } | ||
| 8 | + public double? Location { get; set; } | ||
| 9 | + public double? Begin { get; set; } | ||
| 10 | + public double? End { get; set; } | ||
| 11 | + public int? RoadDirectionId { get; set; } | ||
| 12 | + public int? SettlementId { get; set; } | ||
| 13 | + public int? IntensityTotal { get; set; } | ||
| 14 | + public int? IntensityIncrease { get; set; } | ||
| 15 | + public int? IntensityMoto { get; set; } | ||
| 16 | + public int? IntensityMotoSidecar { get; set; } | ||
| 17 | + public int? IntensityCar { get; set; } | ||
| 18 | + public int? IntensityTruckTwo { get; set; } | ||
| 19 | + public int? IntensityTruckTwoSix { get; set; } | ||
| 20 | + public int? IntensityTruckSixEight { get; set; } | ||
| 21 | + public int? IntensityTruckEightFourteen { get; set; } | ||
| 22 | + public int? IntensityTruckFourteen { get; set; } | ||
| 23 | + public int? IntensityLorryTwelve { get; set; } | ||
| 24 | + public int? IntensityLorryTwelveTwenty { get; set; } | ||
| 25 | + public int? IntensityLorryTwentyThirty { get; set; } | ||
| 26 | + public int? IntensityLorryThirty { get; set; } | ||
| 27 | + public int? IntensityTractorUnderTen { get; set; } | ||
| 28 | + public int? IntensityTractorOverTen { get; set; } | ||
| 29 | + public int? IntensityBus { get; set; } | ||
| 30 | + public int? IntensityBusCoupled { get; set; } | ||
| 31 | + public int? DateAdd { get; set; } | ||
| 32 | + | ||
| 33 | + } | ||
| 34 | +} | ||
| 0 | \ No newline at end of file | 35 | \ No newline at end of file |