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())); }
public async Task TestFindByStationIdAsync() { IEnumerable <Measurement> fetched = await measurementDao.FindByStationIdAsync(32); foreach (Measurement m in measurements) { CollectionAssert.Contains(fetched.ToList(), m); } }
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); } }