public async Task <string> CreateAsync(CarCreateInputModel inputModel, ApplicationUser user) { var car = new Car { UserId = user.Id, Make = inputModel.Make, Model = inputModel.Model, Type = inputModel.Type, Color = inputModel.Color, Year = inputModel.Year, PassengerSeats = inputModel.PassengerSeats, AllowedSmoking = inputModel.AllowedSmoking, AllowedDrinks = inputModel.AllowedDrinks, AllowedFood = inputModel.AllowedFood, AllowedPets = inputModel.AllowedPets, HasAirConditioning = inputModel.HasAirConditioning, PlaceForLuggage = inputModel.PlaceForLuggage, }; user.Car = car; this.usersRepository.Update(user); await this.usersRepository.SaveChangesAsync(); return(user.CarId); }
public async Task CreateAsync(string userId, CarCreateInputModel input) { var car = new Car { UserId = userId, CarImageUrl = GlobalConstants.NoCarPictureLocation, Brand = input.Brand, Model = input.Model, YearOfManufacture = input.YearOfManufacture, Color = input.Color, Seats = input.Seats, IsLuggageAvaliable = input.IsLuggageAvaliable, IsSmokingAllowed = input.IsSmokingAllowed, IsAirConditiningAvailable = input.IsAirConditiningAvailable, IsAllowedForPets = input.IsAllowedForPets, }; if (input.CarPicture != null) { var carImageUrl = await this.cloudinaryService.UploadImageAsync( input.CarPicture, string.Format(GlobalConstants.CloudinaryCarPictureName, userId)); car.CarImageUrl = carImageUrl; } await this.unitOfWork.Cars.AddAsync(car); await this.unitOfWork.CompleteAsync(); }
public async Task <IActionResult> Create([FromForm] CarCreateInputModel input) { var currentUser = await this.userManager.GetUserAsync(this.User); if (!this.ModelState.IsValid) { return(this.View()); } await this.carsService.CreateAsync(currentUser.Id, input); return(this.RedirectToAction("Index", "Cars")); }
public async Task CreateAsyncSetCarIdToUserCorrectly() { var inputModel = new CarCreateInputModel { Make = "Audi", Model = "R8", PassengerSeats = 2, }; var carId = await this.Service.CreateAsync(inputModel, this.User); Assert.Equal(carId, this.User.CarId); }
public async Task CreateAsyncAddsTheCarInDb() { var inputModel = new CarCreateInputModel { Make = "Audi", Model = "R8", PassengerSeats = 2, }; await this.Service.CreateAsync(inputModel, this.User); Assert.Equal(2, this.DbContext.Cars.Count()); }
public async Task <IActionResult> Create(CarCreateInputModel carInputCreateInputModel) { if (this.ModelState.IsValid) { var carServiceModel = mapper.Map <CarServiceModel>(carInputCreateInputModel); carServiceModel.Owner = this.userServices.GetUserByName(this.User.Identity.Name); await this.carServices.AddCarAsync(carServiceModel); return(RedirectToAction("ListCars", "Car")); } else { return(this.View()); } }
public async Task <IActionResult> Create(CarCreateInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View()); } var user = await this.userManager.GetUserAsync(this.User); var carId = await this.carsService.CreateAsync(inputModel, user); if (carId == null) { return(this.View()); } return(this.RedirectToAction("Details", new { id = carId })); }
public async Task CreateAsyncAddEntitySuccessfullyToDb() { await this.InitializeAsync(); var car = new CarCreateInputModel { CarImageUrl = GlobalConstants.NoCarPictureLocation, Brand = "TestBrand", Model = "TestModel", YearOfManufacture = 2010, Color = "testColor", Seats = 4, IsLuggageAvaliable = true, IsSmokingAllowed = true, IsAirConditiningAvailable = true, IsAllowedForPets = true, }; await this.carsService.CreateAsync(Guid.NewGuid().ToString(), car); Assert.Equal(1, await this.dbContext.Cars.CountAsync()); }