public async Task <DTO.CountryOutput> UpdateEntityAsync(long id, DTO.CountryInput entity)
        {
            try
            {
                await TransactionHandler.BeginTransactionAsync();

                var foundCountry = await CountryRepository.GetEntityByIdAsync(id);

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

                foundCountry.Code = entity.Code;
                foundCountry.Name = entity.Name;

                await CountryRepository.UpdateEntityAsync(foundCountry);

                await TransactionHandler.CommitTransactionAsync();

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

                throw;
            }
            finally
            {
                await TransactionHandler.DisposeTransactionAsync();
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PostCountryAsync([FromBody] DTO.CountryInput country)
        {
            var insertedCountry = await CountryManager.InsertEntityAsync(country);

            return(Ok(new DTO.SuccessResponse <DTO.CountryOutput>
            {
                Success = true,
                Content = insertedCountry
            }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutCountryAsync([FromQuery] long countryId,
                                                          [FromBody] DTO.CountryInput country)
        {
            var updatedCountry = await CountryManager.UpdateEntityAsync(countryId, country);

            return(Ok(new DTO.SuccessResponse <DTO.CountryOutput>
            {
                Success = true,
                Content = updatedCountry
            }));
        }
        public async Task <DTO.CountryOutput> InsertEntityAsync(DTO.CountryInput entity)
        {
            try
            {
                await TransactionHandler.BeginTransactionAsync();

                var convertedCountry = Mapper.Map <DAO.Country>(entity);
                var insertedCountry  = await CountryRepository.InsertEntityAsync(convertedCountry);

                await TransactionHandler.CommitTransactionAsync();

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

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