public async Task <IActionResult> CreateAdCar(CreateAdCarInputFormViewModel input) { if (!this.ModelState.IsValid) { input.Makes = this.makeCarService.GetAll <MakeInputViewModel>(); input.Models = this.modelCarService.GetAll <ModelInputViewModel>(); input.Bodies = this.bodyCarService.GetAll <BodyInputViewModel>(); input.Safety = await this.featureService.GetAllOfTypeAsync <FeatureViewModel>(GlobalConstants.FeatureTypeNameSafety); input.Extras = await this.featureService.GetAllOfTypeAsync <FeatureViewModel>(GlobalConstants.FeatureTypeNameExtras); input.Entartaiment = await this.featureService.GetAllOfTypeAsync <FeatureViewModel>(GlobalConstants.FeatureTypeNameEntertainment); input.Comfort = await this.featureService.GetAllOfTypeAsync <FeatureViewModel>(GlobalConstants.FeatureTypeNameComfort); return(this.View(input)); } string inputMainImage = string.Empty; if (input.MainImage == null) { inputMainImage = GlobalConstants.ImageNotFound; } else { inputMainImage = await this.cloudinaryService.UploadAsyncFile(this.cloudinary, input.MainImage); } IEnumerable <string> inputImages = null; if (input.Images == null) { inputImages.ToList().Add(GlobalConstants.ImageNotFound); } else { inputImages = await this.cloudinaryService.UploadAsyncFiles(this.cloudinary, input.Images); } var userId = this.userManager.GetUserId(this.User); var carId = await this.carService.AddAsync(input.MakeId, input.ModelId, input.DriveId, input.BodyId, input.Month, input.Year, input.Color, input.InputFeatures, inputImages, input.Mileage, input.Price, inputMainImage, input.Description, userId); return(this.RedirectToAction(nameof(this.DetailsAdCar), "Cars", new { Id = carId })); }
public async Task <IActionResult> CreateAdCar() { var viewModel = new CreateAdCarInputFormViewModel(); viewModel.Makes = this.makeCarService.GetAll <MakeInputViewModel>(); viewModel.Models = this.modelCarService.GetAll <ModelInputViewModel>(); viewModel.Bodies = this.bodyCarService.GetAll <BodyInputViewModel>(); viewModel.Safety = await this.featureService.GetAllOfTypeAsync <FeatureViewModel>(GlobalConstants.FeatureTypeNameSafety); viewModel.Extras = await this.featureService.GetAllOfTypeAsync <FeatureViewModel>(GlobalConstants.FeatureTypeNameExtras); viewModel.Entartaiment = await this.featureService.GetAllOfTypeAsync <FeatureViewModel>(GlobalConstants.FeatureTypeNameEntertainment); viewModel.Comfort = await this.featureService.GetAllOfTypeAsync <FeatureViewModel>(GlobalConstants.FeatureTypeNameComfort); return(this.View(viewModel)); }