public async Task EditAsync(EditCarAdViewModel inputModel) { var carAd = AutoMapperConfig.MapperInstance.Map <CarAd>(inputModel); this.carAdsRepository.Update(carAd); await this.carAdsRepository.SaveChangesAsync(); }
public async Task <IActionResult> Edit(EditCarAdViewModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } await this.carAdsService.EditAsync(inputModel); return(this.RedirectToAction("MyCarAds")); }
public async Task <IActionResult> EditAdCar(EditCarAdViewModel input) { var carViewModel = this.carService.GetById <EditCarAdViewModel>(input.Id); var user = await this.userManager.GetUserAsync(this.User); if (carViewModel == null) { return(this.NotFound()); } if (await this.IsUserAuthorOrAdmin(user, input.UserId)) { return(this.RedirectToAction("Login", "Account")); } if (!this.ModelState.IsValid) { input.Makes = this.makeCarService.GetAll <MakeInputViewModel>(); input.Models = this.modelCarService.GetAllByMakeId <ModelInputViewModel>(input.MakeId); input.Bodies = this.bodyCarService.GetAll <BodyInputViewModel>(); input.Drives = this.engineService.GetAllByModelIdAndFuelId <DriveInputViewModel>(input.ModelId, input.FuelId); input.CarFeatures = await this.featureService.GetAllByCarIdAsync <FeatureViewModel>(input.Id); 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)); } var carId = await this.carService.EditAsync(input.Id, input.MakeId, input.ModelId, input.DriveId, input.BodyId, input.Month, input.Year, input.Color, input.InputFeatures, input.Mileage, input.Price, input.Description); return(this.RedirectToAction(nameof(this.DetailsAdCar), "Cars", new { Id = carId })); }