Blame view

src/MapsDb/DataService/BusStopDs.cs 2.46 KB
32912d0b   Administrator   first commit
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
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using MapsDb.Interfeces;
  using MapsDb.Models;
  using MapsModels.DsModels;
  
  namespace MapsDb.DataService
  {
      public class BusStopDs : IBusStopDs
      {
          private PostgresDbContext _context;
          public BusStopDs(){
              _context = new PostgresDbContext();
          }
          public void Dispose()
          {
              _context.Dispose();
          }
  
          public Task<IList<BusStopListDs>> GetAllBusStopAsync(){
              return Task.Factory.StartNew(GetAllBusStop);
          }
          private IList<BusStopListDs> GetAllBusStop()
          {
             return _context.BusStop.Select(x => new BusStopListDs
              {
                  Road = x.Road.Name, 
                  Region = x.Region.Name,
                  Settlement = x.Settlement.Name,
                  LocationLeft = x.LocationLeft,
                  LocationRight = x.LocationRight,
                  StateCommon = x.StateCommon.Value
              }).ToList();
          }
  
          public Task SaveBusStopAsync(BusStop busStop){
                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);
              }
          }
          public Task<BusStopDetailsDs> FindOneDetailsAsync(int Id){
44582203   Administrator   bag fix
53
               return Task.Factory.StartNew(()=> { return FindOneDetails(Id); });
32912d0b   Administrator   first commit
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
          }
          private BusStopDetailsDs FindOneDetails(int Id){
             return _context.BusStop.Where(x => x.BusStopId == Id).Select(x => new BusStopDetailsDs{
                  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
70
             }).Single();
32912d0b   Administrator   first commit
71
72
73
          }
      }
  }