Пример #1
0
        public async Task <CarDto> AddCarService([FromForm] CarPhotoDto carPhotoDto)
        {
            var result = await AddPhotoAsync(carPhotoDto.File);

            var car = new Cars
            {
                CarPhotoUrl = result.SecureUrl.AbsoluteUri,
                PublicId    = result.PublicId,
                Car         = carPhotoDto.Car,
                Brand       = carPhotoDto.Brand,
                FuelType    = carPhotoDto.FuelType,
                Year        = carPhotoDto.Year,
                Price       = carPhotoDto.Price,
                Mileage     = carPhotoDto.Mileage,
                isTaken     = false,
                AppUserId   = 4
            };

            _carRepository.Add <Cars>(car);
            if (await _carRepository.SaveAllAsync())
            {
                return(_mapper.Map <CarDto>(car));
            }

            throw new Exception();
        }
Пример #2
0
        public async Task <ActionResult> AddCar([FromForm] CarPhotoDto carPhotoDto)
        {
            try
            {
                var addcar = await _carService.AddCarService(carPhotoDto);

                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest("Failed to add car :/"));
            }
        }