Exemplo n.º 1
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()));
        }
Exemplo n.º 2
0
        public async Task TestFindByStationIdAsync()
        {
            IEnumerable <Measurement> fetched = await measurementDao.FindByStationIdAsync(32);

            foreach (Measurement m in measurements)
            {
                CollectionAssert.Contains(fetched.ToList(), m);
            }
        }
Exemplo n.º 3
0
 public async Task <bool> HasMeasurements(Station station)
 {
     try
     {
         return((await measurementDao.FindByStationIdAsync(station.StationId)).Count() != 0);
     }
     catch (Common.Dal.Ado.MySqlException ex)
     {
         throw new BusinessSqlException(ex.Message, ex.InnerException);
     }
 }