Esempio n. 1
0
        public async Task <IHttpActionResult> GetStation(int id)
        {
            IStationDao   stationDao  = AdoFactory.Instance.GetStationDao("wetr");
            IAddressDao   addressDao  = AdoFactory.Instance.GetAddressDao("wetr");
            ICommunityDao communitDao = AdoFactory.Instance.GetCommunityDao("wetr");
            IDistrictDao  districtDao = AdoFactory.Instance.GetDistrictDao("wetr");
            IProvinceDao  provinceDao = AdoFactory.Instance.GetProvinceDao("wetr");
            ICountryDao   countryDao  = AdoFactory.Instance.GetCountryDao("wetr");

            Station myStations = await stationDao.FindByIdAsync(id);

            if (myStations == null)
            {
                return(Content(HttpStatusCode.BadRequest, new object()));
            }

            StationDTO station = new StationDTO(myStations);

            station.CommunityId = (await addressDao.FindByIdAsync(station.AddressId)).CommunityId;
            station.DistrictId  = (await communitDao.FindByIdAsync(station.CommunityId)).DistrictId;
            station.ProvinceId  = (await districtDao.FindByIdAsync(station.DistrictId)).ProvinceId;
            station.CountryId   = (await provinceDao.FindByIdAsync(station.ProvinceId)).CountryId;
            station.Location    = (await addressDao.FindByIdAsync(station.AddressId)).Location;

            return(Content(HttpStatusCode.OK, station));
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> GetMyStations()
        {
            string token  = Request.Headers.GetValues("Authorization").FirstOrDefault();
            int    userId = JwtHelper.Instance.GetUserId(token);

            IStationDao   stationDao  = AdoFactory.Instance.GetStationDao("wetr");
            IAddressDao   addressDao  = AdoFactory.Instance.GetAddressDao("wetr");
            ICommunityDao communitDao = AdoFactory.Instance.GetCommunityDao("wetr");
            IDistrictDao  districtDao = AdoFactory.Instance.GetDistrictDao("wetr");
            IProvinceDao  provinceDao = AdoFactory.Instance.GetProvinceDao("wetr");
            ICountryDao   countryDao  = AdoFactory.Instance.GetCountryDao("wetr");

            IEnumerable <Station> myStations = null;

            myStations = await stationDao.FindByUserIdAsync(userId);

            List <StationDTO> convertedStations = new List <StationDTO>();

            /* Infer location ids for convenience */
            foreach (var s in myStations)
            {
                StationDTO station = new StationDTO(s);

                station.CommunityId = (await addressDao.FindByIdAsync(station.AddressId)).CommunityId;
                station.DistrictId  = (await communitDao.FindByIdAsync(station.CommunityId)).DistrictId;
                station.ProvinceId  = (await districtDao.FindByIdAsync(station.DistrictId)).ProvinceId;
                station.CountryId   = (await provinceDao.FindByIdAsync(station.ProvinceId)).CountryId;
                station.Location    = (await addressDao.FindByIdAsync(station.AddressId)).Location;

                convertedStations.Add(station);
            }

            return(Content(HttpStatusCode.OK, convertedStations));
        }
Esempio n. 3
0
        public void Setup()
        {
            _communityDao = Substitute.For <ICommunityDao>();
            Func <HttpRequestMessage> fakeFunc = () => FakeHttpMessageBuilder.CreateFakeHttpMessage();

            _modelFactory  = new ModelFactory(new ObjectDifferenceManager(), fakeFunc);
            _communityRepo = new CommunityRepository(_communityDao, _modelFactory);
            _fixture       = new Fixture();
        }
 public async Task <IEnumerable <Community> > GetAllCommunities()
 {
     try {
         ICommunityDao stationDao = GetICommunityDao();
         return(await stationDao.FindAllAsync());
     }
     catch (Exception) {
         return(null);
     }
 }
Esempio n. 5
0
 public AddressManager(ICountryDao countryDao,
                       IProvinceDao provinceDao,
                       IDistrictDao districtDao,
                       ICommunityDao communityDao,
                       IAddressDao addressDao
                       )
 {
     this.countryDao   = countryDao;
     this.communityDao = communityDao;
     this.provinceDao  = provinceDao;
     this.districtDao  = districtDao;
     this.addressDao   = addressDao;
 }
Esempio n. 6
0
        public async Task <IHttpActionResult> GetStations(int communityId)
        {
            IStationDao   stationDao  = AdoFactory.Instance.GetStationDao("wetr");
            IAddressDao   addressDao  = AdoFactory.Instance.GetAddressDao("wetr");
            ICommunityDao communitDao = AdoFactory.Instance.GetCommunityDao("wetr");
            IDistrictDao  districtDao = AdoFactory.Instance.GetDistrictDao("wetr");
            IProvinceDao  provinceDao = AdoFactory.Instance.GetProvinceDao("wetr");
            ICountryDao   countryDao  = AdoFactory.Instance.GetCountryDao("wetr");

            IEnumerable <Station> stations = null;

            stations = await stationDao.FindAllAsync();

            List <StationDTO> convertedStations = new List <StationDTO>();

            /* Infer location ids for convenience */
            foreach (var s in stations)
            {
                StationDTO station = new StationDTO(s);

                station.CommunityId = (await addressDao.FindByIdAsync(station.AddressId)).CommunityId;
                station.DistrictId  = (await communitDao.FindByIdAsync(station.CommunityId)).DistrictId;
                station.ProvinceId  = (await districtDao.FindByIdAsync(station.DistrictId)).ProvinceId;
                station.CountryId   = (await provinceDao.FindByIdAsync(station.ProvinceId)).CountryId;
                station.Location    = (await addressDao.FindByIdAsync(station.AddressId)).Location;

                convertedStations.Add(station);
            }

            if (communityId != 0)
            {
                convertedStations.RemoveAll(s => s.CommunityId != communityId);
            }

            return(Content(HttpStatusCode.OK, convertedStations));
        }
 private static ICommunityDao GetICommunityDao()
 {
     return(_iCommunityDao ?? (_iCommunityDao =
                                   new AdoCommunityDao(DefaultConnectionFactory.FromConfiguration(_connectionStringConfigName))));
 }
Esempio n. 8
0
 public CommunityRepository(ICommunityDao communityDao, IModelFactory modelFactory)
 {
     _communityDao = communityDao;
     _modelFactory = modelFactory;
 }
Esempio n. 9
0
        public async Task <IHttpActionResult> GetCommunities()
        {
            ICommunityDao dao = AdoFactory.Instance.GetCommunityDao("wetr");

            return(Ok(await dao.FindAllAsync()));
        }