Example #1
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));
        }
Example #2
0
        public async Task <IHttpActionResult> DeleteStation(int stationId)
        {
            string token  = Request.Headers.GetValues("Authorization").FirstOrDefault();
            int    userId = JwtHelper.Instance.GetUserId(token);

            IStationDao           stationDao = AdoFactory.Instance.GetStationDao("wetr");
            IEnumerable <Station> stations   = await stationDao.FindByUserIdAsync(userId);

            if (stations.Where(s => s.StationId == stationId).Count() == 0)
            {
                /* No station found so it might have been already deleted. */
                return(Content(HttpStatusCode.Forbidden, new object()));
            }

            IMeasurementDao measurementDao = AdoFactory.Instance.GetMeasurementDao("wetr");

            if ((await measurementDao.FindByStationIdAsync(stationId)).Count() > 0)
            {
                /* There must not be any measurmenets associated with this station. */
                return(Content(HttpStatusCode.Forbidden, new object()));
            }

            await stationDao.DeleteAsync(stationId);

            return(Content(HttpStatusCode.OK, new object()));
        }
Example #3
0
        public async Task TestFindByUserIdAsync()
        {
            int UserId = 1;
            IEnumerable <Station> stations = await stationDao.FindByUserIdAsync(UserId);

            foreach (var station in stations)
            {
                Assert.IsTrue(station.UserId == UserId);
            }
        }
Example #4
0
 public async Task <IEnumerable <Station> > GetStationsForUser(int userId)
 {
     try
     {
         return(await stationDao.FindByUserIdAsync(userId));
     }
     catch (Common.Dal.Ado.MySqlException ex)
     {
         throw new BusinessSqlException(ex.Message, ex.InnerException);
     }
 }