32912d0b
Administrator
first commit
|
1
2
3
|
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
|
b9b3b8dd
Administrator
add deteils and c...
|
4
|
using MapsDb.Interfaces;
|
32912d0b
Administrator
first commit
|
5
6
|
using MapsDb.Models;
using MapsModels.DsModels;
|
94ffda14
Yarik
Delete action
|
7
|
using Microsoft.EntityFrameworkCore;
|
32912d0b
Administrator
first commit
|
8
9
10
11
12
13
14
15
16
|
namespace MapsDb.DataService
{
public class BusStopDs : IBusStopDs
{
private PostgresDbContext _context;
public BusStopDs(){
_context = new PostgresDbContext();
}
|
b9b3b8dd
Administrator
add deteils and c...
|
17
|
public Task<IList<BusStopListDsM>> GetIndexListAsync(){
|
32912d0b
Administrator
first commit
|
18
19
|
return Task.Factory.StartNew(GetAllBusStop);
}
|
b9b3b8dd
Administrator
add deteils and c...
|
20
|
private IList<BusStopListDsM> GetAllBusStop()
|
32912d0b
Administrator
first commit
|
21
|
{
|
b9b3b8dd
Administrator
add deteils and c...
|
22
|
return _context.BusStop.Select(x => new BusStopListDsM
|
32912d0b
Administrator
first commit
|
23
24
25
26
27
28
29
30
31
32
|
{
Road = x.Road.Name,
Region = x.Region.Name,
Settlement = x.Settlement.Name,
LocationLeft = x.LocationLeft,
LocationRight = x.LocationRight,
StateCommon = x.StateCommon.Value
}).ToList();
}
|
b9b3b8dd
Administrator
add deteils and c...
|
33
|
public Task SaveAsync(BusStop busStop){
|
32912d0b
Administrator
first commit
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
return Task.Factory.StartNew(()=> { Save(busStop); });
}
private void Save(BusStop busStop)
{
var busStopFromDb = _context.BusStop.SingleOrDefault(x => x.BusStopId == busStop.BusStopId);;
if(busStopFromDb != null)
{
busStopFromDb = busStop;
}
else
{
_context.BusStop.Add(busStop);
}
}
|
b9b3b8dd
Administrator
add deteils and c...
|
48
|
public Task<BusStopDetailsDsM> FindOneDetailsAsync(int Id){
|
44582203
Administrator
bag fix
|
49
|
return Task.Factory.StartNew(()=> { return FindOneDetails(Id); });
|
32912d0b
Administrator
first commit
|
50
|
}
|
b9b3b8dd
Administrator
add deteils and c...
|
51
52
|
private BusStopDetailsDsM FindOneDetails(int Id){
return _context.BusStop.Where(x => x.BusStopId == Id).Select(x => new BusStopDetailsDsM{
|
32912d0b
Administrator
first commit
|
53
54
55
56
57
58
59
60
61
62
63
64
65
|
BusStopId = x.BusStopId,
Road = x.Road.Name,
Region = x.Region.Name,
Settlement = x.Settlement.Name,
LocationLeft = x.LocationLeft,
LocationRight = x.LocationRight,
StateCommon = x.StateCommon.Value,
AreaStopAvailability = x.AreaStopAvailability,
AreaLandAvailability = x.AreaLandAvailability,
PocketAvailability = x.PocketAvailability,
ToiletAvailability = x.ToiletAvailability,
YearBuild = x.YearBuild,
YearRepair = x.YearRepair
|
44582203
Administrator
bag fix
|
66
|
}).Single();
|
32912d0b
Administrator
first commit
|
67
|
}
|
94ffda14
Yarik
Delete action
|
68
69
70
71
72
73
|
public async Task<int> DeleteAsync(int? Id)
{
var busStop = await _context.BusStop.SingleOrDefaultAsync(x => x.BusStopId == Id);
_context.BusStop.Remove(busStop);
return await _context.SaveChangesAsync();
}
|
32912d0b
Administrator
first commit
|
74
75
|
}
}
|