Ejemplo n.º 1
0
        public async Task <IActionResult> Create(ElectricCarInputViewModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.RedirectToAction(nameof(this.Create)));
            }

            var userId = this.userManager.GetUserId(this.User);
            var carId  = await this.carsService.CreateCarAsync(input, userId);

            if (input.Images != null)
            {
                var imagePath = $"{this.environment.WebRootPath}/img";

                var imageUploadModel = new ImageUploadViewModel();
                imageUploadModel.Images        = input.Images;
                imageUploadModel.Path          = imagePath;
                imageUploadModel.UserId        = userId;
                imageUploadModel.ImageTypeName = GlobalConstants.CarExternalImage;
                imageUploadModel.CarId         = carId;

                await this.imagesService.UploadImages(imageUploadModel);
            }

            this.TempData["Message"] = "You can drive now. Your car is created successufully";

            return(this.RedirectToAction(nameof(this.Index)));
        }
Ejemplo n.º 2
0
        public async Task <int> CreateCarAsync(ElectricCarInputViewModel input, string userId)
        {
            var car = new ElectricCar
            {
                Acceleration           = input.Acceleration,
                Battery                = input.Battery,
                Color                  = input.Color,
                Doors                  = input.Doors,
                Drive                  = input.Drive,
                ElectricityConsumption = input.ElectricityConsumption,
                HorsePower             = input.HorsePower,
                Kilometres             = input.Kilometres,
                LuggageCapacity        = input.LuggageCapacity,
                MakeId                 = input.CarMakeId,
                ModelId                = input.CarModelId,
                Range                  = input.Range,
                Seats                  = input.Seats,
                TopSpeed               = input.TopSpeed,
                UserId                 = userId,
                Year        = input.Year,
                CarTypeId   = input.CarTypeId,
                Description = input.Description,
            };

            await this.carRepository.AddAsync(car);

            await this.carRepository.SaveChangesAsync();

            return(car.Id);
        }
Ejemplo n.º 3
0
        public async Task CreateCarAsyncShouldReturnValidCarId()
        {
            var userId = "asdasdqwe";

            var car = new ElectricCarInputViewModel
            {
                Acceleration           = "2.1",
                Seats                  = 4,
                TopSpeed               = 260,
                Battery                = "100 kWh",
                CarMakeId              = 1,
                CarModelId             = 1,
                CarTypeId              = 1,
                Doors                  = 4,
                Drive                  = "AWD",
                ElectricityConsumption = "10/100",
                HorsePower             = 200,
                Kilometres             = 20,
                LuggageCapacity        = 120,
                Range                  = 500,
                Year = 2017,
            };

            var id = await this.carsService.CreateCarAsync(car, userId);

            Assert.True(id > 0);
        }
Ejemplo n.º 4
0
        public IActionResult Create()
        {
            this.ViewBag.Makes = new SelectList(this.carsService.GetMakes(), nameof(VehicleMakeViewModel.Id), nameof(VehicleMakeViewModel.Name));

            var inputModel = new ElectricCarInputViewModel();

            inputModel.CarTypes = this.carsService.GetAllCarTypesAsKeyValuePairs();

            return(this.View(inputModel));
        }