FlowIntensityDs.cs
5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using MapsDb.Interfaces;
using MapsDb.Models;
using MapsModels.DsModels;
using Microsoft.EntityFrameworkCore;
namespace MapsDb.DataService
{
public class FlowIntensityDs : IFlowIntensityDs
{
private PostgresDbContext _context;
public FlowIntensityDs(){
_context = new PostgresDbContext();
}
public Task<IList<FlowIntensityEditDsM>> GetIndexListAsync(PaginationDsM pagination){
return Task.Factory.StartNew(()=> { return GetAllFlowIntensity(pagination); });
}
private IList<FlowIntensityEditDsM> GetAllFlowIntensity(PaginationDsM pagination)
{
var data = _context.FlowIntensity.Select(FlowIntensity => new FlowIntensityEditDsM
{
Id = FlowIntensity.Id,
RoadId = FlowIntensity.RoadId,
RegionId = FlowIntensity.RegionId,
Location = FlowIntensity.Location,
Begin = FlowIntensity.Begin,
End = FlowIntensity.End,
RoadDirectionId = FlowIntensity.RoadDirectionId,
SettlementId = FlowIntensity.SettlementId,
IntensityTotal = FlowIntensity.IntensityTotal,
IntensityIncrease = FlowIntensity.IntensityIncrease,
IntensityMoto = FlowIntensity.IntensityMoto,
IntensityMotoSidecar = FlowIntensity.IntensityMotoSidecar,
IntensityCar = FlowIntensity.IntensityCar,
IntensityTruckTwo = FlowIntensity.IntensityTruckTwo,
IntensityTruckTwoSix = FlowIntensity.IntensityTruckTwoSix,
IntensityTruckSixEight = FlowIntensity.IntensityTruckSixEight,
IntensityTruckEightFourteen = FlowIntensity.IntensityTruckEightFourteen,
IntensityTruckFourteen = FlowIntensity.IntensityTruckFourteen,
IntensityLorryTwelve = FlowIntensity.IntensityLorryTwelve,
IntensityLorryTwelveTwenty = FlowIntensity.IntensityLorryTwelveTwenty,
IntensityLorryTwentyThirty = FlowIntensity.IntensityLorryTwentyThirty,
IntensityLorryThirty = FlowIntensity.IntensityLorryThirty,
IntensityTractorUnderTen = FlowIntensity.IntensityTractorUnderTen,
IntensityTractorOverTen = FlowIntensity.IntensityTractorOverTen,
IntensityBus = FlowIntensity.IntensityBus,
IntensityBusCoupled = FlowIntensity.IntensityBusCoupled,
DateAdd = FlowIntensity.DateAdd,
}).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<FlowIntensity> CreateAsync(FlowIntensityEditDsM data){
return Task.Factory.StartNew(()=> { return Create(data); });
}
private FlowIntensity Create(FlowIntensityEditDsM data)
{
FlowIntensity Model = InsertModel(data);
_context.FlowIntensity.Add(Model);
_context.SaveChanges();
return Model;
}
public Task<FlowIntensity> UpdateAsync(FlowIntensityEditDsM data, int id){
return Task.Factory.StartNew(()=> { return Update(data, id); });
}
private FlowIntensity Update(FlowIntensityEditDsM data, int id)
{
FlowIntensity Model = InsertModel(data);
Model.Id = id;
_context.FlowIntensity.Update(Model);
_context.SaveChanges();
return Model;
}
public FlowIntensity InsertModel(FlowIntensityEditDsM data){
FlowIntensity Model = new FlowIntensity{
RoadId = data.RoadId,
RegionId = data.RegionId,
Location = data.Location,
Begin = data.Begin,
End = data.End,
RoadDirectionId = data.RoadDirectionId,
SettlementId = data.SettlementId,
IntensityTotal = data.IntensityTotal,
IntensityIncrease = data.IntensityIncrease,
IntensityMoto = data.IntensityMoto,
IntensityMotoSidecar = data.IntensityMotoSidecar,
IntensityCar = data.IntensityCar,
IntensityTruckTwo = data.IntensityTruckTwo,
IntensityTruckTwoSix = data.IntensityTruckTwoSix,
IntensityTruckSixEight = data.IntensityTruckSixEight,
IntensityTruckEightFourteen = data.IntensityTruckEightFourteen,
IntensityTruckFourteen = data.IntensityTruckFourteen,
IntensityLorryTwelve = data.IntensityLorryTwelve,
IntensityLorryTwelveTwenty = data.IntensityLorryTwelveTwenty,
IntensityLorryTwentyThirty = data.IntensityLorryTwentyThirty,
IntensityLorryThirty = data.IntensityLorryThirty,
IntensityTractorUnderTen = data.IntensityTractorUnderTen,
IntensityTractorOverTen = data.IntensityTractorOverTen,
IntensityBus = data.IntensityBus,
IntensityBusCoupled = data.IntensityBusCoupled,
DateAdd = data.DateAdd,
};
return Model;
}
public async Task<int> DeleteAsync(int Id)
{
var flowIntensity = await _context.FlowIntensity.SingleOrDefaultAsync(x => x.Id == Id);
_context.FlowIntensity.Remove(flowIntensity);
return await _context.SaveChangesAsync();
}
}
}