Example #1
0
        public async Task <DTO.CityOutput> UpdateEntityAsync(long id, DTO.CityInput entity)
        {
            try
            {
                await TransactionHandler.BeginTransactionAsync();

                var foundCity = await CityRepository.GetEntityByIdAsync(id);

                if (foundCity == null)
                {
                    throw new NotFoundException("This city does not exist.");
                }

                foundCity.ZipCode = entity.ZipCode;
                foundCity.Name    = entity.Name;

                await CityRepository.UpdateEntityAsync(foundCity);

                await TransactionHandler.CommitTransactionAsync();

                return(Mapper.Map <DTO.CityOutput>(foundCity));
            }
            catch
            {
                await TransactionHandler.RollbackTransactionAsync();

                throw;
            }
            finally
            {
                await TransactionHandler.DisposeTransactionAsync();
            }
        }
Example #2
0
        public async Task <IActionResult> PutCityAsync([FromQuery] long cityId, [FromBody] DTO.CityInput city)
        {
            var updatedCity = await CityManager.UpdateEntityAsync(cityId, city);

            return(Ok(new DTO.SuccessResponse <DTO.CityOutput>
            {
                Success = true,
                Content = updatedCity
            }));
        }
Example #3
0
        public async Task <IActionResult> PostCityAsync([FromBody] DTO.CityInput city)
        {
            var insertedCity = await CityManager.InsertEntityAsync(city);

            return(Ok(new DTO.SuccessResponse <DTO.CityOutput>
            {
                Success = true,
                Content = insertedCity
            }));
        }
Example #4
0
        public async Task <DTO.CityOutput> InsertEntityAsync(DTO.CityInput entity)
        {
            try
            {
                await TransactionHandler.BeginTransactionAsync();

                var convertedCity = Mapper.Map <DAO.City>(entity);
                var insertedCity  = await CityRepository.InsertEntityAsync(convertedCity);

                await TransactionHandler.CommitTransactionAsync();

                return(Mapper.Map <DTO.CityOutput>(insertedCity));
            }
            catch
            {
                await TransactionHandler.RollbackTransactionAsync();

                throw;
            }
            finally
            {
                await TransactionHandler.DisposeTransactionAsync();
            }
        }