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)); }
public async Task <bool> AddStation(Station station) { try { if (station != null) { IStationDao stationDao = GetIStationDao(); if (station.CommunityId == 0 && station.Community != null) { station.CommunityId = station.Community.Id; } if (station.TypeId == 0 && station.StationType != null) { station.TypeId = station.StationType.Id; } if (station.Creator == 0 && station.User != null) { station.Creator = station.User.Id; } return(await stationDao.AddStationAsync(station)); } return(false); } catch (Exception) { return(false); } }
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)); }
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 <IEnumerable <Station> > GetStationByCreatorId(int creator) { try { IStationDao stationDao = GetIStationDao(); return(await stationDao.FindByCreatorIdAsync(creator)); } catch (Exception) { return(null); } }
public async Task <IEnumerable <Station> > FilterByRegion(District district) { try { IStationDao stationDao = GetIStationDao(); return(await stationDao.FindByDistrictIdAsync(district.Id)); } catch (Exception) { return(null); } }
public async Task <IEnumerable <Station> > GetStationsByTypeId(int stationTypeId) { try { IStationDao stationDao = GetIStationDao(); return(await stationDao.FindByStationTypeIdAsync(stationTypeId)); } catch (Exception) { return(null); } }
public async Task <IEnumerable <Station> > FilterByRegion(Province province) { try { IStationDao stationDao = GetIStationDao(); return(await stationDao.FindByProvinceIdAsync(province.Id)); } catch (Exception) { return(null); } }
public async Task <IEnumerable <Station> > GetAllJoined() { try { IStationDao stationDao = GetIStationDao(); return(await stationDao.FindJoinedAsync()); } catch (Exception) { return(null); } }
public async Task <IEnumerable <Station> > FilterByRegion(Community community) { try { IStationDao stationDao = GetIStationDao(); return(await stationDao.FindByCommunityIdAsync(community.Id)); } catch (Exception) { return(null); } }
public async Task <Station> GetStationById(int id) { try { IStationDao stationDao = GetIStationDao(); return(await stationDao.FindJoinedByIdAsync(id)); } catch (Exception) { return(null); } }
public async Task <IEnumerable <Station> > GetStationsByName(string name) { try { if (!name.Equals("")) { IStationDao stationDao = GetIStationDao(); return(await stationDao.FindByNameAsync(name)); } return(null); } catch (Exception) { return(null); } }
public async Task <bool> DeleteStation(Station station) { // Catch exeption faster than check if measurements are in db!!! try { if (station != null) { IStationDao stationDao = GetIStationDao(); return(await stationDao.DeleteStationAsync(station)); } return(false); } catch (Exception) { return(false); } }
public async Task <IHttpActionResult> EditStationAsync(StationDTO station) { /* Check if model is valid */ if (!ModelState.IsValid) { var errors = ModelState.ToDictionary( kvp => kvp.Key, kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray() ); return(Content(HttpStatusCode.BadRequest, errors)); } string token = Request.Headers.GetValues("Authorization").FirstOrDefault(); int userId = JwtHelper.Instance.GetUserId(token); IStationDao stationDao = AdoFactory.Instance.GetStationDao("wetr"); Station stationToEdit = await stationDao.FindByIdAsync(station.StationId); /* If the station doesn't belong to the user */ if (stationToEdit.UserId != userId) { return(Content(HttpStatusCode.Forbidden, new object())); } /* Create new address */ IAddressDao addressDao = AdoFactory.Instance.GetAddressDao("wetr"); await addressDao.UpdateAsync(new Address() { AddressId = stationToEdit.AddressId, CommunityId = station.CommunityId, Location = station.Location, Zip = "NO_ZIP" }); int newAddressId = Convert.ToInt32((await addressDao.GetNextId()) - 1); station.AddressId = newAddressId; /* Edit Station */ await stationDao.UpdateAsync(station.ToStation()); return(Content(HttpStatusCode.OK, new object())); }
public async Task <IHttpActionResult> QueryMeasurements(QueryRequest query) { /* Check if model is valid */ if (!ModelState.IsValid) { var errors = ModelState.ToDictionary( kvp => kvp.Key, kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray() ); return(Content(HttpStatusCode.BadRequest, errors)); } IMeasurementDao dao = AdoFactory.Instance.GetMeasurementDao("wetr"); IStationDao stationDao = AdoFactory.Instance.GetStationDao("wetr"); Station s = await stationDao.FindByIdAsync(query.StationId); double[] result = await dao.GetQueryResult(query.Start, query.End, query.MeasurementTypeId, query.ReductionTypeId, query.GroupingTypeId, new List <Station>() { s }); return(Content(HttpStatusCode.OK, result)); }
public async Task <IEnumerable <Station> > FilterByRegion(GeoCoordinate geoCoordinate, double radius = 0) { try { IStationDao stationDao = GetIStationDao(); IEnumerable <Station> stations = await stationDao.FindAllAsync(); List <Station> returnStations = new List <Station>(); foreach (Station station in stations) { if (DistanceTo(geoCoordinate.Latitude, geoCoordinate.Longitude, station.Latitude, station.Longitude) <= radius) { returnStations.Add(station); } } return(returnStations); } catch (Exception) { return(null); } }
public async Task <IHttpActionResult> CreateStation(StationDTO station) { /* Check if model is valid */ if (!ModelState.IsValid) { var errors = ModelState.ToDictionary( kvp => kvp.Key, kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray() ); return(Content(HttpStatusCode.BadRequest, errors)); } 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"); await addressDao.InsertAsync(new Address() { CommunityId = station.CommunityId, Location = station.Location, Zip = "NO_ZIP" }); int newAddressId = Convert.ToInt32((await addressDao.GetNextId()) - 1); /* Cleanup */ station.AddressId = newAddressId; station.StationId = 0; station.UserId = userId; await stationDao.InsertAsync(station.ToStation()); return(Content(HttpStatusCode.OK, new object())); }
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)); }
public MeasurementManager(IMeasurementDao measurementDao, IStationDao stationDao, IAddressManager addressManager) { this.measurementDao = measurementDao; this.stationDao = stationDao; this.addressManager = addressManager; SetupTwitter(); /* Twitter Testing * * Measurement m = new Measurement() * { * StationId = 45, * MeasurementTypeId = 1, * Value = -23, * TimesStamp = DateTime.Now, * UnitId=1 * * }; * * bool res = AddMeasurement(m).Result; * */ }
public StationManager(IStationDao stationDao, IStationTypeDao stationTypeDao, IMeasurementDao measurementDao) { this.stationDao = stationDao; this.stationTypeDao = stationTypeDao; this.measurementDao = measurementDao; }
private static IStationDao GetIStationDao() { return(_iStationDao ?? (_iStationDao = new AdoStationDao(DefaultConnectionFactory.FromConfiguration(_connectionStringConfigName)))); }