Пример #1
0
        public async override Task TestUpdateAsync()
        {
            int addressId = 1;

            Address address = await addressDao.FindByIdAsync(addressId);

            address.Location = "TestUpdate";

            Assert.IsTrue(await addressDao.UpdateAsync(address));
            Address test = await addressDao.FindByIdAsync(addressId);

            Assert.IsTrue(test.Equals(address));
        }
Пример #2
0
 public async Task <bool> UpdateAddress(Address updatedAddress)
 {
     if (!CheckAddress(updatedAddress))
     {
         return(false);
     }
     try
     {
         return(await addressDao.UpdateAsync(updatedAddress));
     }
     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()));
        }
Пример #4
0
        public async Task <IResult> UpdateAsync(Address address)
        {
            await _addressDao.UpdateAsync(address);

            return(new SuccessResult(true, ResultMessages.AddressUpdated));
        }