コード例 #1
0
        public void DetailsModel(VehicleDto vehicleDto)
        {
            var     config = new MapperConfiguration(cfg => { cfg.CreateMap <VehicleModelEntity, VehicleDto>(); });
            IMapper mapper = config.CreateMapper();

            var entity = mapper.Map <VehicleDto, VehicleModelEntity>(vehicleDto);


            _modelRepository.Details(entity);
        }
コード例 #2
0
        public async Task <ActionResult <VehicleDto> > Create(SaveVehicleDto saveVehicleDto)
        {
            var model = await _modelRepository.Details(saveVehicleDto.ModelId);

            if (model == null)
            {
                return(BadRequest("Invalid ModelId"));
            }

            var user = await _userRepository.Details(_userAccessor.GetCurrentUsername());

            var vehicle = Mapper.Map <SaveVehicleDto, Vehicle>(saveVehicleDto);

            vehicle.User       = user;
            vehicle.LastUpdate = DateTime.Now;

            _vehicleRepository.Create(vehicle);
            await _unitOfWork.CompleteAsync();

            vehicle = await _vehicleRepository.Details(vehicle.Id);

            return(Mapper.Map <Vehicle, VehicleDto>(vehicle));
        }