Exemple #1
0
        public async Task <string> CreateAsync(CreateCarRequestModel input)
        {
            var car = new Car
            {
                Price        = input.Price,
                FuelType     = (FuelType)Enum.Parse(typeof(FuelType), input.FuelType),
                HorsePower   = input.HorsePower,
                Transmission = (TransmissionType)Enum.Parse(typeof(TransmissionType), input.Transmission),
                Year         = input.Year,
                Mileage      = input.Mileage,
                Color        = (Color)Enum.Parse(typeof(Color), input.Color),
                Condition    = (ConditionType)Enum.Parse(typeof(ConditionType), input.Condition),
                EuroStandard = (EuroStandard)Enum.Parse(typeof(EuroStandard), input.EuroStandard),
                DoorsCount   = (DoorsCount)Enum.Parse(typeof(DoorsCount), input.DoorsCount),
                BodyType     = (BodyType)Enum.Parse(typeof(BodyType), input.BodyType),
                BrandId      = input.BrandId,
                ModelId      = input.ModelId,
                OwnerId      = input.OwnerId,
            };

            await this.dbContext.Cars.AddAsync(car);

            await this.dbContext.SaveChangesAsync();

            foreach (var comfortId in input.Comforts)
            {
                await this.carComfortsService.CreateAsync(car.Id, comfortId);
            }

            foreach (var exteriorId in input.Exteriors)
            {
                await this.carExteriorsService.CreateAsync(car.Id, exteriorId);
            }

            foreach (var protectionId in input.Protections)
            {
                await this.carProtectionsService.CreateAsync(car.Id, protectionId);
            }

            foreach (var safetyId in input.Safeties)
            {
                await this.carSafetiesService.CreateAsync(car.Id, safetyId);
            }

            return(car.Id);
        }
Exemple #2
0
        public async Task <CarResponseModel> CreateCar(CreateCarRequestModel requestModel)
        {
            _logger.LogInformation("CreateCar - params: requestModel={0}", requestModel);

            Car car = new Car()
            {
                CarCategoryId         = requestModel.CategoryId,
                CarImpactClassId      = requestModel.ImpactClassId,
                CarProbabilityClassId = requestModel.CarProbabilityClassId,
                DateCreated           = DateTime.UtcNow,
                Description           = requestModel.Description,
                Title    = requestModel.Title,
                GarageId = requestModel.GarageId,
            };

            await _carRepository.AddAsync(car);

            var result = await _carRepository.GetByIdAsync(car.Id);

            return(_mapper.Map <Car, CarResponseModel>(result));
        }
 public async Task <ActionResult <CarResponseModel> > PostCar(CreateCarRequestModel requestModel)
 {
     return(Ok(await _carService.CreateCar(requestModel)));
 }