コード例 #1
0
        public ActionResult <FuelTypeDto> GetFuelType(int id)
        {
            var fuelType = _repository.GetById(id);

            if (fuelType == null)
            {
                return(NotFound(ExceptionMessageHeaders.GetMessage(ExceptionMessageHeaders.GetMessage(ExceptionMessageHeaders.CanNotFoundEntityWithId, id))));
            }

            var dto = _mapper.Map <FuelTypeDto>(fuelType);

            return(dto);
        }
コード例 #2
0
        public async Task <ActionResult <CarDto> > GetCar(int id)
        {
            var car = await _repository.GetByIdAsync(id).ConfigureAwait(false);

            if (car == null)
            {
                return(NotFound(
                           ExceptionMessageHeaders.GetMessage(ExceptionMessageHeaders.CanNotFoundEntityWithId, id)
                           ));
            }

            var result = _mapper.Map <CarDto>(car);

            return(result);
        }
コード例 #3
0
        public async Task <ActionResult <Car> > DeleteCar(int id)
        {
            var car = _repository.GetById(id);

            if (car == null)
            {
                return(NotFound(ExceptionMessageHeaders.GetMessage(ExceptionMessageHeaders.CanNotFoundEntityWithId, id)));
            }

            await _repository.RemoveAsync(car).ConfigureAwait(false);

            await _unitOfWork.CommitAsync().ConfigureAwait(false);

            return(car);
        }
コード例 #4
0
        public async Task <IActionResult> PutEngine(int id, string engineDto)
        {
            var engineUnit = await _repository.GetByIdAsync(id).ConfigureAwait(false);

            var engineDtoDes = engineDto.GetDto <EngineDto>();

            if (engineUnit == null)
            {
                return(NotFound(ExceptionMessageHeaders.GetMessage(ExceptionMessageHeaders.CanNotFoundEntityWithId, id)));
            }

            if (engineDto == null)
            {
                return(BadRequest(ExceptionMessageHeaders.CanNotRecognizeInputModel));
            }

            engineUnit    = _mapper.Map <Engine>(engineDtoDes);
            engineUnit.Id = id;

            _repository.Update(engineUnit);

            try
            {
                await _unitOfWork.CommitAsync().ConfigureAwait(false);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EngineExists(id))
                {
                    return(NotFound(ExceptionMessageHeaders.GetMessage(ExceptionMessageHeaders.CanNotFoundEntityWithId, id)));
                }
                else
                {
                    throw;
                }
            }

            return(Ok(engineDtoDes));
        }
コード例 #5
0
        public async Task <IActionResult> PutCar(int id, string carDto)
        {
            var tmp = _repository.GetById(id);

            if (tmp == null || string.IsNullOrWhiteSpace(carDto))
            {
                return(NotFound(ExceptionMessageHeaders.GetMessage(ExceptionMessageHeaders.CanNotFoundEntityWithId, id)));
            }

            var car = carDto.GetDto <CarDto>();

            if (car == null)
            {
                return(BadRequest(ExceptionMessageHeaders.CanNotRecognizeInputModel));
            }

            var result = _mapper.Map <Car>(car);

            _repository.Update(result);

            try
            {
                await _unitOfWork.CommitAsync().ConfigureAwait(false);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    BadRequest();
                }
            }

            return(Ok(result));
        }
コード例 #6
0
        public async Task <IActionResult> PutBodyType(int id, string bodyTypeDto)
        {
            var dto = bodyTypeDto.GetDto <BodyTypeDto>();

            if (dto == null)
            {
                return(BadRequest(ExceptionMessageHeaders.CanNotRecognizeInputModel));
            }

            if (!BodyTypeExists(id))
            {
                return(NotFound(ExceptionMessageHeaders.GetMessage(ExceptionMessageHeaders.CanNotFoundEntityWithId, id)));
            }

            var bodyType = _mapper.Map <BodyType>(dto);

            bodyType.Id = id;

            await _repository.UpdateAsync(bodyType).ConfigureAwait(false);

            await _UoW.CommitAsync().ConfigureAwait(false);

            return(Ok());
        }