public async Task <bool> AddStation(Station newStation) { try { if (!CheckStation(newStation)) { return(false); } return(await stationDao.InsertAsync(newStation)); } catch (Common.Dal.Ado.MySqlException ex) { throw new BusinessSqlException(ex.Message, ex.InnerException); } }
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 static async Task ClassInitializeAsync(TestContext context) { User user = new User { UserId = 1, FirstName = "Andreas", LastName = "Roither", Email = "*****@*****.**", Password = "******" }; await userDao.InsertAsync(user); Country country = new Country { CountryId = 9, Name = "TestCountry" }; await countryDao.InsertAsync(country); Province province = new Province { CountryId = 9, ProvinceId = 6, Name = "TestProvince" }; await provinceDao.InsertAsync(province); District district = new District { DistrictId = 6, ProvinceId = 6, Name = "TestDistrict" }; await districtDao.InsertAsync(district); Community community = new Community { DistrictId = 6, CommunityId = 6, Name = "TestCommunity" }; await communityDao.InsertAsync(community); Address address = new Address { AddressId = 6, CommunityId = 6, Location = "TestLocation", Zip = "124" }; await addressDao.InsertAsync(address); StationType type = new StationType { StationTypeId = 1, Name = "TestType" }; await stationTypeDao.InsertAsync(type); Station station = new Station { StationId = 1, Name = "Station 1", Longitude = 12, Latitude = 12, StationTypeId = 1, AddressId = 6, UserId = 1 }; await stationDao.InsertAsync(station); }
public static async Task ClassInitializeAsync(TestContext context) { User user = new User() { UserId = 23, FirstName = "Daniel", LastName = "Englisch", Email = "*****@*****.**", Password = "******" }; await userDao.InsertAsync(user); Country country = new Country { CountryId = 33, Name = "MyCountry" }; await countryDao.InsertAsync(country); Province province = new Province { ProvinceId = 66, CountryId = country.CountryId, Name = "MyProvince" }; await provinceDao.InsertAsync(province); District district = new District { DistrictId = 54, ProvinceId = province.ProvinceId, Name = "MyDistrict" }; await districtDao.InsertAsync(district); Community community = new Community { CommunityId = 74, DistrictId = district.DistrictId, Name = "MyCommunity" }; await communityDao.InsertAsync(community); Address address = new Address { AddressId = 93, CommunityId = community.CommunityId, Location = "Waidhofnerstraße 34a", Zip = "332A" }; await addressDao.InsertAsync(address); StationType stationType = new StationType { StationTypeId = 83, Name = "DeluxeStation" }; await stationTypeDao.InsertAsync(stationType); Station station = new Station { StationId = 32, UserId = user.UserId, AddressId = address.AddressId, Name = "TemperaturStation", Latitude = 3.323M, Longitude = -3.333M, StationTypeId = stationType.StationTypeId }; await stationDao.InsertAsync(station); MeasurementType measurementType = new MeasurementType { MeasurementTypeId = 43, Name = "Temperatur" }; await measurementTypeDao.InsertAsync(measurementType); Unit unit = new Unit { UnitId = 34, Name = "Celcius" }; await unitDao.InsertAsync(unit); Measurement m1 = new Measurement { MeasurementId = 44, MeasurementTypeId = measurementType.MeasurementTypeId, StationId = station.StationId, Value = 23.3, TimesStamp = DateTime.FromFileTime(131862006360000000), UnitId = unit.UnitId }; Measurement m2 = new Measurement { MeasurementId = 45, MeasurementTypeId = measurementType.MeasurementTypeId, StationId = station.StationId, Value = -0.3, TimesStamp = DateTime.Now, UnitId = unit.UnitId }; Measurement m3 = new Measurement { MeasurementId = 46, MeasurementTypeId = measurementType.MeasurementTypeId, StationId = station.StationId, Value = 12.85, TimesStamp = DateTime.Now, UnitId = unit.UnitId }; measurements.Add(m1); measurements.Add(m2); measurements.Add(m3); foreach (var m in measurements) { await measurementDao.InsertAsync(m); } }