예제 #1
0
        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);
        }
예제 #2
0
        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();
        }
예제 #3
0
        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"));
        }
예제 #4
0
        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);
        }
예제 #5
0
        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());
            }
        }
예제 #7
0
        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 }));
        }
예제 #8
0
        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());
        }