public async Task <IActionResult> Create(CarCreateBindingModel model) { if (!this.ModelState.IsValid) { var manufacturers = await this.GetAllManufacturers(); model.Manufacturers = manufacturers; return(this.View(model)); } var serviceModel = Mapper.Map <CarServiceModel>(model); serviceModel.Owner = new PoolItUserServiceModel { UserName = this.User.Identity.Name }; var result = await this.carsService.CreateAsync(serviceModel); if (!result) { this.Error(NotificationMessages.CarCreateError); } this.Success(NotificationMessages.CarCreated); return(this.RedirectToAction("Create", "Rides", new { Area = "Rides" })); }
public async Task <IActionResult> Create(CarCreateBindingModel carCreateBindingModel) { if (!this.ModelState.IsValid) { List <CarStatusServiceModel> allCarStatuses = await this.carService .GetAllStatuses() .ToListAsync(); this.ViewData["statuses"] = allCarStatuses .Select(carStatus => new CarCreateCarStatusViewModel { Name = carStatus.Name }) .ToList(); return(this.View()); } string pictureUrl = await this.cloudinaryService.UploadPictureAsync( carCreateBindingModel.Picture, carCreateBindingModel.Model); CarServiceModel carServiceModel = AutoMapper.Mapper .Map <CarServiceModel>(carCreateBindingModel); carServiceModel.Picture = pictureUrl; await this.carService.Create(carServiceModel); return(this.Redirect("/")); }
public async Task <IActionResult> Create() { var manufacturers = await this.GetAllManufacturers(); var model = new CarCreateBindingModel { Manufacturers = manufacturers }; return(this.View(model)); }