예제 #1
0
        public async override Task TestUpdateAsync()
        {
            int     StationId = 1;
            Station station   = await stationDao.FindByIdAsync(StationId);

            station.Name      = "TestUpdate";
            station.Latitude  = 1;
            station.Longitude = 1;

            Assert.IsTrue(await stationDao.UpdateAsync(station));

            Station station2 = await stationDao.FindByIdAsync(StationId);

            Assert.IsTrue(station.Equals(station2));
        }
예제 #2
0
        public async Task <bool> UpdateStation(Station updatedStation)
        {
            if (!CheckStation(updatedStation))
            {
                return(false);
            }

            try
            {
                return(await stationDao.UpdateAsync(updatedStation));
            }
            catch (Common.Dal.Ado.MySqlException ex)
            {
                throw new BusinessSqlException(ex.Message, ex.InnerException);
            }
        }
예제 #3
0
        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()));
        }