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

                var foundUnit = await UnitRepository.GetEntityByIdAsync(id);

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

                foundUnit.Name = entity.Name;

                await UnitRepository.UpdateEntityAsync(foundUnit);

                await TransactionHandler.CommitTransactionAsync();

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

                throw;
            }
            finally
            {
                await TransactionHandler.DisposeTransactionAsync();
            }
        }
예제 #2
0
        public async Task <IActionResult> UpdateUnitAsync([FromQuery] long unitId, [FromBody] DTO.UnitInput unit)
        {
            var updatedUnit = await UnitManager.UpdateEntityAsync(unitId, unit);

            return(Ok(new DTO.SuccessResponse <DTO.UnitOutput>
            {
                Success = true,
                Content = updatedUnit
            }));
        }
예제 #3
0
        public async Task <IActionResult> PostUnitAsync([FromBody] DTO.UnitInput unit)
        {
            var insertedUnit = await UnitManager.InsertEntityAsync(unit);

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

                var convertedUnit = Mapper.Map <DAO.Unit>(entity);
                var insertedUnit  = await UnitRepository.InsertEntityAsync(convertedUnit);

                await TransactionHandler.CommitTransactionAsync();

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

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