public async Task <IActionResult> Create() { var userCars = await this.GetUserCars(); var model = new RideCreateBindingModel { OwnedCars = userCars }; return(this.View(model)); }
public async Task <IActionResult> Create(RideCreateBindingModel model) { if (!this.ModelState.IsValid) { var userCars = await this.GetUserCars(); model.OwnedCars = userCars; return(this.View(model)); } model.Date = model.Date.ToUniversalTime(); var car = await this.carsService.GetAsync(model.CarId); if (car == null || !this.carsService.IsUserOwner(car, this.User?.Identity?.Name)) { this.Error(NotificationMessages.RideCreateError); return(this.View()); } var serviceModel = Mapper.Map <RideServiceModel>(model); var id = await this.ridesService.CreateAsync(serviceModel); if (id == null) { this.Error(NotificationMessages.RideCreateError); var userCars = await this.GetUserCars(); model.OwnedCars = userCars; return(this.View(model)); } this.Success(NotificationMessages.RideCreated); return(this.RedirectToAction("Details", new { id })); }